原文地址:http://www.excelib.com/article/294/show

学生在前面已经给大家介绍过了Firewalld中direct的作用,使用他可以直接使用iptables、ip6tables中的规则进行配置,下面学生就给大家介绍direct的具体用法。

direct结构

我们还是先从配置文件入手,direct的配置文件为/etc/firewalld/direct.xml文件,结构如下

 <?xml version="1.0" encoding="utf-8"?>
<direct>
[ <chain ipv="ipv4|ipv6" table="table" chain="chain"/> ]
[ <rule ipv="ipv4|ipv6" table="table" chain="chain" priority="priority"> args </rule> ]
[ <passthrough ipv="ipv4|ipv6"> args </passthrough> ]
</direct>

大家可以看到这里的direct一共有三种节点:chain、rule和passthrough,他们都是可选的,而且都可以出现多次。

属性

  • ipv:这个属性非常简单,表示ip的版本

  • table:chain和rule节点中的table属性就是iptables/ip6tables中的table

  • chain:chain中的chain属性用于指定一个自定义链的名字,注意,不可与已有链重名;rule中的chain属性既可以是内建的(也就是iptables/ip6tables中的五条链),也可以是在direct中自定义的chain

  • priority:优先级,用于设置不同rule的优先级,就像iptables中规则的前后顺序,数字越小优先级越高

  • args:rule和passthrough中的args就是iptables/ip6tables中的一条具体的规则,不过他们可以使用我们自定义的chain。

使用

  因为direct的使用跟iptables/ip6tables非常相似,换句话说,想用好direct需要有iptables/ip6tables的基础,而iptables/ip6tables并不是我们这套教程的重点,所以这里学生就不给大家详细讲解了。

  direct中自定义chain跟iptables/ip6tables中使用-N新建chain类似,创建完之后就可以在规则中使用-j或者-g来使用了。

Firewalld中跟direct相关的命令如下

 firewall-cmd [--permanent] --direct --get-all-chains
firewall-cmd [--permanent] --direct --get-chains { ipv4 | ipv6 | eb } table
firewall-cmd [--permanent] --direct --add-chain { ipv4 | ipv6 | eb } table chain
firewall-cmd [--permanent] --direct --remove-chain { ipv4 | ipv6 | eb } table chain
firewall-cmd [--permanent] --direct --query-chain { ipv4 | ipv6 | eb } table chain firewall-cmd [--permanent] --direct --get-all-rules
firewall-cmd [--permanent] --direct --get-rules { ipv4 | ipv6 | eb } table chain
firewall-cmd [--permanent] --direct --add-rule { ipv4 | ipv6 | eb } table chain priority args
firewall-cmd [--permanent] --direct --remove-rule { ipv4 | ipv6 | eb } table chain priority args
firewall-cmd [--permanent] --direct --remove-rules { ipv4 | ipv6 | eb } table chain
firewall-cmd [--permanent] --direct --query-rule { ipv4 | ipv6 | eb } table chain priority args firewall-cmd --direct --passthrough { ipv4 | ipv6 | eb } args
firewall-cmd --permanent --direct --get-all-passthroughs
firewall-cmd --permanent --direct --get-passthroughs { ipv4 | ipv6 | eb }
firewall-cmd --permanent --direct --add-passthrough { ipv4 | ipv6 | eb } args
firewall-cmd --permanent --direct --remove-passthrough { ipv4 | ipv6 | eb } args
firewall-cmd --permanent --direct --query-passthrough { ipv4 | ipv6 | eb } args

下面我们来看个文档(firewalld.direct(5))中提供的例子

 <?xml version="1.0" encoding="utf-8"?>
<direct>
<chain ipv="ipv4" table="raw" chain="blacklist"/>
<rule ipv="ipv4" table="raw" chain="PREROUTING" priority="">-s 192.168.1.0/ -j blacklist</rule>
<rule ipv="ipv4" table="raw" chain="PREROUTING" priority="">-s 192.168.5.0/ -j blacklist</rule>
<rule ipv="ipv4" table="raw" chain="blacklist" priority="">-m limit --limit /min -j LOG --log-prefix "blacklisted: "</rule>
<rule ipv="ipv4" table="raw" chain="blacklist" priority="">-j DROP</rule>
</direct>

在这个例子中首先自定义了一个叫blacklist的链,然后将所有来自192.168.1.0/24和192.168.5.0/24的数据包都指向了这个链,最后定义了这个链的规则:首先进行记录,然后drop,记录的方法是使用“blacklisted: ”前缀并且限制1分钟记录一次。

当然,使用相似的方法大家也可以写出来上一节学生给大家留下的那个问题:对ping请求进行限制。

最新文章

  1. Java 素数 prime numbers-LeetCode 204
  2. Android与H5交互
  3. html-css控制背景图全屏拉伸不重复显示
  4. PHP7在linux下的安装步骤
  5. Java for LeetCode 055 Jump Game
  6. 资源 之 4.3 访问Resource(拾壹)
  7. Spring的注解方式
  8. CSAPP--存储器及程序的局部性
  9. 安卓开发中ScrollView不能用RelativeLayout的解决方案
  10. L1 正则 和 L2 正则的区别
  11. Iso language code table之(软件国际化)
  12. Lock与synchronized 的区别
  13. adb shell dumpsys
  14. BZOJ 2938: [Poi2000]病毒 [AC自动机 拓扑排序]
  15. cocos2d-x 3.11 游戏开发环境搭建流程
  16. 由于github仓库中提前建立readme文件,导致git push报错error: failed to push some refs to &#39;git@github.com:
  17. python检测服务器端口
  18. Android 屏幕操作
  19. python3+paramiko实现ssh客户端
  20. Jaxb如何优雅的处理CData

热门文章

  1. C++面向对象高级编程(七)point-like classes和function-like classes
  2. Mimiktaz抓取本机密码
  3. L165
  4. Android支持Split Apks后,如何获得指定包名下的所有类
  5. linux配置PHP环境!!(云服务器架设)
  6. continue的作用
  7. (转)Hive自定义UDAF详解
  8. Unity 播放 带 alpha 通道的视频(Video Player组件)
  9. EasyPlayer RTSP安卓Android播放器架构简析
  10. 使用 $scope.$apply 手动更新页面数据