Opening a port on CentOS 6

For example, if you want to open port 80,

iptables -A INPUT -p tcp -m tcp --dport 80 -j ACCEPT

In the above example, –dport 80 signifies the port number to be opened, replacing 80 with another port number opens that port, for example, if we wish to open port 8080,

iptables -A INPUT -p tcp -m tcp --dport 8080 -j ACCEPT

iptables-save

service iptables restart

Opening a port on CentOS 7

Usually firewalld is the default on all CentOS 7 machines but you can switch to iptables as well

If using firewalld:

firewall-cmd --zone=public --add-port=PORT_HERE/tcp --permanent firewall-cmd --reload

If using iptables:

iptables -A INPUT -p tcp -m tcp --dport PORT_HERE -j ACCEPT service iptables reload

Replace PORT_HERE with the port you wish to open.

Example

IPTables

iptables -A INPUT -p tcp -m tcp --dport 80 -j ACCEPT service iptables reload Will open port 80 if using iptables

Firewalld

firewall-cmd --zone=public --add-port=80/tcp --permanent firewall-cmd --reload Will open port 80 if using firewall-cmd


Last modified: August 03 2017 19:21:19