1区域
trusted :允许所有流量通过
home/internal:仅允许ssh数据通过
work:仅允许ssh,ipp-client,dhcpv6-client数据通过
public:默认区域,仅允许ssh,dhcpv6-client数据通过
external:仅允许ssh数据通过,通过该区域的数据将会伪装(SNAT/DNAT)
dmz:仅允许ssh数据通过
block:任何传入的网络数据包都将被阻止。拒绝所有流量
drop:拒绝所有流量,没有返回回应消息
2、命令详解
firewall -cmd --permanent
--permanent #永久生效的配置参数、资源、端口以及服务等信息
1、域zone相关的命令
--get-default-zone #查询默认的区域名称
--set-default-zone=<区域名称> #设置默认的区域
--get-active-zones #显示当前正在使用的区域与网卡名称
--get-zones #显示总共可用的区域
2、services管理的命令
--add-service=<服务名> --zone=<区域> #设置指定区域允许该服务的流量
--remove-service=<服务名> --zone=<区域> #设置指定区域不再允许该服务的流量
3、Port相关命令
--add-port=<端口号/协议> --zone=<区域> #设置指定区域允许该端口的流量
--remove-port=<端口号/协议> --zone=<区域> #设置指定区域不再允许该端口的流量
4、查看所有规则的命令
--list-all --zone=<区域> 显示指定区域的网卡配置参数、资源、端口以及服务等信息
--reload #让“永久生效”的配置规则立即生效,并覆盖当前的配置规则
3、firewalld配置使用**
查看默认区域:
[root@iptables-server ~]# firewall-cmd --get-default-zone
public
验证:
在192.168.246.201机器上访问192.168.246.200
[root@iptables-test ~]# curl -I http://192.168.246.200 #不通
curl: (7) Failed connect to 192.168.246.200:80; No route to host
[root@iptables-test ~]# ssh root@192.168.246.200 #ssh 可以
root@192.168.246.200's password:
2、更改默认区域
[root@iptables-server ~]# firewall-cmd --set-default-zone=trusted
success
[root@iptables-server ~]# firewall-cmd --reload
success
[root@iptables-server ~]# firewall-cmd --get-default-zone
trusted
验证:
在192.168.246.201机器上访问192.168.246.200
[root@iptables-test ~]# curl -I http://192.168.246.200 #访问成功
HTTP/1.1 200 OK
================================================
修改回默认区域:
[root@iptables-server ~]# firewall-cmd --set-default-zone=public
success
[root@iptables-server ~]# firewall-cmd --reload
success
3.向public区域添加服务
[root@iptables-server ~]# firewall-cmd --permanent --add-service=http --zone=public
success
[root@iptables-server ~]# firewall-cmd --reload #重新加载配置文件
success
验证:
在192.168.246.201机器上访问192.168.246.200
[root@iptables-test ~]# curl -I http://192.168.246.200
HTTP/1.1 200 OK
4.指定IP地址为192.168.246.201/24的客户端进入drop区域
[root@iptables-server ~]# firewall-cmd --permanent --add-source=192.168.246.201/24 --zone=drop
success
[root@iptables-server ~]# firewall-cmd --reload
success
验证:
在192.168.246.201的机器上访问246.200
[root@iptables-test ~]# curl -I http://192.168.246.200 #访问不通
5.将192.168.246.201/24移除drop区域
[root@iptables-server ~]# firewall-cmd --permanent --remove-source=192.168.246.201/24 --zone=drop
success
[root@iptables-server ~]# firewall-cmd --reload
success
验证:
在192.168.246.201的机器上面访问246.200
[root@iptables-test ~]# curl -I http://192.168.246.200 #访问成功
HTTP/1.1 200 OK
6.向pubic区域添加服务,以添加端口的方式
[root@iptables-server ~]# firewall-cmd --permanent --add-port=80/tcp --zone=public
success
[root@iptables-server ~]# firewall-cmd --reload
success
验证:
用192.168.246.201访问192.168.246.200机器
[root@iptables-test ~]# curl -I http://192.168.246.200
HTTP/1.1 200 OK
7.删除服务、端口
[root@iptables-server ~]# firewall-cmd --permanent --remove-service=http --zone=public
success
[root@iptables-server ~]# firewall-cmd --reload
success
验证:
用192.168.246.201访问192.168.246.200机器
[root@iptables-test ~]# curl -I http://192.168.246.200 #访问通
HTTP/1.1 200 OK
====================================================================================
[root@iptables-server ~]# firewall-cmd --permanent --remove-port=80/tcp --zone=public
success
[root@iptables-server ~]# firewall-cmd --reload
success
验证:
在192.168.246.201访问192.168.246.200机器
[root@iptables-test ~]# curl -I http://192.168.246.200 #访问失败
curl: (7) Failed connect to 192.168.246.200:80; No route to host
8.允许指定ip访问某个端口
仍以Redis为例
Redis服务端操作:(#允许192.168.142.166访问本机的6379端口)
# firewall-cmd --permanent --add-rich-rule="rule family="ipv4" source address="192.168.142.166" port protocol="tcp" port="6379" accept"
被允许ip地址验证:
# telnet 192.168.62.135 6379