Linux - NetworkingThis forum is for any issue related to networks or networking.
Routing, network cards, OSI, etc. Anything is fair game.
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.
I have a list of IPs that I want to block, so I made a script to use iptables to block them. The IP list is one IP per line and the file is named "newips". The script is named "ipblock.sh". Both are located in /home/oranges.
Code:
#!/bin/bash
for IP in `cat /home/oranges/newips`; do iptables -A INPUT -s $IP -j DROP; done
So I can the script by su'ing and then typed "sh /home/oranges/ipblock.sh", and the script runs, but for every IP on the list, I get this error:
Code:
' not found.3.5: host/network `##.##.##.##
Try `iptables -h' or 'iptables --help' for more information.
This suggests that one of the following is the issue:
A) You have something in the IP file other than IPs in the form ##.##.##.## (do you have quotes or tics in the file? Are you trying to append network with "/". If so you may need to escape or quote the "/" as it has special meaning to the shell.
B) iptables isn't on when you ran your script.
Every packet you have would take forever to check all your rules!
What exactly are you trying to accomplish? That is I know you want to block these IPs but to what end? It seems you might be better off writing rules for the IPs you DO allow - OR block entire ranges (e.g. those assigned to specific countries) if you're trying to block hack attempts.
apart from the fact that your list of ips is *huge* -- the problem you have is because that list is in DOS format, i.e. lines are terminated with \r\n instead of just \n.
So if you modify your script like
Code:
#!/bin/bash
for IP in `tr -d '\r' < /home/oranges/newips`; do iptables -A INPUT -s $IP -j DROP; done
it should work. But having 200000+ rules is probably not such a hot idea (don't know if it's possible at all to add that many rules).
If you really need to filter that many individual ips you probably want to at least do some cascading to substantially reduce the number of rules that have to be traversed for each packet.
Every packet you have would take forever to check all your rules!
What exactly are you trying to accomplish? That is I know you want to block these IPs but to what end? It seems you might be better off writing rules for the IPs you DO allow - OR block entire ranges (e.g. those assigned to specific countries) if you're trying to block hack attempts.
I want to allow all IPs except those. I'm trying to block ads, porn, government IPs, spyware, etc. that might connect somehow (through browser, torrent client, programs, etc.)
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.