Ipset

前言

    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.html

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

 

使用

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

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

ipset 添加黑名单

    ipset create openapi hash:net maxelem 1000000tcp

    ipset add openapi 192.168.0.1ide

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

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

相关文章
相关标签/搜索