Simple IPTables Commands

24 Nov 2009

For the life of me I can't seem to remember these simple commands to edit my IPTables so I just wanted to document the few that I seem to be using the most:

View current rules
View a list of current rules
iptables -L

Insert a new rule
This will insert a new rule in the INPUT chain in the number 5 slot:
iptables -I INPUT 5 -p tcp --dport [port] -j ACCEPT

Delete specific rule
This will delete rule number 5 from the list. Change the 5 to whatever number you need to delete
iptables -D INPUT 5

Save rules to a file
Make sure to save the rules to a file so they are applied upon boot. Note that I needed to use the "sh -c" option for sudo or you will get a permission denied error
sudo sh -c "iptables-save >/etc/iptables.rules"


Tags:  | 

Comments

Post new comment

The content of this field is kept private and will not be shown publicly.
  • Lines and paragraphs break automatically.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd>

More information about formatting options