V2EX = way to explore
V2EX 是一个关于分享和探索的地方
Sign Up Now
For Existing Member  Sign In
Distributions
Ubuntu
Fedora
CentOS
中文资源站
网易开源镜像站
manfred4527
V2EX  ›  Linux

Linux 如何批量添加路由

  •  
  •   manfred4527 · Mar 7, 2020 · 3378 views
    This topic created in 2245 days ago, the information mentioned may be changed or developed.

    因为多 ISP 接入,现在希望通过 iproute2 批量添加 ISP 路由,将网站的 ISP 的 IP 地址段( https://ispip.clang.cn/cmcc_cidr.txt )批量添加路由

    需要批量输入命令

    ip route add TXT 文件内容 via 1.1.1.1 dev eth0 table x

    ip rule add from TXT 文件内容 to any table X pref x

    以上的命令有什么脚本可以快速输入

    2 replies    2020-03-07 19:15:43 +08:00
    taolu
        1
    taolu  
       Mar 7, 2020   ❤️ 1
    curl https://ispip.clang.cn/cmcc_cidr.txt | while read ip; do ip route add ${ip} via 1.1.1.1 dev eth0 table x; ip rule add from ${ip} to any table X pref x; done
    manfred4527
        2
    manfred4527  
    OP
       Mar 7, 2020
    @taolu 感谢 我等会试一下
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   5128 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 32ms · UTC 09:07 · PVG 17:07 · LAX 02:07 · JFK 05:07
    ♥ Do have faith in what you're doing.