用活Firewalld防火墙之direct
原文地址: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/
非常相似,换句话说,想用好direct需要有ip6tables
iptables/
的基础,而ip6tables
iptables/
并不是我们这套教程的重点,所以这里学生就不给大家详细讲解了。ip6tables
direct中自定义chain跟iptables/
中使用-N新建chain类似,创建完之后就可以在规则中使用-j或者-g来使用了。ip6tables
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请求进行限制。
最新文章
- Java 素数 prime numbers-LeetCode 204
- Android与H5交互
- html-css控制背景图全屏拉伸不重复显示
- PHP7在linux下的安装步骤
- Java for LeetCode 055 Jump Game
- 资源 之 4.3 访问Resource(拾壹)
- Spring的注解方式
- CSAPP--存储器及程序的局部性
- 安卓开发中ScrollView不能用RelativeLayout的解决方案
- L1 正则 和 L2 正则的区别
- Iso language code table之(软件国际化)
- Lock与synchronized 的区别
- adb shell dumpsys
- BZOJ 2938: [Poi2000]病毒 [AC自动机 拓扑排序]
- cocos2d-x 3.11 游戏开发环境搭建流程
- 由于github仓库中提前建立readme文件,导致git push报错error: failed to push some refs to &#39;git@github.com:
- python检测服务器端口
- Android 屏幕操作
- python3+paramiko实现ssh客户端
- Jaxb如何优雅的处理CData
热门文章
- C++面向对象高级编程(七)point-like classes和function-like classes
- Mimiktaz抓取本机密码
- L165
- Android支持Split Apks后,如何获得指定包名下的所有类
- linux配置PHP环境!!(云服务器架设)
- continue的作用
- (转)Hive自定义UDAF详解
- Unity 播放 带 alpha 通道的视频(Video Player组件)
- EasyPlayer RTSP安卓Android播放器架构简析
- 使用 $scope.$apply 手动更新页面数据