ipset基本用法和保存配置
ipset基本用法
- 创建ipset集合
创建一个新的ipset集合:ipset create SETNAME TYPENAME
ipset create bb hash:ip
ipset create cc hash:net
- 向集合中添加条目
ipset add bb 2.2.2.2
ipset add bb 192.168.10.21-192.168.10.31
ipset add cc 192.168.2.0/24 #添加ip段
- 查询条目
ipset list
ipset list aa
- 检查目标ip是否在ipset集合中
ipset test aa 1.1.1.1
- 删除条目
ipset del aa 1.1.1.1
- 清空ipset中所有集合的ip条目(删条目,不删集合)
ipset flush aa
- 删除ipset中的某个集合或者所有集合:ipset destroy
[SETNAME]
ipset destroy aa
SET TYPES 集合类型 method存储方式: 存储方式有 bitmap, hash, list;
datatype数据类型: 支持的类型有:ip, net, mac, port, iface,即除了ip外,还可以是网络段,端口号(支持指定 TCP/UDP 协议),mac 地址,网络接口名称,或者多种。在创建的时候,指定是什么类型,在添加的时候,数据就要按照对应的格式来,不然就会报错
hash:ip,port
ipset create aa hash:ip,port
ipset add aa 1.1.1.1,22
需要保存配置,不然重启会失效
保存ipset规则
ipset save a -f /root/a.ipset
导入ipset规则
/sbin/ipset restore -f /root/a.ipset #写到/etc/rc.d/rc.local中给执行权限
本作品采用 知识共享署名-相同方式共享 4.0 国际许可协议 进行许可。