Take the 2-minute tour ×

I'm new to opening up ports in CentOS. I need to open up tcp port 8080 and have installed/ran nmap to find it is not open already. I've been reading about the iptables command, I have v1.3.5 installed but I really don't know where to start with it regarding opening up this port.

I'd appreciate a code sample or at least a link to a guide to opening this port using iptables (or any other good method.)

Thank you.

share|improve this question
add comment

2 Answers

up vote 9 down vote accepted

I always like to add a comment and limit scope in my firewall rules.

If I was opening up tcp port 8080 from everywhere (no scope limiting needed) for Tomcat I would run the following command

iptables -A INPUT -m state --state NEW -m tcp -p tcp --dport 8080 -j ACCEPT -m comment --comment "Tomcat Server port"

Then make sure to save your running iptables config so that it goes into effect after the next restart

service iptables save 

Note: you'll need to have the comment module installed for that part to work, probably a good chance that it is if you are running Centos 5 or 6


If you want to limit scope you can use the -s flag. Here is an example on how to limit traffic to 8080 from the 192.168.1 subnet

iptables -A INPUT -m state --state NEW -m tcp -p tcp --dport 8080 -s -j ACCEPT -m comment --comment "Tomcat Server port"
share|improve this answer
I performed the first statement you listed, saved it, and restarted the server. I can't seem to see the 8080 opened using nmap? –  user1062058 Dec 17 '11 at 2:01
In case anbody has experienced that the port didn't open after giving this command, you may have a target REJECT already existing in the INPUT chain and your new rule only added after that (I had this problem) which never reaches. So you have to insert your rule before the REJECT. First use iptables -L -n --line-numbers to display all rules with numbers and then use iptables -I INPUT <n> instead of iptables -A INPUT in the command in the answer (where <n> was the number of the REJECT target). This will insert your new rule above the REJECT and it should work. –  prajeesh kumar Sep 11 '12 at 4:35
add comment

See the CentOS docs: http://www.centos.org/docs/5/html/5.2/Deployment_Guide/ch-iptables.html and the wiki: http://wiki.centos.org/HowTos/Network/IPTables

share|improve this answer
Hi, the wiki seemed to clear things up more than the docs. Would this be a good command ? iptables -A INPUT -p tcp --dport 8080 -j ACCEPT –  user1062058 Dec 16 '11 at 23:09
Yes, this is the command. –  Stone Dec 17 '11 at 7:24
add comment

Your Answer


