侧边栏壁纸
博主头像
落叶人生博主等级

走进秋风,寻找秋天的落叶

  • 累计撰写 130559 篇文章
  • 累计创建 28 个标签
  • 累计收到 9 条评论
标签搜索

目 录CONTENT

文章目录

Ipset

2023-12-23 星期六 / 0 评论 / 0 点赞 / 91 阅读 / 2084 字

前言 IP sets are a framework inside the Linux kernel, which can be administered by theipsetutility. De

前言

    IP sets are a framework inside the Linux kernel, which can be administered by the ipset utility. Depending on the type, an IP set may store IP addresses, networks, (TCP/UDP) port numbers, MAC addresses, interface names or combinations of them in a way, which ensures lightning speed when matching an entry against a set.

    IP集是Linux内核内的框架,它可以由IPSET实用程序。根据不同的类型,IP组可以存储IP地址,网络(TCP / UDP)端口号,MAC地址,接口名称,或在某种程度上,保证闪电般的速度匹配与一组条目中时,它们的组合。

 

使用

    ipset 一般用来辅助 iptables 使用;在iptables中,可以在创建规则的时候限制来源 IP,将这些 IP 地址写入多条 iptables 的规则(这些IP都是无规律性的),但是一旦要限制的 IP 过多的时候,当需要匹配几百甚至上千个IP地址的话,那么性能就会受到严重的影响,实测下来非常慢;

    ipset在这个方面做了很大的改善,其最主要是的在结构和规则的查找上面做了很大的改善,当出现上面的情况的时候,ipset对性能就始终稳定在一个相对值上。根据提供的测试结果表明,当规则在300-1500之间的时候其对性能的影响基本是水平线。所以当你的防火墙规则过多的时候不妨试试看。

ipset 添加黑名单

    ipset create openapi hash:net maxelem 1000000

    ipset add openapi 192.168.0.1

   使用 iptables 创建防火墙规则,openapi 这个 ipset 里的 ip 都无法访问 22 端口:

    iptables -I INPUT -m set --match-set openapi src -p tcp --destination-port 22 -j DROP

    

  

广告 广告

评论区