动态防火墙后台程序 firewalld 提供了一个 动态管理的防火墙, 用以支持网络 “ zones” , 以分配对一个网络及其相关链接和界面一定程度的信任。它具备对 IP v4 和 IP v6 防火墙设置的支持。它支持以太网桥 , 并有分离运行时间和永久性配置选择。它还具备一个通向服务或者应用程序以直接增加防火墙规则
的接口系统提供了图像化的配置工具 firewall-config 、 system-config-firewall, 提供命令行客户端 firewall-cmd, 用于配置 firewalld 永久性或非永久性运行时间的改变 : 它依次用iptables 工具与执行数据包筛选的内核中的 Netfilter 通信。
firewalld-cmd --state ##查看火墙当前状态 firewalld-cmd --get-active-zone ##查看火墙默认生效(已激活)的域 firewalld-cmd --get-default-zone ##显示默认区域 firewalld-cmd --get-zones ##列出所有域 firewalld-cmd --zone=public --list-all ##列出pubulic域所有的策略 firewalld-cmd --get-services ##查看火墙管控的所有服务 firewalld-cmd --list-all-zones ##列出所有的域 firewalld-cmd --set-default-zone=dmz ##设置默认域为dmz firewall-cmd --add-source=172.25.254.68 --zone=trusted ##将172.25.254.68加入trusted域 firewall-cmd --list-all --zone=trusted ##列出所有域为trusted的信息 firewall-cmd --list-interfaces ##列出所有接口 firewall-cmd --get-zone-of-interface=eth0 ##显示eth0的域 firewall-cmd --change-interface=eth0 --zone=trusted ##修改eth0的域为trusted firewall-cmd --remove-interface=eth0 --zone=trusted ##移除eth0的域 firewall-cmd --permanent --add-source=172.25.254.68 ##将该ip永久加入 firewall-cmd --add-port=8080/tcp --zone=public ##将8080端口加入public域 firewall-cmd --permanebt --remove-service=ssh firewall-cmd --reload ##对移除之后的访问有影响 firewall-cmd --complete-reload ##对移除之后和之前的访问都有影响
[root@client ~]# yum install firewalld firewalld-config ##安装火墙 [root@client ~]# systemctl stop iptables ##关闭iptables [root@client ~]# systemctl disable iptables ##开机自动启动服务 [root@client ~]# systemctl start firewalld ##开启火墙 [root@client ~]# systemctl enable firewalld ##开机自动开启 [root@client ~]# yum search iptables ##寻找iptables安装包 [root@client ~]# yum install iptables-services.x86_64
[root@client ~]# firewall-cmd --state ##查看火墙状态 [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 Desktop]# yum install httpd -y [root@client Desktop]# systemctl start httpd [root@client Desktop]# echo westos > /var/www/html/index.html
在网页浏览172.25.254.128 显示连接不上
[root@client Desktop]# firewall-cmd --set-default-zone=trusted success [root@client Desktop]# systemctl restart firewalld [root@client Desktop]# firewall-cmd --add-source=172.25.254.28 --zone=trusted success
再次网页浏览172.25.254.128,更改过域后就可以看到在里面写进的内容了
在真机上:
[root@foundation68 ~]# virt-manager
在客户端添加两块网卡:
在客户端:
添加两个网卡的IP
[root@client Desktop]# nm-connection-editor ##添加两个IP [root@client ~]# systemctl restart network ##重启网络 [root@client ~]# ifconfig ##查看IP
[root@client ~]# firewall-cmd --set-default-zone=public ##设置默认域为public [root@client ~]# firewall-cmd --get-zone-of-interface=eth1 ##显示eth1的域 [root@client ~]# firewall-cmd --get-zone-of-interface=eth0 ##显示eth0的域
[root@client ~]# firewall-cmd --change-interface=eth0 --zone=trusted ##修改eth0的域为trusted [root@client ~]# firewall-cmd --get-zone-of-interface=eth0 [root@client ~]# firewall-cmd --get-zone-of-interface=eth1 [root@client ~]# firewall-cmd --remove-interface=eth0 --zone=trusted ##移除eth0的域
[root@client ~]# firewall-cmd --list-all [root@client ~]# systemctl restart firewalld
[root@client ~]# firewall-cmd --add-source=172.25.254.68 [root@client ~]# firewall-cmd --list-all
[root@client ~]# firewall-cmd --remove-source=172.25.254.68 ##移除IP [root@client ~]# firewall-cmd --permanent --add-source=172.25.254.123 ##将该ip永久加入 [root@client ~]# firewall-cmd --reload ##生效 [root@client ~]# firewall-cmd --list-all
[root@client ~]# cd /etc/firewalld [root@client firewalld]# ls [root@client firewalld]# cd zones [root@client zones]# ls [root@client zones]# vim public.xml 添加: <service name="http"/> [root@client zones]# systemctl restart firewalld [root@client zones]# firewall-cmd --list-all
在文件里添加http服务
可以看到services里面有http服务
[root@client ~]# vim /usr/lib/firewalld/services/http.xml <port protocol="tcp" port="8080"/> [root@client ~]# firewall-cmd --add-port=8080/tcp --zone=public ##将8080端口加入public域 [root@client ~]# firewall-cmd --list-all
更改端口:
[root@client ~]# firewall-cmd --remove-service=ssh success [root@client ~]# firewall-cmd --list-all
在真机上连接虚拟机:
但是不会中断已经连接上的虚拟机的界面
[root@client ~]# firewall-cmd --reload success [root@client ~]# firewall-cmd --list-all
[root@client ~]# firewall-cmd --complete-reload ##对移除之后和之前的访问都有影响
再次看真机上已经连接的虚拟机就不能做任何动作了,并且真机也连接不到虚拟机。已经完全中断ssh服务。
reload刷新之后不会中断连接,complete-reload刷新之后会中断连接