How to open a port in iptables?

Posted on In QA, Tutorial

How to open a port, say 3389, in iptables to allow incoming traffics to it?

There are several cases for this question: ipv4 or ipv6 or both, TCP or UDP or both and which interface?

For simplicity, I give commands to allow all (ipv4 and ipv6, TCP and UDP from all interfaces) using port 3389 as an example. You may choose which ones to be used. For other ports, replace 3389 with the port you want to open.

# allow TCP ipv4
iptables -I INPUT -p tcp --dport 3389 -j ACCEPT
# allow UDP ipv4
iptables -I INPUT -p udp --dport 3389 -j ACCEPT
# allow TCP ipv6
ip6tables -I INPUT -p tcp --dport 3389 -j ACCEPT
# allow UDP ipv6
ip6tables -I INPUT -p udp --dport 3389 -j ACCEPT

Note that the rules are in memory only after these commands and will be lost after Linux reboots. If you would like to make it permanent (take effect after reboot), please checkĀ How to make iptables/ip6tables configurations permanent across reboot on CentOS 7 Linux? .

Leave a Reply

Your email address will not be published. Required fields are marked *