APLawrence.com -  Resources for Unix and Linux Systems, Bloggers and the self-employed

Managing iptables drop lists

© May 2015 Anthony Lawrence

I've talked about my Logdropper script before. While making some changes to that script, I screwed up and accidentally blocked far more addresses than I wanted to. I could have just reset iptables entirely or rebooted, but I only wanted to get rid of the ones I just added.

Bash brace expansion helped me out (see Bash 3.00 brace expansion and Bash Brace Expansion). I can get a list of DROPS easily:

# /sbin/iptables --list -n --line-numbers | grep DROP 
5    DROP       all  --           
6    DROP       all  --           
7    DROP       all  --           
8    DROP       all  --           
9    DROP       all  --           
10   DROP       all  --           
11   DROP       all  --           
12   DROP       all  --           
13   DROP       all  --           
14   DROP       all  --           
15   DROP       all  --           
16   DROP       all  --           
17   DROP       all  --           
18   DROP       all  --           
19   DROP       all  --           
20   DROP       all  --     

I knew that the new rules started at line 8. You delete rules with "iptables -D INPUT linenumber" (assuming your DROPS are in the INPUT chain, see Understanding IPTABLES). Obviously it would be tedious to do that manually, so we will use brace expansion. However, we can't say "for i in {8..20}" because the lines will renumber after each command. Fortunately, Bash doesn't object to counting down:

for i in {20..8}; 
do iptables -D INPUT $i

Simple, right?

Got something to add? Send me email.

(OLDER)    <- More Stuff -> (NEWER)    (NEWEST)   

Printer Friendly Version

-> Managing iptables drop lists

Inexpensive and informative Apple related e-books:

iOS 10: A Take Control Crash Course

Are Your Bits Flipped?

Take Control of Pages

Sierra: A Take Control Crash Course

Take Control of iCloud

More Articles by © Anthony Lawrence

Printer Friendly Version

Have you tried Searching this site?

This is a Unix/Linux resource website. It contains technical articles about Unix, Linux and general computing related subjects, opinion, news, help files, how-to's, tutorials and more.

Contact us

Printer Friendly Version

The difference between e-mail and regular mail is that computers handle e-mail, and computers never decide to come to work one day and shoot all the other computers. (Jamais Cascio)

Linux posts

Troubleshooting posts

This post tagged:





Unix/Linux Consultants

Skills Tests

Unix/Linux Book Reviews

My Unix/Linux Troubleshooting Book

This site runs on Linode