Block ip address of spammers with iptables under Linux

by on September 25, 2007 · 4 comments· LAST UPDATED September 25, 2007

in , ,

Q. How do I block ip address of spammers with iptables based firewall under CentOS Linux 5?

A. You can simply block IP address of spammers by editing /etc/sysconfig/iptables file under:

a) CentOS Linux
b) Fedora Linux
c) RHEL 4.x/5.x etc

Open file /etc/sysconfig/iptables:
# vi /etc/sysconfig/iptables
Append ip address of spammers as follows:
-A RH-Firewall-1-INPUT -s SPAMMER-IP -j DROP
-A RH-Firewall-1-INPUT -s SPAMMER-SUBNET-BLOCK -j DROP

Save and close the file. Just restart the firewall:
# /etc/init.d/iptables restart

You can also create a small shell script to block lots of IP address at a time.

TwitterFacebookGoogle+PDF versionFound an error/typo on this page? Help us!

{ 4 comments… read them below or add one }

1 Andy September 25, 2007 at 7:20 pm

Hi

Do you know of any way that it does it automatically by getting a list of known spammers from the internet?

Reply

2 kunal October 15, 2007 at 6:16 am

How to automatically block a user after multiple failed sshd logins say after 3 failed logins
for temporary time say 2 days.

Reply

3 ccpizza August 30, 2009 at 12:13 pm

2kunal:
check out denyhosts (http://denyhosts.sourceforge.net)

Reply

4 dbw October 3, 2009 at 12:21 pm

Check out project honey pot. They have a list of spammers, and you can also help find spamming ips by joining their project.

Reply

Leave a Comment

Tagged as: , , , , ,

Previous Faq:

Next Faq: