ipset使用

hash:ip #存储IP

hash:ip,port #存储IP加端口

hash:net #存储IP段和IP

bitmap:port #存储端口

ipset create address hash:ip #创建集合名为address,存储ip

ipset create address-port hash:ip,port #创建集合名为address-port ,存储IP加端口

ipset list address #查看集合里面的信息

ipset add address-port 1.1.1.1,udp:53 #添加1.1.1.1,udp:53到集合里面

ipset add address-port 1.1.1.1,80-86 #添加1.1.1.1,80-86端口到集合

iptables -I INPUT -m set --match-set vader src -j DROP #封禁源IP是集合vader

iptables -I INPUT -m set ! --match-set yoda src -j DROP #封禁源IP除集合Vader外

ipset create r2d2 hash:net #创建集合名为r2d2,存储IP和IP段

ipset add r2d2 1.2.3.0/24 #添加1.2.3.0/24 到集合r2d2

ipset add r2d2 1.2.3.0/30 nomatch # 1.2.3.0/30不属于集合r2d2

ipset create obiwan hash:ip timeout 300 #创建集合,里面的IP默认300秒自动删除

ipset add obiwan 6.6.6.6 timeout 60 #添加6.6.6.6到集合,设置60秒自动删除

ipset -exist add obiwan 6.6.6.6 timeout 100 #重新设置时间

ipset create yoda hash:ip,port hashsize 4096 maxelem 1000000 #创建了名为 yoda 的集合,初始 hash 大小是 4096,如果满了,这个 hash 会自动扩容为之前的两倍。最大能存储的数量是 100000 个

ipset flush yoda #清空集合

ipset del yoda x.x.x.x #删除指定集合中的内容

ipset save yoda #输出集合内容,如果里面有IP段,会把IP段里的IP都列出来

原文地址:https://www.cnblogs.com/yunweiweb/p/13123551.html