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.
Want to read Linux tips and tricks, but don't have time to check our blog everyday? Subscribe to our daily email newsletter to make sure you don't miss a single tip/tricks. Subscribe to our weekly newsletter here!
- Email FAQ to a friend
- Printable version
- Rss Feed
- Last Updated: 9-25-07

{ 2 comments… read them below or add one }
Hi
Do you know of any way that it does it automatically by getting a list of known spammers from the internet?
How to automatically block a user after multiple failed sshd logins say after 3 failed logins
for temporary time say 2 days.