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:
* Allow tcp traffic on port 8008 (rule is part of INPUT chain):
* Add a new chain 'mychain'
* Delete rule at position 2 (= second rule) in chain INPUT
* See how many packet/bytes have been used for each of the rules
See iptables 101 for more background info.
See the manpage for an overview of all cmds.
See also:
- http://involution.com/iptables_demo/
- https://help.ubuntu.com/community/IptablesHowTo
- http://varsecurity.blogspot.com/2009/03/iptables-tutorial.html
* 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 ACCEPTAdding / 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 mychainWhenever 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.
-I INPUT 2 -j mychain
* Delete rule at position 2 (= second rule) in chain INPUT
-D INPUT 2Listing chains / rules
* See how many packet/bytes have been used for each of the rules
iptables -L -v
Comments