在6.x中用的是iptables,但在CentOS 7.x中,使有了一种新的防火墙策略:FireWall。
软件环境
- Linux:CentOS Linux release 7.6.1810 (Core)
命令
- 查询防火墙状态
// 方法一:输出running表示已经开启,反之没有
[root@localhost ~]# firewall-cmd --state
// 方法二:Active如果为active则表示开启,反之没有
[root@localhost ~]# systemctl status firewalld
- 启动防火墙
[root@localhost ~]# systemctl start firewalld
- 查看端口
// 1、查看所有开放的端口
[root@localhost ~]# firewall-cmd --list-ports
// 2、查看指定端口的状态
[root@localhost ~]# firewall-cmd --zone-public --query-port=81/tcp
- 添加新端口(需重启防火墙才生效)
[root@localhost ~]# firewall-cmd --zone=public --add-port=81/tcp --permanent
- 关闭端口(需重启防火墙才生效)
[root@localhost ~]# firewall-cmd --zone=public --remove-port=81/tcp --permanent
- 重启防火墙
[root@localhost ~]# firewall-cmd --reload
- 关闭防火墙
[root@localhost ~]# systemctl stop firewalld