CentOS升级到7之后用firewall代替了iptables来设置Linux端口,

下面是具体的设置方法:

SRE实战 互联网时代守护先锋,助力企业售后服务体系运筹帷幄!一键直达领取阿里云限量特价优惠。

[]:选填

<>:必填

[<zone>]:作用域(block、dmz、drop、external、home、internal、public、trusted、work)

<port>:端口号

[-<port>]:或者端口范围

<protocol>:端口协议(tcp、udp)协议目前支持这四种类型Linux CentOS 7 防火墙与端口设置操作 随笔 第1张

[<seconds>]:过期时间,使用N秒后自动关闭(秒)

[--permanent]:永久设置,在重启后依然保证设置可用,如果不加此项,重启后端口会恢复关闭状态

注:设置端口后要重启防火墙使其生效 firewall-cmd --reload

 

1、检查端口状态

yes:已开通 

no:未开通 

firewall-cmd --query-port=<port>[-<port>]/<protocol>
firewall-cmd [--zone=<zone>] --query-port=<port>[-<port>]/<protocol>
firewall-cmd [--permanent] [--zone=<zone>] --query-port=<port>[-<port>]/<protocol>

Linux CentOS 7 防火墙与端口设置操作 随笔 第2张

Linux CentOS 7 防火墙与端口设置操作 随笔 第3张

查看已开放的端口

firewall-cmd --zone=public --list-ports

Linux CentOS 7 防火墙与端口设置操作 随笔 第4张

 

2、启用端口

success:执行成功

warning:警告xxx

firewall-cmd --add-port=<port>[-<port>]/<protocol>
firewall-cmd [--zone=<zone>] --add-port=<port>[-<port>]/<protocol> [--timeout=<seconds>]
firewall-cmd [--permanent] [--zone=<zone>] --add-port=<port>[-<port>]/<protocol>

Linux CentOS 7 防火墙与端口设置操作 随笔 第5张

Linux CentOS 7 防火墙与端口设置操作 随笔 第6张

Linux CentOS 7 防火墙与端口设置操作 随笔 第7张

3、禁用端口 

success:执行成功

warning:警告xxx

firewall-cmd --remove-port=<port>[-<port>]/<protocol>
firewall-cmd [--zone=<zone>] --remove-port=<port>[-<port>]/<protocol>
firewall-cmd [--permanent] [--zone=<zone>] --remove-port=<port>[-<port>]/<protocol>

 Linux CentOS 7 防火墙与端口设置操作 随笔 第8张

Linux CentOS 7 防火墙与端口设置操作 随笔 第9张

Linux CentOS 7 防火墙与端口设置操作 随笔 第10张

4、防火墙相关

--reload:不改变状态的条件下重启防火墙

--complete-reload:状态信息将会丢失,当防火墙有问题时可以使用,如,状态信息和防火墙规则都正常却无法建立任何链接的情况等

firewall-cmd --reload
firewall-cmd --complete-reload
例子

Linux CentOS 7 防火墙与端口设置操作 随笔 第11张

Linux CentOS 7 防火墙与端口设置操作 随笔 第12张

 

查看防火墙状态

firewall-cmd --state

Linux CentOS 7 防火墙与端口设置操作 随笔 第13张

 

 

查看、打开、关闭应急模式(应急模式阻断所有网络连接,防止出现紧急状况)

firewall-cmd --query-panic

Linux CentOS 7 防火墙与端口设置操作 随笔 第14张

 

firewall-cmd --panic-on

Linux CentOS 7 防火墙与端口设置操作 随笔 第15张

 

firewall-cmd --panic-off

打开、关闭、重启防火墙 

systemctl stop firewalld
systemctl start firewalld
systemctl restart firewalld

Linux CentOS 7 防火墙与端口设置操作 随笔 第16张

 

 

 开启/关闭 开机自启动防火墙

systemctl enable firewalld
systemctl disable firewalld

 

查看版本: firewall-cmd --version 查看帮助: firewall-cmd --help 查看区域信息:  firewall-cmd --get-active-zones 查看指定接口所属区域: firewall-cmd --get-zone-of-interface=eth0

 

 

 

 

 

 

扫码关注我们
微信号:SRE实战
拒绝背锅 运筹帷幄