CentOS7 firewall 开放端口和关闭防火墙

CentOS7开放端口,重载防火墙配置

1
2
sudo firewall-cmd --zone=public --add-port=6379/tcp --permanent
sudo firewall-cmd --reload

检查防火墙规则命令

1
firewall-cmd --list-all

会显示:

1
2
3
4
5
6
7
8
9
10
11
12
13
public (active)   # 状态
target: default
icmp-block-inversion: no
interfaces: ens33 #接口信息
sources:
services: ssh dhcpv6-client #开放服务
ports: 6379/tcp # 开放端口
protocols:
masquerade: no
forward-ports:
source-ports:
icmp-blocks:
rich rules:

其他命令:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
# 重启防火墙
systemctl restart firewalld
# 检查状态
firewall-cmd --state
firewall-cmd --list-all
#禁用 firewall
systemctl disable firewalld
systemctl stop firewalld
# 查询防火墙状态
systemctl status firewalld
#启用防火墙
systemctl enable firewalld
systemctl start firewalld
# 查询防火墙状态
systemctl status firewalld