Linux下的firewalld部署

1、防火墙

使用firewalld
[root@client ~]# systemctl stop iptables
[root@client ~]# systemctl disable iptables
[root@client ~]# systemctl start firewalld
[root@client ~]# systemctl enable firewalld
firewalld域

这里写图片描述

使用命令行接口配置防火墙
[root@client ~]# firewall-cmd --state #查看火墙状态
[root@client ~]# firewall-cmd --list-all #查看防火墙规则
[root@client ~]# firewall-cmd --get-active-zones #查看当前生效的域

这里写图片描述

[root@client ~]# firewall-cmd --get-default-zone #查看默认域
[root@client ~]# firewall-cmd --get-zones #查看所有的域
[root@client ~]# firewall-cmd --zone=public --list-all #查看public域的规则
[root@client ~]# firewall-cmd --get-services #查看系统中用名称代表的服务
[root@client ~]# firewall-cmd --list-all-zones #查看所有域的规则
[root@client ~]# firewall-cmd --set-default-zone=trusted #修改默认域为trusted

这里写图片描述

firewalld域的设置
[root@client Desktop]# firewall-cmd --list-all
[root@client Desktop]# firewall-cmd --add-source=172.25.254.168 --zone=trusted #添加168主机到trusted域
[Desktop]# systemctl start httpd
[root@client Desktop]# echo westos > /var/www/html/index.html
[Desktop]# systemctl restart httpd

168主机测试:
这里写图片描述
其他主机测试:
这里写图片描述

[root@client Desktop]# firewall-cmd --remove-source=172.25.254.168 --zone=trusted 
多网卡下的firewalld配置

为虚拟机添加网卡
这里写图片描述

[root@client Desktop]# firewall-cmd --list-interfaces #查看网卡
[root@client Desktop]# firewall-cmd --get-zone-of-interface=eth0 #查看eth0的默认域
[root@client Desktop]# firewall-cmd --get-zone-of-interface=eth1 #查看eth1的默认域
[root@client Desktop]# firewall-cmd --change-interface=eth0 --zone=trusted #修改eth0默认域为trusted域
[root@client Desktop]# firewall-cmd --get-zone-of-interface=eth0 #查看eth0的默认域
[root@client Desktop]# firewall-cmd --remove-interface=eth0 --zone=trusted #将eth0从trusted域上移除
[root@client Desktop]# firewall-cmd --get-zone-of-interface=eth0 
no zone
[root@client Desktop]# firewall-cmd --add-interface=eth0 --zone=public #添加eth0到public域
[root@client Desktop]# firewall-cmd --get-zone-of-interface=eth0
public

这里写图片描述

2、firewalld临时与永久设置

#临时设置source
[root@client Desktop]# firewall-cmd --add-source=172.25.254.168
[root@client Desktop]# firewall-cmd --list-all
[root@client Desktop]# systemctl restart firewalld
[root@client Desktop]# firewall-cmd --list-all #重启后消失,是临时的

这里写图片描述

#永久设置source
[root@client Desktop]# firewall-cmd --permanent --add-source=172.25.254.168 #-permanent表示永久
[root@client Desktop]# firewall-cmd --reload #重新加载
[root@client Desktop]# firewall-cmd --list-all

这里写图片描述
可以在配置文件中查看永久设置

[root@client Desktop]# cd /etc/firewalld/
[root@client firewalld]# ls
[root@client firewalld]# cd zones/
[root@client zones]# ls
[root@client zones]# vim public.xml #配置文件中有添加配置行

这里写图片描述

一般,与服务相关的配置文件在/usr/lib/firewalld下:
[root@client zones]# cd /usr/lib/firewalld
[root@client firewalld]# ls
[root@client firewalld]# cd services/
[root@client services]# ls #可以看到多个服务的相关文件
[root@client services]# vim http.xml #查看http的配置文件

这里写图片描述

这也解释了为什么http的服务端口是80
#firewalld支持服务的移除与添加
[root@client services]# firewall-cmd --remove-service=ssh #移除ssh
[root@client services]# firewall-cmd --reload #重新加载
[root@client services]# firewall-cmd --list-all #ssh再次出现
[root@client services]# firewall-cmd --permanent --remove-service=ssh #永久移除
[root@client services]# firewall-cmd --reload #重新加载,已经连接的ssh不会受到影响,新的连接失败
[root@client services]# firewall-cmd --list-all #移除成功
[root@client services]# firewall-cmd --complete-reload #完全重新加载,已经连接的ssh被停止,不能操作
reload重新加载会影响新的连接,新连接失败:

这里写图片描述

reload重新加载不影响已经建立的连接,可以正常使用
但使用complete-reload重新加载后,已经建立的连接被停止,不能正常使用了

这里写图片描述

猜你喜欢

转载自blog.csdn.net/yyyxxxs/article/details/80607689
今日推荐