国内单机双网卡机器需要做源进源出配置才能确保国内IP正常访问。
- 创建一个脚本文件,例如
/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 - 设置脚本为可执行:
chmod +x /usr/local/bin/setup_route.sh
-
创建一个 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 -
启用并启动服务:
systemctl enable setup_route.service systemctl start setup_route.service
这样,每次开机时,系统将运行 /usr/local/bin/setup_route.sh 脚本来配置路由。

