setup-ipset.sh 780 B

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