如果centos7有安装iptables防火墙及其他防火墙先关掉或者卸载掉,没有就忽略。
关闭iptablessystemctl stop iptables
安装firewalld
yum install -y firewalld
开启防火墙
systemctl start firewalld
查看防火墙状态
systemctl status firewalld
重启防火墙
systemctl restart firewalld
设置防火墙开机自启
systemctl enable firewalld
关闭防火墙开机自启
systemctl disable firewalld
查看预定义区域
firewall-cmd --get-zones
查看每个区域的详细信息
firewall-cmd --list-all-zones
区域简介:
区域 默认规则 block 拒绝流入的流量,除非与流出的流量相关 dmz 拒绝流入的流量,除非与流出的流量相关;如果流量与ssh服务相关,则允许流量 drop 拒绝流入的流量,除非与流出的流量相关 external 拒绝流入的流量;除非与流出的流量相关;如果流量与ssh服务相关,则允许流量 home 拒绝流入的流量;除非与流出的流量相关;如果流量与ssh,mdns,ipp-client,amba-client,dhcpv6-client服务相关,则允许流量 internal 等同于home区域 public 拒绝流入的流量;除非与流出的流量相关;如果流量与ssh,dhcpv6-client服务相关,则允许流量 trusted 允许所有的数据包流入与流出 work 拒绝流入的流量;除非与流出的流量相关;如果流量与ssh,ipp-client,dhcpv6-client服务相关,则允许流量 创建自定义区域
firewall-cmd --permanent --new-zone=testing
注意: --permanent选项不能少
查看默认区域
firewall-cmd --get-default-zone
查看网卡关联的区域
firewall-cmd --get-zone-of-interface=eth0
注意: 一张网卡只能关联一个区域
修改默认区域
# #修改默认区域为`trusted` # firewall-cmd --set-default-zone=trusted success # firewall-cmd --get-default-zone trusted # firewall-cmd --get-zone-of-interface=eth0 trusted # #还原 # firewall-cmd --set-default-zone=public success # firewall-cmd --get-default-zone public # firewall-cmd --get-zone-of-interface=eth0 public
修改网卡关联的区域
方法1:先删除现有关联区域,再添加目标关联区域(因为同一时间,一张网卡只能关联一个区域,所以要先添加再删除)# firewall-cmd --remove-interface=eth0 --zone=public success # firewall-cmd --get-zone-of-interface=eth0 no zone ## 设置eth0关联区域为trusted # firewall-cmd --add-interface=eth0 --zone=trusted success # firewall-cmd --get-zone-of-interface=eth0 trusted
方法2:
## 设置eth0关联区域为public # firewall-cmd --change-interface=eth0 --zone=public success # firewall-cmd --get-zone-of-interface=eth0 public
查看当前活动区域及绑定的接口和源
# firewall-cmd --get-active-zones public interfaces: eth0
版权属于:
haha
评论 (0)