1.禁用其他防火墙
#禁用iptables
[root@web02 ~]# systemctl mask iptable
Created symlink from /etc/systemd/system/iptable.service to /dev/null.
#取消禁用iptables
[root@web02 ~]# systemctl unmask iptables
Removed symlink /etc/systemd/system/iptables.service.
2.启动firewalld
[root@web02 ~]# systemctl start firewalld
3.firewalld常用命令
#查看默认区域
[root@web02 ~]# firewall-cmd --get-default-zone
public
#查看区域规则(默认区域)
[root@web02 ~]# firewall-cmd --list-all
public
target: default
icmp-block-inversion: no
interfaces:
sources:
services: dhcpv6-client ssh
ports:
protocols:
masquerade: no
forward-ports:
source-ports:
icmp-blocks:
rich rules:
#查看区域规则(指定区域)
[root@web02 ~]# firewall-cmd --list-all --zone=trusted
trusted #区域名称
target: ACCEPT #状态:接收(默认状态)
icmp-block-inversion: no #icmp块
interfaces: #绑定的网卡
sources: #允许通过的IP地址、网段
services: #允许通过的服务
ports: #允许访问的端口
protocols: #允许通过的协议 (TCP/UDP/DCCP/SCTP)
masquerade: no #IP伪装
forward-ports: #转发的端口
source-ports: #源端口
icmp-blocks: #icmp块
rich rules: #富规则
#查询一个区域是否有某条规则
[root@web02 ~]# firewall-cmd --query-service=ssh
yes
[root@web02 ~]# firewall-cmd --query-service=http
no
#重启防火墙(清理默认的规则)
[root@web02 ~]# firewall-cmd --reload
success