How to Install Fedora on VirtualBox
The installation of Fedora using VirtualBox is a great ...
You can block an IP address at the server firewall or at the web server. A firewall rule can restrict access to server services; an Apache or Nginx rule applies to the website or location where it is configured. Choose the layer that matches the traffic you need to stop.
203.0.113.45, 203.0.113.0/24 and 2001:db8::45 below are documentation examples. Replace them with the verified address or network.| Method | Scope | Use When |
|---|---|---|
| UFW | Traffic reaching the host firewall | UFW already manages an Ubuntu/Debian server |
| Apache 2.4 | The configured website or directory | Apache allows the required access-control directives |
| Nginx | The configured server or location | You manage the Nginx site configuration |
These commands use Ubuntu’s UFW firewall. First inspect its status and rule order:
sudo ufw status verbose
sudo ufw status numberedContinue only if UFW is the active firewall. If it is inactive, do not enable it remotely until the actual SSH port and all required services are allowed and recovery access is available. The rule below goes before existing user rules, so an earlier broad allow rule does not take precedence:
sudo ufw insert 1 deny from 203.0.113.45
sudo ufw status numberedTo restrict only web traffic from that address, use port-specific rules instead of the all-service rule above:
sudo ufw insert 1 deny from 203.0.113.45 to any port 80 proto tcp
sudo ufw insert 1 deny from 203.0.113.45 to any port 443 proto tcpFor a verified network range or IPv6 address, the same syntax accepts CIDR notation or IPv6. IPv6 filtering requires IPv6 support to be enabled in the UFW configuration:
sudo ufw insert 1 deny from 203.0.113.0/24
sudo ufw insert 1 deny from 2001:db8::45Review a range before blocking it. These examples affect new traffic that reaches UFW; existing connections, Docker-published ports and other networking arrangements can require separate checks. If a CDN proxies the site, the host may see the CDN address instead of the visitor’s address.
For website-only filtering, Apache 2.4 uses Require directives. Add this to the relevant directory configuration, or to .htaccess only if the host permits the required overrides. Merge it with existing authorization rules rather than replacing them blindly:
<RequireAll>
Require all granted
Require not ip 203.0.113.45
</RequireAll>A denied website request should return HTTP 403. This does not block SSH or other services. The old Order, Allow and Deny examples belong to legacy access-control configuration and should not be mixed with this example.
When changing the main Apache configuration on Ubuntu, validate it before reloading:
sudo apachectl configtest
sudo systemctl reload apache2Run the reload only after the test reports success. For an .htaccess change, test an actual request and check the error log as well; a main-configuration test does not validate every per-directory .htaccess file.
Nginx does not read .htaccess files. Add access-control directives to the existing server or location that handles the request. Order matters: place the deny before a matching allow rule. Preserve the existing application configuration:
deny 203.0.113.45;
allow all;Check syntax, then reload only if the test succeeds:
sudo nginx -t
sudo systemctl reload nginxA request reaching that Nginx context from the denied address should return 403. Behind a trusted reverse proxy, configure real-client-IP handling correctly before relying on client-IP rules; do not trust arbitrary forwarded headers.
To undo the all-service UFW example, delete the matching rule:
sudo ufw delete deny from 203.0.113.45If you used the port-specific examples, remove each matching rule instead:
sudo ufw delete deny from 203.0.113.45 to any port 80 proto tcp
sudo ufw delete deny from 203.0.113.45 to any port 443 proto tcpRemove range or IPv6 rules using the corresponding address and the same delete deny from syntax. For Apache or Nginx, remove the specific restriction, validate any server configuration changes and reload as appropriate. Retest both denied and allowed paths.
Manual IP rules do not expire automatically. A configured tool such as Fail2Ban can apply temporary bans based on matching logs, but it needs the correct filters and ban duration. Broad network or country blocks can also exclude legitimate visitors. Combine targeted blocking with updates, strong authentication, monitoring and backups.
Yes. Add a rule for each verified address, or use a CIDR range when you intend to block the entire network. Review the effect on legitimate users first.
Only if the chosen rule has that scope. An Apache or Nginx restriction normally affects the configured website or location. A firewall rule can cover one port or multiple server services.
Yes. Remove the exact firewall or web-server restriction, apply any required reload and test access again.
No. The manual rules in this guide remain until removed. Temporary bans require a tool or process configured to expire them.
Yes, if a rule blocks a legitimate crawler or an intermediary it uses. Verify the traffic and the address before applying a block.