Author Topic: How Do I Block an IP Address on My Linux server?  (Read 4419 times)

Offline admin

  • Administrator
  • Sr. Member
  • *****
  • Posts: 296
    • View Profile
How Do I Block an IP Address on My Linux server?
« on: April 02, 2011, 01:21:02 AM »
How do I block an IP address or subnet under Linux operating system?

In order to block an IP on your Linux server you need to use iptables tools (administration tool for IPv4 packet filtering and NAT) and netfilter firewall. First you need to log into shell as root user. To block an IP address you need to type the iptables command as follows:

Syntax to block an IP address under Linux
Code: [Select]
iptables -A INPUT -s IP-ADDRESS -j DROPReplace IP-ADDRESS with your actual IP address. For example, if you wish to block an ip address 65.55.44.100 for whatever reason then type the command as follows:
Code: [Select]
# iptables -A INPUT -s 65.55.44.100 -j DROPIf you have IP tables firewall script, add the above rule to your script.

If you just want to block access to one port from an ip 65.55.44.100 to port 25 then type command:
Code: [Select]
# iptables -A INPUT -s 65.55.44.100 -p tcp --destination-port 25 -j DROPThe above rule will drop all packets coming from IP 65.55.44.100 to port mail server port 25.

CentOS / RHEL / Fedora Block An IP And Save It To Config FileType the following two command:
Code: [Select]
# iptables -A INPUT -s 65.55.44.100 -j DROP
# service iptables save

How Do I Unblock An IP Address?
Use the following syntax (the -d options deletes the rule from table):
# iptables -D INPUT -s xx.xxx.xx.xx -j DROP
Code: [Select]
# iptables -D INPUT -s 65.55.44.100 -j DROP
# service iptables save