Find the answer to your Linux question:
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.
  1. #1
    Just 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?

  2. #2
    Linux Guru
    Join Date
    Oct 2001
    Location
    Täby, Sweden
    Posts
    7,578
    Try this instead:
    Code:
    &#40;while &#58;; do read host; if &#91; -z "$host" &#93;; then break; fi; iptables -A FORWARD -j DROP -d "$host"; done&#41; <blocklist
    Provided there's no whitespace in the blocklist, these two work as well:
    Code:
    for host in `cat blocklist`; do iptables -A FORWARD -j DROP -d "$host"; done
    Code:
    xargs -i iptables -A FORWARD -j DROP -d &#123;&#125; <blocklist

  3. #3
    Just Joined!
    Join Date
    Dec 2003
    Posts
    41
    Thanks for the info. I'll give it a shot.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •