firewall火墙策略

firewall的基本zone分类

drop    丢弃所有进入的包,而不给出任何响应

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

这里写图片描述

文件添加基本的火墙策略

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

 [root@client ~]# firewall-cmd --list-all
public (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-zones
ROL block dmz drop external home internal public trusted work
#查看firewall的zone
[root@client ~]# firewall-cmd --set-default-zone=trusted
success
修改默认的firewall的zone
[root@client ~]# firewall-cmd --reload 
success
重新加载firewall的火墙策略
[root@client ~]# firewall-cmd --complete-reload 
success
它也是重新加载火墙策略,就是他是即时生效。
[root@client ~]# firewall-cmd --permanent --add-port=8080/tcp
success
将tcp协议的8080端口永久的加入到火墙策略中
--permanent是永久修改的意思
[root@client ~]# firewall-cmd --permanent --add-source=172.25.254.119 --zone=trusted
success 
接受来自172.25.254.119的所有请求
[root@client ~]# firewall-cmd --permanent --add-interface=eth0 --zone=public
success
将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 ACCEPT
success
接受所有来自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
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值