原文地址: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请求进行限制。

用活Firewalld防火墙之direct的更多相关文章

  1. 用活firewalld防火墙之service

    原文地址:http://www.excelib.com/article/291/show 前面学生已经给大家介绍了在firewalld中service的概念以及在zone中怎么使用service,但是 ...

  2. centos7 firewall-cmd 用活firewalld防火墙中的zone

    原文:http://www.excelib.com/article/290/show/ firewalld中zone的含义学生前面已经给大家介绍过了,说白了一个zone就是一套规则集.可是什么时候该用 ...

  3. 用活firewalld防火墙中的zone

    原文地址:http://www.excelib.com/article/290/show firewalld中zone的含义学生前面已经给大家介绍过了,说白了一个zone就是一套规则集.可是什么时候该 ...

  4. CentOS7、REHL7的firewalld防火墙使用简单说明

    title: CentOS7.REHL7的firewalld防火墙使用简单说明 categories: Linux tags: - Linux timezone: Asia/Shanghai date ...

  5. Firewalld防火墙与ICMP攻击

    原文地址:http://www.excelib.com/article/293/show 提到ICMP大家应该都很熟悉,可能有人会说:不就是ping吗?但是说到ICMP攻击以及相关防御措施可能就有的人 ...

  6. 11.Firewalld防火墙

    Firewalld防火墙 目录 Firewalld防火墙 Firewalld概述 Firewalld Firewalld和iptables的关系 netfilter Firewalld/iptable ...

  7. 第8章 Iptables与Firewalld防火墙

    章节简述: 红帽RHEL7系统已经用firewalld服务替代了iptables服务,新的防火墙管理命令firewall-cmd与图形化工具firewall-config. 本章节基于数十个防火墙需求 ...

  8. CentOS7使用firewalld防火墙配置端口

    安装启用firewalld防火墙 CentOS7默认的防火墙是firewalld 如果没有firewalld防火墙,可以执行yum install firewalld 命令进行安装 firewalld ...

  9. Linux firewalld 防火墙

    Linux firewalld 防火墙  简介 RHEL 7 系统中集成了多款防火墙管理工具,其中 firewalld(Dynamic Firewall Manager of Linux system ...

随机推荐

  1. Access control allow origin 简单请求和复杂请求

    原文地址:http://blog.csdn.net/wangjun5159/article/details/49096445 错误信息: XMLHttpRequest cannot load http ...

  2. CF910B

    题解: dp f[i][j]表示i根a,j根b要多少 然后随便转移一下 代码: #include<bits/stdc++.h> using namespace std; ][],n,a,b ...

  3. HDU 5875 Function (线段树+gcd / 单调栈)

    题意:给你一串数a再给你一些区间(lef,rig),求出a[lef]%a[lef+1]...%a[rig] 题解:我们可以发现数字a对数字b取模时:如果a<b,则等于原数,否则a会变小至少一半. ...

  4. bfs+状态压缩dp

    题目连接 题解 : 对两两管道进行bfs,然后用dp[i][j] 来表示在i状态下通过了前j个管道 参考博客 #include<bits/stdc++.h> using namespace ...

  5. New Concept English three(12)

    25W/m 76% Most of us have formed an unrealistic picture of life on a desert island. We sometimes ima ...

  6. 手机微信网站开发放弃windows phone的理由

    1.手机操作系统市场份额: 全球(2.44% 下滑): http://news.mydrivers.com/1/449/449736.htm 中国(1% 下滑): http://app.techweb ...

  7. Android程序员学WEB前端(6)-CSS(1)-选择器-Sublime

    转载请注明出处:http://blog.csdn.net/iwanghang/article/details/76576469 觉得博文有用,请点赞,请评论,请关注,谢谢!~ CSS外部文档链接: & ...

  8. linux系统编程-进程

    进程 现实生活中 在很多的场景中的事情都是同时进行的,比如开车的时候 手和脚共同来驾驶汽车,再比如唱歌跳舞也是同时进行的: 如下是一段视频,迈克杰克逊的一段视频: http://v.youku.com ...

  9. python数据取整

    第三方包:numpy 安装 $ sudo dnf install numpy 4舍6入5取偶 def getInteger(): a = np.float(5.5) # 4舍6入 5取偶 int_a ...

  10. 【IDEA】创建maven项目时,报错[FATAL_ERROR] Cannot start Maven: Cannot find JRE '1.7'

    在使用IDEA使用maven创建springMVC项目时,出现下面的错误,导致无法创建生成正常的springMVC项目结构,而只有一个pom文件: [FATAL_ERROR] Cannot start ...