Open ports with iptables
Linode
Linode Staff
My site isn't working. How do I open ports 80 and 443 with iptables?
1 Reply
rgerke
Linode Staff
You'll need to open those ports in order to get your site to work. To do that, you can set your iptables rules to do so. Here's a guide that gives you instructions on how to do that:
The rules that you're specifically looking to add in this situation are the following:
-A INPUT -p tcp --dport 80 -m state --state NEW -j ACCEPT
-A INPUT -p tcp --dport 443 -m state --state NEW -j ACCEPT
Here's the sample command sequence that is provided in our iptables guide:
iptables -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
iptables -A INPUT -i lo -m comment --comment "Allow loopback connections" -j ACCEPT
iptables -A INPUT -p icmp -m comment --comment "Allow Ping to work as expected" -j ACCEPT
iptables -A INPUT -p tcp -m multiport --destination-ports 22,25,53,80,443,465,5222,5269,5280,8999:9003 -j ACCEPT
iptables -A INPUT -p udp -m multiport --destination-ports 53 -j ACCEPT
iptables -P INPUT DROP
iptables -P FORWARD DROP
The ports given in this example are just that, an example. What this sequence of commands will do is drop all traffic to the system and then allow it on only certain ports. You can use the ports in the example, because 443 and 80 are included, but feel free to use only the ports that you want open.