Dino Geek, try to help you

How to block specific IP addresses?


Blocking specific IP addresses can be accomplished through various methods depending on the context in which you need the block to occur, such as on a web server, network router, or using operating system firewall rules.

  1. Using a Web Server:

  1. Apache Web Server:

1. Editing the .htaccess File: Open the `.htaccess` file which is typically found in your website’s root directory. Add the following lines: \`\`\`apache Require all granted Require not ip 192.168.1.100 Require not ip 10.0.0.200 \`\`\` This will block access from the IP addresses `192.168.1.100` and `10.0.0.200`.

  1. Nginx Web Server:

1. Editing the Configuration File: Open the Nginx configuration file, typically located at `/etc/nginx/nginx.conf` or in a server block file. Add the following lines: \`\`\`nginx server { listen 80; server\_name example.com;

deny 192.168.1.100; deny 10.0.0.200; allow all; } \`\`\` This configuration will block access from the IP addresses `192.168.1.100` and `10.0.0.200`.

  1. Using a Network Router:

Most modern routers have built-in IP filtering or firewall capabilities. The process varies by manufacturer, but generally follows these steps:

1. Access Router Admin Panel: Open a web browser and enter the router’s IP address (commonly `192.168.1.1` or `192.168.0.1`).

1. Login: Enter the admin username and password.

1. Navigate to Security or Firewall Settings: Look for a section labeled “Access Control,” “Firewall,” or “IP Filtering.”

1. Block IP Address: Add the IP addresses you wish to block. For example, you may see a form asking for the IP address range or individual IPs.

  1. Using Operating System Firewall:

  1. Windows Firewall:

1. Open Windows Defender Firewall with Advanced Security: Search for “Windows Defender Firewall” in the Start menu and select “Advanced Settings.”

1. Create a New Rule: Go to Inbound Rules > New Rule… > Custom > All programs > Any protocol.

1. Specify IP Addresses: On the “Scope” page, specify the IP address ranges you wish to block.

1. Block the Connection: Choose “Block the connection” and complete the wizard.

  1. iptables on Linux:

1. Open Terminal and Gain Root Access: Use `sudo` for root privileges.

1. Add iptables Rule: Execute the command: \`\`\`bash sudo iptables -A INPUT -s 192.168.1.100 -j DROP sudo iptables -A INPUT -s 10.0.0.200 -j DROP \`\`\`
1. Save the Rules: Persist iptables rules across reboots: \`\`\`bash sudo sh -c “iptables-save > /etc/iptables/rules.v4“ \`\`\`

  1. Conclusion:

Blocking specific IP addresses can be a critical measure to enhance network security, mitigate attacks, or simply manage who accesses your resources. The methods mentioned above provide a versatile approach using common web servers, network routers, and operating system firewalls.

  1. References:

1. Apache Documentation: [Apache 2.4: .htaccess files](https://httpd.apache.org/docs/2.4/howto/htaccess.html)

1. Nginx Documentation: [Nginx Beginner’s Guide](https://nginx.org/en/docs/beginners_guide.html)

1. Microsoft Documentation: [Create an Inbound ICMP Rule](https://docs.microsoft.com/en-us/windows/security/threat-protection/windows-firewall/create-an-inbound-icmp-rule)

1. iptables Documentation: [iptables-extensions(8) — Linux manual page](http://ipset.netfilter.org/iptables-extensions.man.html)

1. Router Manuals and Firmware Guides: Specific to each router manufacturer, usually found on their official websites.


Simply generate articles to optimize your SEO
Simply generate articles to optimize your SEO





DinoGeek offers simple articles on complex technologies

Would you like to be quoted in this article? It's very simple, contact us at dino@eiki.fr

CSS | NodeJS | DNS | DMARC | MAPI | NNTP | htaccess | PHP | HTTPS | Drupal | WEB3 | LLM | Wordpress | TLD | Domain name | IMAP | TCP | NFT | MariaDB | FTP | Zigbee | NMAP | SNMP | SEO | E-Mail | LXC | HTTP | MangoDB | SFTP | RAG | SSH | HTML | ChatGPT API | OSPF | JavaScript | Docker | OpenVZ | ChatGPT | VPS | ZIMBRA | SPF | UDP | Joomla | IPV6 | BGP | Django | Reactjs | DKIM | VMWare | RSYNC | Python | TFTP | Webdav | FAAS | Apache | IPV4 | LDAP | POP3 | SMTP

| Whispers of love (API) | Déclaration d'Amour |






Legal Notice / General Conditions of Use