当前位置:   article > 正文

使用route的reject拒绝境外ip通信

使用route的reject拒绝境外ip通信

#以下是centos系统格式版,(win不支持,搜本博,错误路由方式处理)

  1. curl -# -O http://ftp.apnic.net/stats/apnic/legacy-apnic-latest
  2. cat legacy-apnic-latest | grep -v '*' | grep -v + > 1.txt
  3. sed -i 's/256/24/g' 1.txt
  4. sed -i 's/512/23/g' 1.txt
  5. sed -i 's/1024/22/g' 1.txt
  6. sed -i 's/2048/21/g' 1.txt
  7. sed -i 's/4096/20/g' 1.txt
  8. sed -i 's/8192/19/g' 1.txt
  9. sed -i 's/16384/18/g' 1.txt
  10. sed -i 's/32768/17/g' 1.txt
  11. sed -i 's/65536/16/g' 1.txt
  12. sed -i 's/131072/15/g' 1.txt
  13. sed -i 's/262144/14/g' 1.txt
  14. sed -i 's/524288/13/g' 1.txt
  15. sed -i 's/1048576/12/g' 1.txt
  16. sed -i 's/2097152/11/g' 1.txt
  17. sed -i 's/4194304/10/g' 1.txt
  18. sed -i 's/8388608/9/g' 1.txt
  19. sed -i 's/16777216/8/g' 1.txt
  20. sed -i 's/|/ /g' 1.txt
  21. sed -i 's/apnic ipv4 //g' 1.txt
  22. awk '{print $1,$2}' 1.txt | sed 's_ _/_g' > 2.txt
  23. sed 's/^/& route add -net /g' 2.txt| sed 's/$/& reject/g' > reject.sh
  24. [root@localhost ~]# more reject.sh
  25. route add -net 128.134.0.0/16 reject
  26. route add -net 128.184.0.0/16 reject
  27. route add -net 128.250.0.0/16 reject
  28. ...
  1. [root@localhost ~]# route -n | more
  2. Kernel IP routing table
  3. Destination Gateway Genmask Flags Metric Ref Use Iface
  4. ....
  5. 8.128.0.0 - 255.192.0.0 ! 0 - 0 -
  6. 8.208.0.0 - 255.240.0.0 ! 0 - 0 -
  7. ....
  1. #查看全部
  2.  route  -n | grep '!' 
  3. #批量删除全部reject条目
  4.  route  -n | grep '!'  | awk   '{ print "route delete -net " $1 " netmask " $3 " reject "}'  | bash
  1. 单条删除
  2. add 变delete
  3. route delete -net 8.8.8.8 netmask 255.255.255.255 reject
  4. 注: 错误写法
  5. route add -net .8.8.8.8/32 reject
  6. SIOCADDRT: 无效的参数
  7. 因不支持/32
  8. reject丢弃数据包,不作回应,甚至不回应arp的询问

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/weixin_40725706/article/detail/229924
推荐阅读
相关标签
  

闽ICP备14008679号