Find the answer to your Linux question:
Results 1 to 3 of 3
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1

    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 ----
    -------- End of file ----

    I tried a command like the following:
    iptables -A FORWARD -j DROP -d `more blocklist` (note the backwards apostraphes)
    blocklist > iptables -A FORWARD -j DROP -d

    Any help?

  2. #2
    Linux Guru
    Join Date
    Oct 2001
    Täby, Sweden
    Try this instead:
    &#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:
    for host in `cat blocklist`; do iptables -A FORWARD -j DROP -d "$host"; done
    xargs -i iptables -A FORWARD -j DROP -d &#123;&#125; <blocklist

  3. #3
    Thanks for the info. I'll give it a shot.

  4. $spacer_open

Posting Permissions

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