Block IP Address on CentOS / Redhat

To block / unblock an IP address, you’d update iptables setting (root / sudoer only).

List existing IP Address rules

Block an IP address
iptables -A INPUT -s IP_ADDRESS -j DROP
iptables -A OUTPUT -d IP_ADDRESS -j DROP

Block the IP address to access an port then type command:
iptables -A INPUT -s IP_ADDRESS -p tcp --destination-port PORT -j DROP

save the configuration and refresh firewall

Block a range of IP addresses
iptables -A INPUT -s xxx.yyy.zzz.12/16 -j DROP

Unblock an IP Address
iptables -D INPUT -s IP_ADDRESS -j DROP

Another way is manually update /etc/sysconfig/iptables while the approach is not recommended.

Share on FacebookShare on Google+Tweet about this on TwitterShare on LinkedInShare on RedditShare on StumbleUponEmail this to someoneShare on TumblrDigg this

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">