on  it road.com

3. 添加端口

在 /etc/services 文件中添加测试端口,并允许该端口接受数据包。
可以通过编辑以下格式的 /etc/services 文件来添加测试端口:

# vi /etc/services
service-name  port/protocol  [aliases ...]   [# comment]
# vi /etc/services
testport        55555/tcp   # Application Name

2.检查iptables中的端口状态

检查 iptables 是否未显示该端口打开:

# iptables-save | grep 55555

4. 打开防火墙端口

添加防火墙规则以允许端口接受数据包:

# firewall-cmd --zone=public --add-port=55555/tcp --permanent
success
# firewall-cmd --reload
success
# iptables-save | grep 55555
-A IN_public_allow -p tcp -m tcp --dport 55555 -m conntrack --ctstate NEW -j ACCEPT

5.查看新增端口状态

添加 httpd 端口并重新加载 httpd 服务后,注意现在 httpd 也在监听新添加的端口 55555:

# lsof -i -P |grep http
httpd     6595   root    4u  IPv6  43709      0t0  TCP *:80 (LISTEN)
httpd     6595   root    6u  IPv6  43713      0t0  TCP *:55555 (LISTEN)
# netstat -na |grep 55555
tcp6       0      0 :::55555                :::*                    LISTEN

1.检查端口状态

检查端口是否未打开且 Apache 未显示该端口:

# netstat -na | grep 55555
# lsof -i -P |grep http
httpd     5823   root    4u  IPv6  42212      0t0  TCP *:80 (LISTEN)
如何在 CentOS/RHEL 7 中打开端口

TCP/IP 网络连接可能被阻止、丢弃、打开或者过滤。
这些操作通常由系统使用的 IPtables 防火墙控制,并且独立于可能正在侦听网络端口的任何进程或者程序。
这篇文章将概述打开应用程序所需端口的步骤。
对于这个帖子示例,我们将打开应用程序特定 (Apache) 端口 55555.

服务器详情如下:

# uname -a
Linux onitroad 3.10.0-693.17.1.el7.x86_64 #1 SMP Thu Jan 25 20:13:58 UTC 2018 x86_64 x86_64 x86_64 GNU/Linux
# cat /etc/redhat-release 
CentOS Linux release 7.4.1708 (Core)
日期:2020-09-17 00:13:45 来源:oir作者:oir