我使用CentOS 7,我必须确保端口2888和3888是开放的。

我读了这篇文章,但这并不管用,因为在CentOS 7操作系统上没有iptables保存命令。

有人告诉我上面的URL对CentOS 7无效。我应该跟着这个走。 但是这篇文章对我来说并不清楚我需要执行什么命令。

我还发现

firewall-cmd --zone=public --add-port=2888/tcp 

但这在重启后就不存在了。

所以我怎么能打开端口,使它幸存重启?


当前回答

你好在Centos 7 firewall-cmd。 是的,如果你用 Firewall-cmd——zone=public——add-port=2888/tcp .使用实例 但如果你重新加载防火墙 firewall-cmd——重载

你的配置不会被保存

你需要添加key

Firewall-cmd——permanent——zone=public——add-port=2888/tcp

其他回答

使用此命令查找您的活动区域:

firewall-cmd --get-active-zones

它会说public、dmz或其他东西。您应该只申请所需的区域。

在公开审判的情况下:

firewall-cmd --zone=public --add-port=2888/tcp --permanent

然后记得重新加载防火墙以使更改生效。

firewall-cmd --reload

否则,请将您的zone替换为public,例如,如果您的zone是dmz:

firewall-cmd --zone=dmz --add-port=2888/tcp --permanent

你好在Centos 7 firewall-cmd。 是的,如果你用 Firewall-cmd——zone=public——add-port=2888/tcp .使用实例 但如果你重新加载防火墙 firewall-cmd——重载

你的配置不会被保存

你需要添加key

Firewall-cmd——permanent——zone=public——add-port=2888/tcp

神之神的回答是正确的,但是 知道你可以使用以下方法也是很有用的:

firewall-cmd --permanent --zone=public --add-port=2888/tcp 

但如果是一个已知的服务,你可以使用:

firewall-cmd --permanent --zone=public --add-service=http 

然后重新加载防火墙

firewall-cmd --reload

[回答修改以反映Martin Peter的评论,原来的回答有-永久在命令行结束]

如果你熟悉centos 6或更早版本的iptables服务,你仍然可以通过手动安装使用iptables服务:

步骤1 => install epel repo

Yum安装epel-release

步骤2 => install iptables service . sh

Yum安装iptables-services

步骤3 =>停止防火墙服务

Systemctl停止防火墙

步骤4 =>启动时禁用防火墙服务

Systemctl禁用防火墙

步骤5 =>启动iptables服务

Systemctl启动iptables

步骤6 => enable iptables on startup

Systemctl启用iptables

最后,您现在可以在/etc/sysconfig/iptables编辑您的iptables配置。

所以->编辑规则->重新加载/重新启动。

做像更老的centos与相同的功能像防火墙。

使用以下命令查看开放端口:

firewall-cmd --list-ports

我们使用以下命令查看端口打开的服务:

firewall-cmd --list-services

我们使用以下命令查看端口开放的服务,并查看开放的端口:

firewall-cmd --list-all

要在防火墙中添加一个服务,我们使用下面的命令,在这种情况下,服务将使用防火墙中的任何端口打开:

firewall-cmd --add-services=ntp 

为了使这个服务永久打开,我们使用下面的命令:

firewall-cmd -add-service=ntp --permanent 

使用实例添加端口。

firewall-cmd --add-port=132/tcp  --permanent