Blocking IP Addresses using IPtables

The following article describes various ways to block IPs using the built-in RedHat firewall, iptables. The following command will drop all incoming connections from IP xx.xx.xx.xx:

iptables -I INPUT -s xx.xx.xx.xx -j DROP

To block a range, such as xx.xx.xx.* specify the CIDR block as follows:

iptables -I INPUT -s xx.xx.xx.0/24 -j DROP

If you wanted to later remove this entry you would replace the -I with -D as follows:

iptables -D INPUT -s xx.xx.xx.xx -j DROP
iptables -D INPUT -s xx.xx.xx.0/24 -j DROP