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 -- 209.51.197.0/24 0.0.0.0/0 6 DROP all -- 103.6.213.150 0.0.0.0/0 7 DROP all -- 148.251.184.96 0.0.0.0/0 8 DROP all -- 148.251.187.69 0.0.0.0/0 9 DROP all -- 173.209.49.90 0.0.0.0/0 10 DROP all -- 173.45.125.154 0.0.0.0/0 11 DROP all -- 209.190.6.194 0.0.0.0/0 12 DROP all -- 213.241.67.51 0.0.0.0/0 13 DROP all -- 49.50.69.30 0.0.0.0/0 14 DROP all -- 5.101.146.50 0.0.0.0/0 15 DROP all -- 62.210.245.47 0.0.0.0/0 16 DROP all -- 62.212.73.131 0.0.0.0/0 17 DROP all -- 68.168.114.42 0.0.0.0/0 18 DROP all -- 88.150.131.58 0.0.0.0/0 19 DROP all -- 94.229.76.218 0.0.0.0/0 20 DROP all -- 95.141.32.156 0.0.0.0/0
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 done
Simple, right?
Got something to add? Send me email.
More Articles by Anthony Lawrence © 2015-05-05 Anthony Lawrence
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)
Printer Friendly Version
Managing iptables drop lists Copyright © May 2015 Tony Lawrence
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