Linux 如何在centOS中打开端口
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/19034542/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to open port in centOS
提问by Niraj Chapla
I have installed and web application which is running on port 8080 on centOS. I only have command line access (through putty) to that machine. I have tried to access that application from my windows machine from which I am connected through putty, but it is giving connection time out error.
我已经安装了在 centOS 上的端口 8080 上运行的 Web 应用程序。我只有命令行访问(通过腻子)到那台机器。我试图从我通过腻子连接的 Windows 机器访问该应用程序,但它给出了连接超时错误。
Then I have tried to open port 8080. I have added following entry into the iptables.
然后我尝试打开端口 8080。我在 iptables 中添加了以下条目。
-A INPUT -m state --state NEW -m tcp -p tcp --dport 8080 -j ACCEPT
-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
将其添加到 iptables 后,我已重新启动它 -
/etc/init.d/iptables restart
But still I am not able to access that application from my windows machine.
但是我仍然无法从我的 Windows 机器访问该应用程序。
Am I doing any mistake or missing something?
我做错了什么或遗漏了什么吗?
采纳答案by jabaldonedo
First, you should disable selinux
, edit file /etc/sysconfig/selinux
so it looks like this:
首先,您应该禁用selinux
,编辑文件/etc/sysconfig/selinux
,使其看起来像这样:
SELINUX=disabled
SELINUXTYPE=targeted
Save file and restart system.
保存文件并重新启动系统。
Then you can add the new rule to iptables
:
然后您可以将新规则添加到iptables
:
iptables -A INPUT -m state --state NEW -p tcp --dport 8080 -j ACCEPT
and restart iptables with /etc/init.d/iptables restart
并重新启动iptables /etc/init.d/iptables restart
If it doesn't work you should check other network settings.
如果它不起作用,您应该检查其他网络设置。
回答by Nirojan Selvanathan
The following configs works on Cent OS 6 or earlier
以下配置适用于 Cent OS 6 或更早版本
As stated above first have to disable selinux.
如上所述,首先必须禁用selinux。
Step 1nano /etc/sysconfig/selinux
步骤 1nano /etc/sysconfig/selinux
Make sure the file has this configurations
确保文件具有此配置
SELINUX=disabled
SELINUXTYPE=targeted
Then restart the system
然后重启系统
Step 2
第2步
iptables -A INPUT -m state --state NEW -p tcp --dport 8080 -j ACCEPT
Step 3
第 3 步
sudo service iptables save
For Cent OS 7
对于 Cent OS 7
step 1
第1步
firewall-cmd --zone=public --permanent --add-port=8080/tcp
Step 2
第2步
firewall-cmd --reload