原文地址: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. Algorithm1: 全排列

    全排列 思想:      这是一个全排列问题,需要使用递归实现,将数组中的所有元素和第一个元素交换,求后面n-1个元素的全排列.      按照这个条件递归下去,知道元素的个数只有一个的时候,输出所有 ...

  2. CF910C

    题解: 首先考虑暴力不行 然后采用贪心 按位展开 然后注意不能有前缀0 代码: #include<bits/stdc++.h> using namespace std; ],ans; ], ...

  3. sed和awk简介

    什么是sed和awk         sed和awk是Linux环境下数据的处理工具,可以完成对数据的增删改查的功能.         sed处理时是以行尾单位的,awk处理数据时以字段为单位. se ...

  4. ORA-06512: at "SYS.XMLTYPE" 问题记录

    执行SQL报错: SQL> SELECT COUNT(cl.enable_flg) FROM cont_ledger cl INNER JOIN project_project pp ON cl ...

  5. EasyPlayerPro安卓流媒体播放器实现Android H.265硬解码流程

    本文转自EasyDarwin团队成员John的博客:http://blog.csdn.net/jyt0551/article/details/74502627 H.265编码算法作为新一代视频编码标准 ...

  6. 【转】Ubuntu16.04安装WPS

    下载安装下载WPS For Linux:http://community.wps.cn/download/ 直接下载:http://kdl.cc.ksosoft.com/wps-community/d ...

  7. python常用模块之sys模块

    python常用模块之sys模块 1.sys.argv[]:命令行参数List,第一个元素是程序本身 # 写一个简单的python程序,代码如下: #!/usr/bin/python #coding= ...

  8. python的基础

    一. print(1 or 1 > 4) # 1  (从左到右1为True就结束了) print(1 > 1 or 3) # 3print(3 > 1 or 3 or 3 > ...

  9. 【C++】STL之队列queue

    1.头文件 # include<queue> 2.成员函数 empty() 当队列为空时,返回true size() 返回队列内元素个数 front() 返回队首元素 back() 返回队 ...

  10. [转载][QT][SQL]sq]学习记录1_模糊搜索

    转载自:sql学习网站: http://www.w3school.com.cn/sql/index.asp 用于模糊搜索数据库的数据 语句:http://www.w3school.com.cn/sql ...