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

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

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

我还发现

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

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

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


当前回答

虽然ganeshragav和Sotsir提供了正确且直接适用的方法,但值得注意的是,您可以将自己的服务添加到/etc/firewall /services.为了获得灵感,请查看/usr/lib/firewall /services/,其中包含firewall的预定义服务。

这种方法的优点是,稍后您将知道为什么这些端口是打开的,正如您在服务文件中所描述的那样。此外,您现在可以将其应用到任何区域,而没有拼写错误的风险。此外,对服务的更改不需要分别应用到所有区域,而只需应用到服务文件。

例如,可以创建/etc/firewall /services/foobar.xml:

<?xml version="1.0" encoding="utf-8"?>
<service>
  <short>FooBar</short>
  <description>
    This option allows you to create FooBar connections between
    your computer and mobile device. You need to have FooBar
    installed on both sides for this option to be useful.
  </description>
  <port protocol="tcp" port="2888"/>
  <port protocol="tcp" port="3888"/>
</service>

(有关语法的信息,请参阅do man firewall .service。)

一旦创建了这个文件,您可以firewall-cmd—reload使其可用,然后永久地将其添加到某个带

firewall-cmd --permanent --zone=<zone> --add-service=foobar

跟着firewall-cmd -reload使它立即激活。

其他回答

Fedora是通过iptables实现的

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

似乎有效

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

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

如果您在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]

虽然ganeshragav和Sotsir提供了正确且直接适用的方法,但值得注意的是,您可以将自己的服务添加到/etc/firewall /services.为了获得灵感,请查看/usr/lib/firewall /services/,其中包含firewall的预定义服务。

这种方法的优点是,稍后您将知道为什么这些端口是打开的,正如您在服务文件中所描述的那样。此外,您现在可以将其应用到任何区域,而没有拼写错误的风险。此外,对服务的更改不需要分别应用到所有区域,而只需应用到服务文件。

例如,可以创建/etc/firewall /services/foobar.xml:

<?xml version="1.0" encoding="utf-8"?>
<service>
  <short>FooBar</short>
  <description>
    This option allows you to create FooBar connections between
    your computer and mobile device. You need to have FooBar
    installed on both sides for this option to be useful.
  </description>
  <port protocol="tcp" port="2888"/>
  <port protocol="tcp" port="3888"/>
</service>

(有关语法的信息,请参阅do man firewall .service。)

一旦创建了这个文件,您可以firewall-cmd—reload使其可用,然后永久地将其添加到某个带

firewall-cmd --permanent --zone=<zone> --add-service=foobar

跟着firewall-cmd -reload使它立即激活。

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

你的配置不会被保存

你需要添加key

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