Question: How do I open and close ports with an iptables firewall setup?
Answer: You can easily open ports on a dedicated server with these simply commands. Depending on whether you need to open a UDP or TCP port, use one or both of the following:
iptables -A INUPT -p tcp –dport -j ACCEPT
iptables -A INUPT -p udp –dport -j ACCEPT
And to close a port, enter:
iptables -A INUPT -p tcp –dport -j DROP
iptables -A INUPT -p udp –dport -j DROP
Then, save and restart iptables:
service iptables save
service iptables restart
You can keep track of which ports have been opened and closed by viewing the /var/log/messages file.
Photo: Flickr