• 使用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的询问

  • 相关阅读:
    C. Swap Game(简单博弈)
    JIRA 如何在项目之间移动 Issue
    26. 删除有序数组中的重复项
    linux下安装ffmpeg的详细教程、ffmpeg is not installed
    Postgresql 阿里云部署排雷
    嵌入式MCU和SOC的区别?
    鸿蒙DevEco Service开发准备与使用
    生产升级JDK 17 必读手册
    【C++】从入门到精通第四弹——命名空间
    SpringBoot上传文件-本地存储
  • 原文地址:https://blog.csdn.net/endzhi/article/details/136602091