配置查看
metric代表优先级,数字越小优先级越高
route -n
手动增删路由表
route del default gw xx.xx.xx.xx eth0
route add default gw xx.xx.xx.x dev eth0 metric 99
xx为网关
持久化配置
- 添加rc.local配置文件
vi /etc/rc.local
复制以下内容
#!/bin/sh -e
(
sleep 30
/usr/sbin/route del default gw 172.16.1.1 eno1
/usr/sbin/route add default gw 172.16.1.1 dev eno1 metric 1001
) &
exit 0
加可执行权限
- mint添加rc服务
默认mint系统已经没有rc服务,因此需要添加
sudo vim /etc/systemd/system/rc-local.service
[Unit]
Description=/etc/rc.local Compatibility
ConditionPathExists=/etc/rc.local
[Service]
Type=forking
ExecStart=/etc/rc.local start
TimeoutSec=0
StandardOutput=tty
RemainAfterExit=yes
SysVStartPriority=99
[Install]
WantedBy=multi-user.target
激活rc服务
sudo systemctl enable rc-local.service
确保重启后仍有服务
创建并编辑/etc/network/if-up.d/route-set文件
#!/bin/sh
(
sleep 30
/usr/sbin/route del default gw 10.10.11.250 eth0
/usr/sbin/route add default gw 10.10.11.250 dev eth0 metric 204
) &
exit 0
参考
https://www.wyr.me/post/707
https://cloud.tencent.com/developer/article/1721972