IPTables Examples

As it is a table of rules, the first rule has precedence. If the first rule dis-allows everything then nothing else afterwards will matter.

* INIVIDUAL REJECTS FIRST
* THEN OPEN IT UP
* THEN BLOCK ALL

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

Add rule to Reject all from an IP Address:
iptables -A INPUT -s 136.xxx.xxx.xxx -d 136.xxx.xxx.xxx -j REJECT

Add rule to Allow in SSH from everywhere:
iptables -A INPUT -s 0.0.0.0/0 -d 136.xxx.xxx.xxx -p tcp –dport 22 -j ACCEPT

-I will insert the rule on top -A will append it last in list

You can either delete by number or by recreating the rule. “iptables -D
INPUT 3″ will remove the 3rd (counting from 1) rule. Or “iptables -D
INPUT -s 65.75.152.40 -j DROP” will remove the corresponding entry

iptables -D INPUT -s 127.0.0.1 -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

Examples:

http://defindit.com/readme_files/iptables.html

You can leave a response, or trackback from your own site.

Leave a Reply