I have multiple iptables entry, which DROP packets from different IPs on different ports. I would like to delete with one command all the rules matching a specific IP. From

man iptables

it seems be possible. How can I do this?

  • man iptables can use to find a information for your requirement. – Eranda Peiris Apr 21 '18 at 2:28
  • 1
    Here's a tip! Use ipset to extract the majority of ip addresses out of iptables. – cybernard Apr 21 '18 at 3:50
  • @ErandaPeiris I said I checked on man and there is not any reference about that – Rockietto Apr 22 '18 at 18:12

I doubt you can do this with a simple iptables command - there may be some frankenhack bash script you can use depending in your version of Linux (I'm thinking an iptables dump, grep,restore)

What you can do is insert an iptables rule at the start of the table to allow from that IP which will override everything that comes afterwards. Something like

 iptables -I INPUT -s X.X.X.X -j ACCEPT
 iptables -I INPUT -d X.X.X.X -j ACCEPT
iptables-save|grep -v 192\.168\.1\.1 >iptables-save && iptables -F && iptables-restore </iptables.save

You may have to use \ to delimited the period symbol

This will not match CIDR notation.

  1. Looking for will not find
  2. Searching for will not match against either.


  1. iptables-save #save the config
  2. grep -v # -v is exclude matching lines
  3. iptables-save # dump the new result to iptables-save

  4. && iptables -F # when done,flush all rules
  5. && iptables-restore

Adamm, the maker of skynet had made a script for exactly this for his iptables firewall; Hopefully this should do the trick. https://github.com/Adamm00/IPSet_ASUS/commit/56f4bad86ac64bf9c74c6d588f4cd2d83265ab1a

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.