How to open port in Linux
Solution 1
First, you should disable selinux
, edit file /etc/sysconfig/selinux
so it looks like this:
SELINUX=disabled
SELINUXTYPE=targeted
Save file and restart system.
Then you can add the new rule to iptables
:
iptables -A INPUT -m state --state NEW -p tcp --dport 8080 -j ACCEPT
and restart iptables with /etc/init.d/iptables restart
If it doesn't work you should check other network settings.
Solution 2
The following configs works on Cent OS 6 or earlier
As stated above first have to disable selinux.
Step 1 nano /etc/sysconfig/selinux
Make sure the file has this configurations
SELINUX=disabled
SELINUXTYPE=targeted
Then restart the system
Step 2
iptables -A INPUT -m state --state NEW -p tcp --dport 8080 -j ACCEPT
Step 3
sudo service iptables save
For Cent OS 7
step 1
firewall-cmd --zone=public --permanent --add-port=8080/tcp
Step 2
firewall-cmd --reload
![Niraj Chapla](https://i.stack.imgur.com/mpNol.jpg?s=256&g=1)
Niraj Chapla
I am fullstack java & python developer. I am working on integration product since 2011 and have expertise in the integration domain. Specialties Java, REST, Python, Django, Hibernate, XML, JSON, Web services, Ant and other open source technologies
Updated on July 08, 2022Comments
-
Niraj Chapla almost 2 years
I have installed and web application which is running on port 8080 on RHEL (centOS). I only have command line access to that machine. I have tried to access that application from my windows machine from which I am connected to server via command-line, but it is giving connection time out error.
Then I have tried to open port 8080. I have added following entry into the iptables.
-A INPUT -m state --state NEW -m tcp -p tcp --dport 8080 -j ACCEPT
After adding this into the iptables I have restarted it with -
/etc/init.d/iptables restart
But still I am not able to access that application from my windows machine.
Am I doing any mistake or missing something?
-
Niraj Chapla almost 11 yearsselinux is disable and selinuxtype is set to targeted and append rule to the iptables. Restarted the iptables as well but still not working. Need to check other network configuration
-
kmehta over 10 years@jabaldonedo I get a 9001 socket exception at exactly 2 hours of a mongodb load from a centos server. Could this be a solution to that? If so, in your opinion, do i have to do this on both the remote host and the requesting host or just the remote host? Thanks!
-
jabaldonedo over 10 yearsMaybe your problem is not related with CentOS, are you sure that your application is correctly configured? that error is a connection issue from MongoDB. I don't know what application are you trying to run, but I suggest you to check again its configuration and/or if you can, ask for some support help.
-
kmehta over 10 yearsYeah it's a mongodb client method "db.cloneCollection". I haven't found any sort of timeout configuration either on the mongo client or the mongod server process.
-
blackbird over 8 yearsRestarting iptables flused my new rule
-
AndrewT almost 7 yearsStep 3 fails save is not a valid parameter
-
Sireesh Yarlagadda over 6 yearsTry this for restart iptables-save
-
DisplayMyName over 4 yearsDid you see it's for CentOS 6 or earlier? Works for me.
-
manudicri over 3 yearsBad argument 'NEW'