setup-ipset.sh 681 B

12345678910111213141516171819202122232425262728293031323334353637
  1. # 需要 root 运行
  2. ipset create ngx-ban-dstip hash:net
  3. # 该策略对 jsproxy 用户的所有程序都生效
  4. iptables \
  5. -A OUTPUT \
  6. -p tcp --syn \
  7. -m owner --uid-owner jsproxy \
  8. -m set --match-set ngx-ban-dstip dst \
  9. -j REJECT
  10. # https://en.wikipedia.org/wiki/Reserved_IP_addresses
  11. REV_NET=(
  12. 0.0.0.0/8
  13. 10.0.0.0/8
  14. 100.64.0.0/10
  15. 127.0.0.0/8
  16. 169.254.0.0/16
  17. 172.16.0.0/12
  18. 192.0.0.0/24
  19. 192.0.2.0/24
  20. 192.88.99.0/24
  21. 192.168.0.0/16
  22. 198.18.0.0/15
  23. 198.51.100.0/24
  24. 203.0.113.0/24
  25. 224.0.0.0/4
  26. 240.0.0.0/4
  27. 255.255.255.255/32
  28. )
  29. for v in ${REV_NET[@]}; do
  30. ipset add ngx-ban-dstip $v
  31. done
  32. # 可屏蔽更多的网段:
  33. # ipset add ngx-ban-dstip xxx