Here are some quick IPtables’ commands :-

To list the rules related to a particular IP Address:

iptables -L -n | grep (IP Address)

To insert a rule ( block) :

iptables -I INPUT -s (IP) -j DROP

To insert a rule ( allow) :

iptables -I INPUT -s (IP) -j ACCEPT

To delete a rule :

iptables -D INPUT -s (IP) -j DROP

To block access to a particular port :

iptables -A INPUT -s (IP) -p tcp –destination-port (port number) -j DROP

To see the number of connections to ‘http’ :

netstat -nap | grep :80 | wc –l

To show total no: of connections per IP

netstat -ntu | awk ‘{print $5}’ | cut -d: -f1 | sort | uniq -c | sort –n

To flush iptables :

iptables -F

Note: The above load the chains/rules into the ram memory only and won’t hold after a server reboot. You must run the ‘save’ command in order to keep your settings.

service iptables save


Shares
Contact Us On WhatsApp