Rayhan’s blog (raynux.com)

Rayhan’s Personal Web Blog Site

Entries Comments

IPTABLES quick command list

15 April, 2009 (12:09) | Fedora, Linux, Reference, Ubuntu

Tags: , , , ,

Iptables is the default and powerful firewall that works on almost all Linux version including Ubuntu and Fedora. Here I have listed some important commands and a short description of each command for quick help. It can help people who already know little Iptables.

manage chain:
# iptables -N new_chain				// create a chain
# iptables -E new_chain old_chain  		// edit a chain
# iptables -X old_chain				// delete a chain

redirecting packet to a user chain:
# iptables -A INPUT -p icmp -j new_chain

listing rules:
# iptables -L					// list all rules of all tables
# iptables -L -v				// display rules and their counters
# iptables -L -t nat				// display rules for a specific tables
# iptables -L -n --line-numbers			// listing rules with line number for all tables
# iptables -L INPUT -n --line-numbers		// listing rules with line number for specific table

manage rules:
# iptables -A chain				// append rules to the bottom of the chain
# iptables -I chain [rulenum]			// insert in chain as rulenum (default at the top or 1)
# iptables -R chain rulenum			// replace rules with rules specified for the rulnum
# iptables -D chain	rulenum			// delete rules matching rulenum (default 1)
# iptables -D chain				// delete matching rules

change default policy:
# iptables -P chain target			// change policy on chain to target
# iptables -P INPUT DROP			// change INPUT table policy to DROP
# iptables -P OUTPUT DROP			// change OUTPUT chain policy to DROP
# iptables -P FORWARD DROP			// change FORWARD chain policy to DROP




Comment from Thomas
Time: January 20, 2012, 9:30 pm

hell yeah man. This is perfect. Thanks :)

Comment from Gabriel
Time: April 6, 2013, 7:52 am

Thanks for sharing. This was very helpful :) .

Comment from anonymous
Time: May 16, 2013, 2:22 am

thanks for cheatsheet, but `iptables -L` lists rules for table `filter’, not for ‘all tables’

Write a comment