Results 1 to 3 of 3
I know the below question sounds like it might belong in another area, but please stick with me here ...
What command might I use to make IPTables parse a ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
- 01-29-2004 #1Just Joined!
- Join Date
- Dec 2003
- Posts
- 41
Want to send list of hosts to IPTables?
I know the below question sounds like it might belong in another area, but please stick with me here ...
What command might I use to make IPTables parse a list of hostnames and add them to the firewall? I want to be able to take a list of hosts in a file called "blocklist" and use one command to add all of them to IPTables.
Say the file looks like this:
-------- Start of file ----
www.yahoo.com
www.hotmail.com
-------- End of file ----
I tried a command like the following:
iptables -A FORWARD -j DROP -d `more blocklist` (note the backwards apostraphes)
or:
blocklist > iptables -A FORWARD -j DROP -d
Any help?
- 01-29-2004 #2Linux Guru
- Join Date
- Oct 2001
- Location
- Täby, Sweden
- Posts
- 7,578
Try this instead:
Provided there's no whitespace in the blocklist, these two work as well:Code:(while :; do read host; if [ -z "$host" ]; then break; fi; iptables -A FORWARD -j DROP -d "$host"; done) <blocklist
Code:for host in `cat blocklist`; do iptables -A FORWARD -j DROP -d "$host"; done
Code:xargs -i iptables -A FORWARD -j DROP -d {} <blocklist
- 02-10-2004 #3Just Joined!
- Join Date
- Dec 2003
- Posts
- 41
Thanks for the info. I'll give it a shot.


Reply With Quote
