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

国内单机双网卡机器需要做源进源出配置才能确保国内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 脚本来配置路由。

暂无评论

发送评论 编辑评论


				
|´・ω・)ノ
ヾ(≧∇≦*)ゝ
(☆ω☆)
(╯‵□′)╯︵┴─┴
 ̄﹃ ̄
(/ω\)
∠( ᐛ 」∠)_
(๑•̀ㅁ•́ฅ)
→_→
୧(๑•̀⌄•́๑)૭
٩(ˊᗜˋ*)و
(ノ°ο°)ノ
(´இ皿இ`)
⌇●﹏●⌇
(ฅ´ω`ฅ)
(╯°A°)╯︵○○○
φ( ̄∇ ̄o)
ヾ(´・ ・`。)ノ"
( ง ᵒ̌皿ᵒ̌)ง⁼³₌₃
(ó﹏ò。)
Σ(っ °Д °;)っ
( ,,´・ω・)ノ"(´っω・`。)
╮(╯▽╰)╭
o(*////▽////*)q
>﹏<
( ๑´•ω•) "(ㆆᴗㆆ)
😂
😀
😅
😊
🙂
🙃
😌
😍
😘
😜
😝
😏
😒
🙄
😳
😡
😔
😫
😱
😭
💩
👻
🙌
🖕
👍
👫
👬
👭
🌚
🌝
🙈
💊
😶
🙏
🍦
🍉
😣
Source: github.com/k4yt3x/flowerhd
颜文字
Emoji
小恐龙
花!
上一篇