TypechoJoeTheme

主机评测

主机评测

专注云服务器评测和优惠码发布

ipset搭建-_

2022-03-27
/
0 评论
/
1,305 阅读
/
正在检测是否收录...
03/27

很多情况下,你可能需要在Linux下屏蔽IP地址。比如,作为一个终端用户,你可能想要免受间谍软件或者IP追踪的困扰。或者当你在运行P2P软件时。你可能想要过滤反P2P活动的网络链接。如果你是一名系统管理员,你可能想要禁止垃圾IP地址访问你们的公司邮件服务器。或者你因一些原因想要禁止某些国家访问你的web服务。在许多情况下,然而,你的IP地址屏蔽列表可能会很快地增长到几万的IP。该如何处理这个?
1.yum安装ipset

  1. yum install ipset -y
  2. ipset list

2.创建集合 myip
你可以通过追加"maxelem N"选项来增加限制。

  1. ipset create myip hash:ip maxelem 1000000

3.添加规则到集合

  1. ipset add myip 192.168.1.2
  2. ipset add myip 192.168.3.4
  3. ipset add myip 192.168.4.3
  4. ipset add myip 192.168.6.8

4.添加iptables 规则 myip 无需重启iptables

  1. iptables -I INPUT -m set --set myip src -j DROP
  2. service iptables save

5.释放ip 192.168.3.4

  1. ipset del myip 192.168.3.4

6.删除集合myip

  1. ipset destroy myip

7.另外几条常用命令

  1. ipset del myip x.x.x.x # 从 myip 集合中删除内容
  2. ipset list myip # 查看 myip 集合内容
  3. ipset list # 查看所有集合的内容
  4. ipset flush myip # 清空 myip 集合
  5. ipset flush # 清空所有集合
  6. ipset destroy myip # 销毁 myip 集合
  7. ipset destroy # 销毁所有集合
  8. ipset save myip > myip.txt # 输出 myip 集合内容到标准输出
  9. ipset restore myip < myip.txt # 根据输入内容恢复集合内容
  10. ipset list myip | wc -l 查找屏蔽总数量
  11. ipset list | grep 10.0.0.2 查找某个IP是否备屏蔽
  12. iptables -I INPUT -m set --match-set myip src -j DROP
  13. iptables -L -n --line-number
  14. iptables -D INPUT 1

更多内容请参考http://ipset.netfilter.org
8.由于系统重启,ipset无法自动恢复集合,防火墙就无法载入带有ipset集合规则,导致效果失效。
需要做如下步骤
把以下2条命令加入到开机启动脚本 /etc/rc.local

  1. /usr/sbin/ipset restore < /root/ip.txt
  2. /etc/init.d/iptables restart
ipset
朗读

赞 · 0
赞赏
感谢您的支持,我会继续努力哒!
打开手机扫一扫,即可进行打赏哦!
版权属于:

主机评测

本文链接:

https://www.zjpc.cc/1094.html(转载时请注明本文出处及文章链接)

评论 (0)
  • OωO
  • |´・ω・)ノ
  • ヾ(≧∇≦*)ゝ
  • (☆ω☆)
  • (╯‵□′)╯︵┴─┴
  •  ̄﹃ ̄
  • (/ω\)
  • ∠( ᐛ 」∠)_
  • (๑•̀ㅁ•́ฅ)
  • →_→
  • ୧(๑•̀⌄•́๑)૭
  • ٩(ˊᗜˋ*)و
  • (ノ°ο°)ノ
  • (´இ皿இ`)
  • ⌇●﹏●⌇
  • (ฅ´ω`ฅ)
  • (╯°A°)╯︵○○○
  • φ( ̄∇ ̄o)
  • ヾ(´・ ・`。)ノ"
  • ( ง ᵒ̌皿ᵒ̌)ง⁼³₌₃
  • (ó﹏ò。)
  • Σ(っ °Д °;)っ
  • ( ,,´・ω・)ノ"(´っω・`。)
  • ╮(╯▽╰)╭
  • o(*////▽////*)q
  • >﹏<
  • ( ๑´•ω•) "(ㆆᴗㆆ)
  • (。•ˇ‸ˇ•。)
  • 泡泡
  • 阿鲁
  • 颜文字
火爆
火爆
火爆