ipset介绍

iptables是在linux内核里配置防火墙规则的用户空间工具,它实际上是netfilter框架的一部分.可能因为iptables是netfilter框架里最常见的部分,所以这个框架通常被称为iptables,iptables是linux从2.4版本引入的防火墙解决方案.

ipset是iptables的扩展,它允许你创建 匹配整个地址sets(地址集合) 的规则。而不像普通的iptables链是线性的存储和过滤,ip集合存储在带索引的数据结构中,这种结构即时集合比较大也可以进行高效的查找.

除了一些常用的情况,比如阻止一些危险主机访问本机,从而减少系统资源占用或网络拥塞,IPsets也具备一些新防火墙设计方法,并简化了配置.

官网:http://ipset.netfilter.org/

安装rpm -ivh libmnl-devel-1.0.2-3.el6.x86_64.rpm libmnl-1.0.2-3.el6.x86_64.rpm

tar xvf ipset-6.24.tar.bz2

cd ipset-6.24

./configure

make

make install

#注意:

如果在centos6.6或其他情况下安装时候,configure报错如下configure: error: Invalid kernel source directory /lib/modules/2.6.32-358.el6.x86_64/source

解决:需要安装内核源码包kernel-devel-2.6.32-358.el6.x86_64.rpm

创建ipset

ipset -n或者ipset create:n, create SETNAME TYPENAME [ CREATE-OPTIONS ]

SETNAME是创建的ipset的名称,TYPENAME是ipset的类型:TYPENAME := method:datatype[,datatype[,datatype]]

method指定ipset中的entry存放的方式,随后的datatype约定了每个entry的格式。

可以使用的method:bitmap, hash, list

可以使用的datatype:ip, net, mac, port, iface

添加记录

ipset add用于在ipset中添加记录:add SETNAME ADD-ENTRY [ ADD-OPTIONS ]

向ipset中添加entry的时候,加入的entry的格式必须与创建ipset是指定的格式匹配。$ipset creat foo hash:ip,port,ip

$ipset add foo ipaddr,portnum,ipaddr

$ipset list foo

Name: foo

Type: hash:ip,port,ip

Revision: 2

Header: family inet hashsize 1024 maxelem 65536

Size in memory: 16584

References: 0

Members:

192.168.1.2,tcp:80,192.168.1.3

删除记录

ipset del用于从ipset中删除记录:del SETNAME DEL-ENTRY [ DEL-OPTIONS ]

查询记录

ipset test可以检查目标entry是否在ipset中:test SETNAME TEST-ENTRY [ TEST-OPTIONS ]

ipset list可以查看ipset的所有内容:list [ SETNAME ] [ OPTIONS ]

导出导入

ipset save可以导出所有的ipset:save [ SETNAME ]

ipset restore则用于将导出的内容导入。

其它flush [ SETNAME ]

Flush all entries from the specified set or flush all sets if none is given.

e, rename SETNAME-FROM SETNAME-TO

Rename a set. Set identified by SETNAME-TO must not exist.

w, swap SETNAME-FROM SETNAME-TO

Swap the content of two sets, or in another words, exchange the name of two sets. The referred sets must exist and identical type of sets can be swapped only.

help [ TYPENAME ]

Print help and set type specific help if TYPENAME is specified.

version

Print program version.

-  If a dash is specified as command, then ipset enters a simple interactive mode and the commands are read from the standard input. The interactive mode can be finished by entering the

pseudo-command quit.

在iptables中使用ipset

在iptables中可以使用-m set启用ipset模块,例如。-A POSTROUTING -m set --match-set felix-masq-ipam-pools src -m set ! --match-set felix-all-ipam-pools dst -j MASQUERADE

iptables的set模块:set

This module matches IP sets which can be defined by ipset(8).

[!] --match-set setname flag[,flag]...

where flags are the comma separated list of src and/or dst specifications and there can be no more than six of them. Hence the command

iptables -A FORWARD -m set --match-set test src,dst

...

在TARGET中也可以操作ipset:SET

This module adds and/or deletes entries from IP sets which can be defined by ipset(8).

--add-set setname flag[,flag...]

add the address(es)/port(s) of the packet to the set

--del-set setname flag[,flag...]

delete the address(es)/port(s) of the packet from the set

where flag(s) are src and/or dst specifications and there can be no more than six of them.

...

在man iptables-extensions中可以找到set module和SET TARGET的所有选项。

