V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
Distributions
Ubuntu
Fedora
CentOS
中文资源站
网易开源镜像站
manfred4527
V2EX  ›  Linux

Linux 如何批量添加路由

  •  
  •   manfred4527 · 2020-03-07 16:57:32 +08:00 · 2893 次点击
    这是一个创建于 1513 天前的主题,其中的信息可能已经有所发展或是发生改变。

    因为多 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 条回复    2020-03-07 19:15:43 +08:00
    taolu
        1
    taolu  
       2020-03-07 17:56:16 +08:00   ❤️ 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
       2020-03-07 19:15:43 +08:00
    @taolu 感谢 我等会试一下
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   2664 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 25ms · UTC 15:36 · PVG 23:36 · LAX 08:36 · JFK 11:36
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.