一、firewalld与iptables的区别
1、firewalld可以动态修改单条规则,而不需要像iptables那样,在修改了规则后必须得全部刷新才可以生效;
2、firewalld在使用上要比iptables人性化很多,即使不明白“五张表五条链”而且对TCP/IP协议也不理解也可以实现大部分功能。
二、firewalld的常用操作
状态:# systemctl status firewalld 或者 firewall-cmd --state
启动:# systemctl start firewalld
停止:# systemctl stop firewalld
使能:# systemctl enable firewalld
禁用:# systemctl disable firewalld
## 查看当前的 zones
[root@centos7 ~]# firewall-cmd --get-active-zones
public
interfaces: ens33
## 设置默认的zone
[root@centos7 ~]# firewall-cmd --set-default-zone=public
## 显示当前开放端口
[root@centos7 ~]# firewall-cmd --zone=public --list-ports
80/tcp
## 显示当前开放的服务
[root@centos7 ~]# firewall-cmd --zone=public --list-services
ssh dhcpv6-client
## 添加端口到永久区
[root@centos7 ~]# firewall-cmd --permanent --zone=public --add-port=8080/tcp
## 添加服务到永久区
[root@centos7 ~]# firewall-cmd --permanent --zone=public --add-services=httpd
## 设置某段地址可以访问端口
[root@centos7 ~]# firewall-cmd --permanent --zone=public --add-rich-rule="rule family="ipv4" source address="10.0.0.0/24" port protocol="tcp" port="37799" accept"
## 屏蔽某个地址
[root@centos7 ~]# firewall-cmd --permanent --zone=public --add-rich-rule='rule family=ipv4 source address="192.168.3.4" drop'
## 刷新配置,添加到永久区后须刷新配置才能生效
[root@centos7 ~]# firewall-cmd --reload
success