linux ipset 命令,linux中ipset命令的使用方法详解相关推荐

  1. php中读取大文件实现方法详解

    php中读取大文件实现方法详解 来源:   时间:2013-09-05 19:27:01   阅读数:6186 分享到:0 [导读] 本文章来给各位同学介绍php中读取大文件实现方法详解吧,有需要了解 ...

  2. vue ajax highcharts,在vue项目中引入highcharts图表的方法(详解)

    npm进行highchars的导入,导入完成后就可以进行highchars的可视化组件开发了 npm install highcharts --save 1.components目录下新建一个char ...

  3. python支持向量机回归_Python中支持向量机SVM的使用方法详解

    除了在Matlab中使用PRTools工具箱中的svm算法,Python中一样可以使用支持向量机做分类.因为Python中的sklearn库也集成了SVM算法,本文的运行环境是Pycharm. 一.导 ...

  4. python更新数据库表的时间字段_python更新数据库中某个字段的数据(方法详解)

    连接数据库基本操作,我把每一步的操作是为什么给大家注释一下,老手自行快进. 请注意这是连接数据库操作,还不是更新. import pymysql #导包 #连接数据库 db = pymysql.con ...

  5. python中验证码连通域分割的方法详解

    python中验证码连通域分割的方法详解 这篇文章主要给大家介绍了关于python中验证码连通域分割的相关资料,文中通过示例代码介绍的非常详细,对大家学习或者使用python具有一定的参考学习价值,需 ...

  6. python中update是啥意思_python中update的基本使用方法详解

    前言 Python 字典 update()方法用于更新字典中的键/值对,可以修改存在的键对应的值,也可以添加新的键/值对到字典中. 语法格式 d.update(e) 参数说明 将e中键-值对添加到字典 ...

  7. python中search用法_Python中的python re.search方法详解

    re.search扫描整个字符串并返回第一个成功的匹配,若string中包含pattern子串,则返回Match对象,否则返回None,注意,如果string中存在多个pattern子串,只返回第一个 ...

  8. python怎么横着输出_对python3中, print横向输出的方法详解

    对python3中, print横向输出的方法详解 Python 2 : print打印的时候,如果结尾有逗号,打出来时候不会换行.但是在python3里面就不行了. Python3: 3.0的pri ...

  9. Python精讲:在Python中遍历字典的三大方法详解

    欢迎你来到站长在线的站长学堂学习Python知识,本文学习的是<在Python中遍历字典的三大方法详解>.本知识点主要内容有:使用字典对象的items()方法可以遍历字典的项和字典的&qu ...

  10. 命令行中 python -v 和 python -V 详解

    看了好多帖子说 "python -v 是包括库的版本号,而 python -V 才是版本号",特意去搜了下官方文档,证实如上说法并不对,以下是详解: 来源:https://docs ...

最新文章

  1. vs编译protobuf 3.0.0
  2. BCH领头,主流币全数突破压力线
  3. 9.文本处理(读写配置文件)
  4. log4j.properties中的这句话“log4j.logger.org.hibernate.SQL=DEBUG ”该怎么写在log4j.xml里面呢?...
  5. 工作分配问题pascal程序
  6. windows server 2016 docker 之创建使用虚拟交换机
  7. 类变量与实例变量辨析
  8. 分析脚本文件AndroidInitProcess分析心得(1)
  9. Chrome如何离线安装crx文件
  10. Weblogic(4)—— Linux环境Weblogic12c配置节点管理(nodemanage.properties)来开启应用服务器(server)及线程池配置...
  11. [转载] python[1]-print中的sep、end参数
  12. Linux - 查看软件安装与安装路径
  13. c++删除数组中重复元素_在VBA中如何使用动态数组,以及利用动态数组去除重复值的方法...
  14. 用户身份链接方法——DeepLink
  15. 在SPSS中将统计表格外观修改为三线表外观的步骤
  16. Jenkins--下载安装及简单配置
  17. 高一计算机课期中考试总结反思,期中考试总结与反思(精选25篇)
  18. 微信公众平台营销策略相关分析
  19. 分享几个实用的神器 APP
  20. 【大数据】一堆大数据名词

热门文章

  1. 《蜗居》中的那些人物们
  2. vue2项目启动控制台打印输出
  3. 一个仿时钟自定义View例子
  4. 如何学习一门编程语言?
  5. 病毒先生:还在砸钱做IP?真正的IP营销应该这么玩!
  6. 线性回归 正则项(惩罚项)原理、正则项的分类与Python代码的实现
  7. 约瑟夫环问题(c语言实现)
  8. 定制开发已经落幕,新的平台强势崛起
  9. Android Spring动画–基于物理的动画
  10. 浅谈对全连接层的理解