Linux - Networking This 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.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
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.
 |
GNU/Linux Basic Guide
This 255-page guide will provide you with the keys to understand the philosophy of free software, teach you how to use and handle it, and give you the tools required to move easily in the world of GNU/Linux. Many users and administrators will be taking their first steps with this GNU/Linux Basic guide and it will show you how to approach and solve the problems you encounter.
Click Here to receive this Complete Guide absolutely free. |
|
 |
07-13-2007, 03:35 PM
|
#1
|
|
Member
Registered: Jul 2005
Distribution: Gentoo, Ubuntu
Posts: 318
Rep:
|
Issue with iptables
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.
(Replace ##.##.##.## with IP address).
What could be the problem?
|
|
|
|
07-13-2007, 03:53 PM
|
#2
|
|
Guru
Registered: May 2005
Location: Atlanta Georgia USA
Distribution: Redhat (RHEL), CentOS, Fedora, Debian, FreeBSD, HP-UX, Solaris, SCO
Posts: 5,644
|
Your script worked for me when I did a test.
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.
|
|
|
|
07-13-2007, 04:00 PM
|
#3
|
|
Member
Registered: Jul 2005
Distribution: Gentoo, Ubuntu
Posts: 318
Original Poster
Rep:
|
I've uploaded the file here so you can see for yourself. There's nothing wrong that I can see here, just IPs listed.
http://senduit.com/9bfa3e
Last edited by SentralOrigin; 07-13-2007 at 04:56 PM.
|
|
|
|
07-14-2007, 09:08 AM
|
#4
|
|
Guru
Registered: May 2005
Location: Atlanta Georgia USA
Distribution: Redhat (RHEL), CentOS, Fedora, Debian, FreeBSD, HP-UX, Solaris, SCO
Posts: 5,644
|
3900 pages of IPs?!
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.
|
|
|
|
07-14-2007, 10:11 AM
|
#5
|
|
Member
Registered: Sep 2006
Location: Munich, Germany
Distribution: Debian / Ubuntu
Posts: 292
Rep:
|
Hi,
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.
|
|
|
|
07-14-2007, 10:14 AM
|
#6
|
|
Guru
Registered: May 2005
Location: Atlanta Georgia USA
Distribution: Redhat (RHEL), CentOS, Fedora, Debian, FreeBSD, HP-UX, Solaris, SCO
Posts: 5,644
|
or run dos2unix against the IP file before hand.
But again I really would not add this many lines to iptables (even if possible).
|
|
|
|
07-14-2007, 03:42 PM
|
#7
|
|
Member
Registered: Jul 2005
Distribution: Gentoo, Ubuntu
Posts: 318
Original Poster
Rep:
|
Thanks everyone.
Quote:
|
Originally Posted by jlightner
3900 pages of IPs?!
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.)
|
|
|
|
| Thread Tools |
Search this Thread |
|
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
All times are GMT -5. The time now is 01:24 PM.
|
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|