Questions? Feedback? powered by Olark live chat software
Knowledgebase
Author Avatar

Ubuntu and Firewall Rules

Written by: on 05 August 2012 11:19 AM 05 August 2012 11:19 AM

With Ubuntu it's important to know how to set your iptables configuration to work at startup. Know the Ubuntu & Firewall Rules.

With Ubuntu it's important to know how to set your iptables configuration to work at startup. To do this first create your iptables rules (never use iptables -F to flush your rules or you will most likely lock yourself out of your SSH session):

iptables -P INPUT ACCEPT
iptables -A INPUT -i lo -j ACCEPT
iptables -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
iptables -I INPUT -p tcp -m tcp --dport 20:22 -j ACCEPT
iptables -I INPUT -p tcp -m tcp --dport 25 -j ACCEPT
iptables -I INPUT -p tcp -m tcp --dport 53 -j ACCEPT
iptables -I INPUT -p tcp -m tcp --dport 80 -j ACCEPT
iptables -I INPUT -p tcp -m tcp --dport 110 -j ACCEPT
iptables -I INPUT -p tcp -m tcp --dport 113 -j ACCEPT
iptables -I INPUT -p tcp -m tcp --dport 143 -j ACCEPT
iptables -I INPUT -p tcp -m tcp --dport 443 -j ACCEPT
iptables -A INPUT -p tcp --dport 10000 -j ACCEPT
iptables -P INPUT DROP
iptables -P FORWARD DROP
iptables -P OUTPUT ACCEPT
iptables -L -v
iptables-save

This will enable the common ports required and make your changes live. However, on startup they will be lost again. You should now follow the 'Configuration on startup' instructions found on the Ubuntu help page:

https://help.ubuntu.com/community/IptablesHowTo

This will help you setup your iptables rules file and make it run when your VPS starts up.

(0 vote(s))
Helpful
Not helpful