我使用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

其他回答

Fedora是通过iptables实现的

sudo iptables -I INPUT -p tcp --dport 3030 -j ACCEPT
sudo service iptables save

似乎有效

CentOS (RHEL) 7已经改变了防火墙,使用firewall-cmd,它有一个区域的概念,就像Windows版本的公共,家庭和私有网络。你应该看看这里,找出你认为你应该使用哪一个。EL7默认使用public,所以下面的示例使用public。

您可以使用firewall-cmd——list-all检查您正在使用的区域,并使用firewall-cmd——set-default-zone=<zone>来更改它。

然后你将知道哪个区域允许一个服务(或端口):

Firewall-cmd——permanent——zone=<zone>——add-service=http

Firewall-cmd——permanent——zone=<zone>——add-port=80/tcp

您可以通过运行以下命令检查端口是否已实际打开:

Firewall-cmd——zone=<zone>——query-port=80/tcp

Firewall-cmd——zone=<zone>——query-service=http

根据文档,

在永久模式下更改防火墙设置时,请 选项仅在重新加载防火墙或 系统重启。

您可以通过以下命令重新加载防火墙设置:firewall-cmd——reload。

如果你熟悉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与相同的功能像防火墙。

防火墙对于iptables老手来说有点不直观。对于那些喜欢使用iptables驱动的防火墙,并在易于配置的树中使用类似iptables的语法的人,可以尝试用fwtree替换firewall: https://www.linuxglobal.com/fwtree-flexible-linux-tree-based-firewall/ 然后做以下事情:

 echo '-p tcp --dport 80 -m conntrack --cstate NEW -j ACCEPT' > /etc/fwtree.d/filter/INPUT/80-allow.rule
 systemctl reload fwtree 

如果您在Centos 7防火墙中允许多个端口,那么我们可以使用以下命令。

#firewall-cmd --add-port={port number/tcp,port number/tcp} --permanent

#firewall-cmd --reload


And check the Port opened or not after reloading the firewall.


#firewall-cmd --list-port


For other configuration [Linuxwindo.com][1]