firewall火墙策略

来源:互联网 发布:番茄时钟 mac 编辑:程序博客网 时间:2024/06/02 07:21

firewall的基本zone分类

drop    丢弃所有进入的包,而不给出任何响应block   拒绝所有外部发起的连接,允许内部发起的连接public  允许指定的进入连接external    出去的ipv4网络连接通过此区域伪装和转发,仅接受ssh服务连接诶dmz 仅接受ssh服务连接work    一般用于工作区域,仅接受ssh ipp-client samba-client dhcpv6-clienthome    同上,类似 用于家庭网络internal    同上,类似,用于内部网络trusted 信任所有连接

这里写图片描述

文件添加基本的火墙策略

在文件中/etc/firewalld/zones/public.xml 中就是你火墙开启的服务

 [root@client ~]# firewall-cmd --list-allpublic (default, active)  interfaces: eth0  sources:   services: dhcpv6-client ssh  ports:   masquerade: no  forward-ports:   icmp-blocks:   rich rules: 

这时我们查看/etc/firewalld/zones/public.xml这个文件的内容

[root@client ~]# cat  /etc/firewalld/zones/public.xml<?xml version="1.0" encoding="utf-8"?><zone>  <short>Public</short>  <description>For use in public areas. You do not trust the other computers on networks to not harm your computer. Only selected incoming connections are accepted.</description>  <service name="dhcpv6-client"/>  <service name="ssh"/>

这里就只允许ssh服务,如果我们添加一个服务,http就直接将这个写入此文件中
如果我们打开http服务,这时火墙就会加载这个目录下的文件

[root@client ~]# ll /usr/lib/firewalld/services/ |grep http-rw-r-----. 1 root root 448 Feb 28  2014 https.xml-rw-r-----. 1 root root 353 Feb 28  2014 http.xml-rw-r-----. 1 root root 310 Feb 28  2014 wbem-https.xml[root@client ~]# cat  /usr/lib/firewalld/services/http.xml <?xml version="1.0" encoding="utf-8"?><service>  <short>WWW (HTTP)</short>  <description>HTTP is the protocol used to serve Web pages. If you plan to make your Web server publicly available, enable this option. This option is not required for viewing pages locally or developing Web pages.</description>  <port protocol="tcp" port="80"/></service>#这里面指明了http的端口和所使用的通信协议

这里写图片描述

用命令添加一些基本的火墙策略

[root@client ~]# firewall-cmd --get-zonesROL block dmz drop external home internal public trusted work#查看firewall的zone
[root@client ~]# firewall-cmd --set-default-zone=trustedsuccess修改默认的firewall的zone
[root@client ~]# firewall-cmd --reload success重新加载firewall的火墙策略
[root@client ~]# firewall-cmd --complete-reload success它也是重新加载火墙策略,就是他是即时生效。
[root@client ~]# firewall-cmd --permanent --add-port=8080/tcpsuccess将tcp协议的8080端口永久的加入到火墙策略中--permanent是永久修改的意思
[root@client ~]# firewall-cmd --permanent --add-source=172.25.254.119 --zone=trustedsuccess 接受来自172.25.254.119的所有请求
[root@client ~]# firewall-cmd --permanent --add-interface=eth0 --zone=publicsuccess将eth0网卡的zone类型永久修改成public类型的[root@client  ~]# firewall-cmd --permanent  --remove-rich-rule="rule family=ipv4 source address=172.25.254.19 forward-port port=22 protocol=tcp to-port=22 to-addr=172.25.254.119"永久删除一条rich rule策略

firewall Direct Rules工具添加火墙策略

[root@client ~]# firewall-cmd --permanent --direct --add-rule  ipv4 filter INPUT  0 ! -s 172.25.254.119  -p tcp --dport 22 -j ACCEPTsuccess接受所有来自22端口的tcp协议请求,除了来自172.25.254.119这个主机的,但是也没有拒绝这台主机,这条策略和他没有关系

firewall 的Rich Rules

这里写图片描述

[root@client ~]# firewall-cmd --permanent --add-rich-rule='rule family=ipv4 source address=172.25.254.119 masquerade'success让所有进入client的网从172.25.254.119出去[root@client ~]# firewall-cmd --permanent --add-rich-rule="rule family=ipv4 source address=172.25.254.19 forward-port port=22 protocol=tcp to-port=22 to-addr=172.25.254.119"success从172.25.254.19来的22端口的tcp协议请求,将这个请求转发到172.25.254.11922端口的tcp
原创粉丝点击