Saturday, May 1, 2010

List iptable rules

List iptable rules:
iptables -n -L (-n prevents slow reverse DNS lookup)

Reject all from an IP Address:
iptables -A INPUT -s -d -j REJECT

Allow in SSH:
iptables -A INPUT -d -p tcp --dport 22 -j ACCEPT

If Logging - Insert Seperate Line *BEFORE* the ACCEPT / REJECT / DROP
iptables -A INPUT -d -p tcp --dport 3306 -j LOG
iptables -A INPUT -d -p tcp --dport 3306 -j ACCEPT
Block All:
iptables -A INPUT -j REJECT

Remove / Delete an individual /single Iptable Rule
iptables -D INPUT -s -p tcp --dport 111 -j ACCEPT
// -D = delete appropriate rule. If you dont know the exact syntax of the rule to delete do the following:
iptables -L
//count down the number of lines until you reach the rule you wish to delete
iptables -D INPUT 4
//format = iptables -D CHAIN #Rule_No

Saving ALL IPTABLE Rules
It seems that the method for saving & loading iptable rules from /etc/init.d/iptables load|save active|inactive does not save NAT rules.
The command for saving iptable rules manually is:
root:~# iptables-save > rules-saved
There is also command called iptables-restore. It is:
root:~# iptables-restore rules-saved

No comments:

Post a Comment