Anybody

  • AI相关
  • 网络
  • 工具
  1. 首页
  2. Linux
  3. 正文

国内单机双网卡 Linux无法访问国内IP 的解决办法

2026年1月23日 400点热度 0人点赞 0条评论

国内单机双网卡机器需要做源进源出配置才能确保国内IP正常访问。

  1. 创建一个脚本文件,例如 /usr/local/bin/setup_route.sh
    #!/bin/bash
    #添加路由表
    if ! grep -q "custom_table" /etc/iproute2/rt_tables; then
     echo "1    custom_table" >> /etc/iproute2/rt_tables
    fi
    #添加路由,将gwip替换为国内IP的网关IP,eth1替换为国内IP对应的网卡
    ip route add default via gwip dev eth1 table custom_table
    #添加规则,将cnip替换为国内IP
    ip rule add from cnip table custom_table
  2. 设置脚本为可执行:

chmod +x /usr/local/bin/setup_route.sh

  1. 创建一个 systemd 服务文件,使其在开机时运行: 创建文件 /etc/systemd/system/setup_route.service,内容如下:

    [Unit]
    Description=Setup custom routing table
    After=network.target
    [Service]
    Type=oneshot
    ExecStart=/usr/local/bin/setup_route.sh
    RemainAfterExit=yes
    [Install]
    WantedBy=multi-user.target
  2. 启用并启动服务:

    systemctl enable setup_route.service
    systemctl start setup_route.service

这样,每次开机时,系统将运行 /usr/local/bin/setup_route.sh 脚本来配置路由。

本作品采用 知识共享署名 4.0 国际许可协议 进行许可
标签: 暂无
最后更新:2026年1月23日

管理员

Github

点赞
< 上一篇

文章评论

razz evil exclaim smile redface biggrin eek confused idea lol mad twisted rolleyes wink cool arrow neutral cry mrgreen drooling persevering
取消回复

COPYRIGHT © 2026 Anybody. ALL RIGHTS RESERVED.

Theme Kratos Made By Seaton Jiang