iptables commands

Here, we'll show some examples of common iptables commands.
See iptables 101 for more background info.
See the manpage for an overview of all cmds.
See also:
Appending rules

* Allow tcp traffic on port 8008 (rule is part of INPUT chain):
-A INPUT -p tcp --dport 8008 -j ACCEPT
* Allow all UDP traffic on ports 5432-5435
-A INPUT -p udp -m multiport --dports 5432,5433,5434,5435 -j ACCEPT
* Allow packet that have ESTABLISHED or RELATED state:
-A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
Adding / Deleting chains

* Add a new chain 'mychain'
-N mychain
* Make 'mychain' branch off from the INPUT chain (append or input as rule nr X)
-A INPUT -j mychain
-I INPUT 2 -j mychain
Whenever you jump to a custom chain, the packet will first pass though the rules in the custom chain ('mychain'), then continue down the original chain (INPUT). Note that if the jump to the custom chain is appended after rules in the original chain, these rules will be executed first.

* Delete rule at position 2 (= second rule) in chain INPUT
-D INPUT 2
Listing chains / rules

* See how many packet/bytes have been used for each of the rules
iptables -L -v

Comments

Popular posts from this blog

Handling control characters (escaping) in python for json and mysql

python port sniffer with pcapy and impacket

Django field, form and model validation process