Centos – How to open a port in Centos 6

centoscentos6port

I'm a newbie at Centos. I need to open a few ports in Centos.

I've googled it a little bit, and found something like this.

-A RH-Firewall-1-INPUT -m state --state NEW -m tcp -p tcp --dport 143 -j ACCEPT

But it gives the following error when i try to restart iptables

iptables: Applying firewall rules: iptables-restore: line 13 failed

How can I open ports in Centos 6

Best Answer

If you want to open a single port:

-A INPUT -m state --state NEW -m tcp -p tcp --dport 143 -j ACCEPT

For multiple, you can use the following instead (or repeat the above line multiple times):

-A INPUT -m state --state NEW -m tcp -p tcp -m multiport --dports 22,80,143 -j ACCEPT

The reason your line doesn't work is likely because you don't have a chain named 'RH-Firewall-1-INPUT'. CentOS 6 simply uses 'INPUT' as the chain name. You'll note something like the following at the top of the default config, naming the chains that exist:

:INPUT ACCEPT [0:0]
:FORWARD ACCEPT [0:0]
:OUTPUT ACCEPT [0:0]

Just to explain a bit further, the line -A INPUT -m state --state NEW -m tcp -p tcp --dport 143 -j ACCEPT means:

  • -A: append a rule
  • INPUT: to the INPUT chain
  • -m state: use the 'state' module
  • --state NEW: only look for NEW connections (i.e. not those that are previously established/related)
  • -m tcp: use the tcp module
  • -p tcp: look for packets using the TCP protocol
  • --dport 143: look for packets with a destination port of 143