As most developers are lazy, I’m a huge fan of scripts. I’ve found myself lately having to add entries to iptables to block a single IP or a small subnet, so I made a quick script to make the job easier on myself.
Usage for both of these is of course really simple. Say
126.96.36.199 is the IP in question:
sudo ./blockip.sh 188.8.131.52 sudo ./allowip.sh 184.108.40.206
Block and allow the IP using iptables with these scripts:
#!/bin/bash #blocking iptables /sbin/iptables -A INPUT -s $1 -j DROP #saving iptables /sbin/iptables-save > /etc/sysconfig/iptables
#!/bin/bash #allowing iptables /sbin/iptables -D INPUT -s $1 -j DROP #saving iptables /sbin/iptables-save > /etc/sysconfig/iptables