ipset 教程
ipset介绍
ipset是iptables的扩展,它允许你创建 匹配整个地址集合的规则。而不像普通的iptables链只能单IP匹配, ip集合存储在带索引的数据结构中,这种结构即时集合比较大也可以进行高效的查找,除了一些常用的情况,比如阻止一些危险主机访问本机,从而减少系统资源占用或网络拥塞,IPsets也具备一些新防火墙设计方法,并简化了配置.官网:http://ipset.netfilter.org/
1.ipset安装
yum安装: yum install ipset
2.创建一个ipset
ipset create xxx hash:net (也可以是hash:ip ,这指的是单个ip,xxx是ipset名称)
或者 ipset create xxx hash:ip
hash:net 和hash:ip的区别是net可以时ip段,ip却只能是固定的ip
比如192.168.0.0/24 这个时ip段,可以用net存储。
192.168.1.1 这种用ip存储,hash ip 存储不了ip段。
一般最好时用net存储,大量的ip段,最好用net存储。
ipset默认可以存储65536个元素,使用maxelem指定数量
ipset create blacklist hash:net maxelem 1000000 #黑名单
ipset create whitelist hash:net maxelem 1000000 #白名单
查看已创建的ipset
ipset list
3.加入一个名单ip
ipset add blacklist 10.60.10.xx
4.去除名单ip
ipset del blacklist 10.60.10.xx
5.创建防火墙规则,与此同时,allset这个IP集里的ip都无法访问80端口(如:CC攻击可用)
iptables -I INPUT -m set –match-set blacklist src -p tcp -j DROP
iptables -I INPUT -m set –match-set whitelist src -p tcp -j DROP
service iptables save
iptables -I INPUT -m set –match-set setname src -p tcp –destination-port 80 -j DROP
6.将ipset规则保存到文件
ipset save blacklist -f blacklist.txt
ipset save whitelist -f whitelist.txt
7.删除ipset
ipset destroy blacklist
ipset destroy whitelist
8.导入ipset规则
ipset restore -f blacklist.txt
ipset restore -f whitelist.txt
ipset的一个优势是集合可以动态的修改,即使ipset的iptables规则目前已经启动,新加的入ipset的ip也生效
最新文章
- [LeetCode] Generate Parentheses 生成括号
- 使用spring配置quartz定时器
- 【群论】polya定理
- 【BZOJ】【2208】【JSOI2010】连通数
- POJ 1287	 Networking (最小生成树)
- Python学习笔记整理(四)Python中的字符串..
- android 代码动态创建视图
- 基于scrapy爬虫的天气数据采集(python)
- Linux 下的一个全新的性能测量和调式诊断工具 Systemtap,第 1 部分: kprobe
- vue 路由嵌套高亮问题
- 数据保存策略(Retention Policies)
- docker+ubuntu14.04+cuda7.0
- Python_在Ubuntu中搭建科学计算环境
- PowerShell一例
- 网络基础协议part 1
- 技术课堂】如何管理MongoDB数据库?
- python unittest框架中addCleanup函数详解
- 【uoj#209】[UER #6]票数统计 组合数+乱搞
- 第一个Net+Mysql的例子,比想象的简单很多
- springmvc(3)注解