原文地址: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. DataTable RowFilter 过滤数据

    用Rowfilter加入过滤条件 eg: string sql = "select Name,Age,Sex from UserInfo"; DataTable dt = Data ...

  2. 解决方案:System.InvalidOperationException: 此实现不是 Windows 平台 FIPS 验证的加密算法的一部分。

    System.InvalidOperationException: This implementation is not part of the Windows Platform FIPS valid ...

  3. Spring整合hibernate:3、使用XML进行声明式的事务管理

    配置applicationContext.xml文件 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 2 ...

  4. MPAndroidChart Wiki(译文)~Part 4

    16. 动画 注意:本章的动画效果只会在API 11(Android3.0.x)及以上的Android版本上生效 在低于上述的Android版本中,动画将不会被执行,并不会导致程序崩溃. 所有类型的图 ...

  5. ng-if 判断条件中不能 使用变量名字拼接,switch可以

  6. 人生苦短之我用Python篇(队列、生产者和消费者模型)

    队列: queue.Queue(maxsize=0) #先入先出 queue.LifoQueue(maxsize=0) #last in fisrt out  queue.PriorityQueue( ...

  7. linux vim 命令使用

    基本上vim可以分为三种状态,分别是命令模式(command mode).插入模式(Insert mode)和底行模式(last line mode) 模式切换方法 在命令模式输入“i”,进入插入模式 ...

  8. 【剑指offer】数组中出现次数超过数组长度一半的数字,C++实现

    原创博文,转载请注明出处! # 题目 数组中有一个数字出现的次数超过数组长度的一半,请找出这个数字.例如输入一个长度为9的数组{1,2,3,2,2,2,5,4,2}.由于数字2在数组中出现了5次,超过 ...

  9. 【机器学习】集成学习之sklearn中的xgboost基本用法

    原创博文,转载请注明出处!本文代码的github地址    博客索引地址 1.数据集 数据集使用sklearn自带的手写数字识别数据集mnist,通过函数datasets导入.mnist共1797个样 ...

  10. windows命令行工具

    winver 检查Windows版本 wmimgmt.msc 打开Windows管理体系结构(wmi) wupdmgr Windows更新程序 wscript Windows脚本宿主设置 write ...