Linux - SoftwareThis forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
how do i use iptables to block a large range of IPs from an ISP?
I want to block 220.128.0.0 - 220.143.255.255 from an ISP in Taiwan that is spamming my network via an old virus and causing my little IPCop to work much harder then it needs to.
I am talking several hundred hits per min from the same IP and when i dig deeper into my firewall logs it shows multiple computers from the same ISP hitting my network almost 24/7 for the past week or so.
now granted even if it did breach my firewall, it will do zero damage to my computer (im running OSx at the office and this is a MS virus) so that is not my concern. i just want to block that ISP and be done with them.
I know that if i use the following line i can block out a full range from 0 - 255, but how do i go past the first set of octects? (think that is the correct word for it)
Code:
# blocks HINET from Taipei Taiwan, CHTD, Chugnhwa Telecom Co., Ltd.
/sbin/iptables -A CUSTOMINPUT -s 220.128.0.0/24 -j DROP
but as you see above they have many more IP ranges, then just the 220.128.x.x that i just blocked with that single line. do i have to create a line for every 220.129, 220.130, etc... up to 220.143, or is there a faster, better way? many thanks.
do i have to create a line for every 220.129, 220.130, etc... up to 220.143, or is there a faster, better way? many thanks.
As far as I know, you need a line per ip block.
Quote:
i think a line like
$IPTABLES -A INPUT -i eth0 -s 220.128.0.0/220.143.255.255 -j REJECT
Correct. It can be entered in the format:
$IPTABLES -A INPUT -i eth0 -s 220.128.0.0/12 -j REJECT
and iptables will create it as:
220.128.0.0/220.143.255.255
Also, if you're looking to reduce spam significantly, you might want to block traffic to port 25 from countries like Korea, China, Hong-Kong, Taiwan, India, Indonesia. See http://www.hakusan.tsg.ne.jp/tjkawa/...er/index-e.jsp
This is why it's a good practice to deny by default and only allow those subnets that really need access. Once you get into the blacklist game, you may wind up with a long, unwieldy list of rules.
Also, instead of using the REJECT target, use the DROP target. If they're going to hammer you, don't do them the favor of sending back an error packet. Put 'em into the proverbial black hole for a bit.
This is why it's a good practice to deny by default and only allow those subnets that really need access. Once you get into the blacklist game, you may wind up with a long, unwieldy list of rules.
If you're running servers like web/mail, it's impossible to know ahead of time what subnets are going to need access to your machine.
So the only practical way is to list all ip blocks to deny. I have over 1,200 entries that block many Asian countries from connecting to port 25. I don't see any impact of the large file on my machine.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.