一、使用 route 命令加入临时路由,重启后将失效
ip route add 添加路由 重启后失效
ip route show 查看路由
二、在 Linux 中添加永久路由的方法
1. centos系统
创建 /etc/sysconfig/network-scripts/route-eth0(推荐)
在 `/etc/sysconfig/network-scripts/` 目录下创建名为 route-eth0 的文件
vi /etc/sysconfig/network-scripts/route-eth0
# 在此文件添加如下格式的内容
11.12.112.0/20 via 11.12.111.1
# 重启网络验证有效
systemctl restart network
2.ubuntu系统
root@xdja-0C:~# root@xdja-0C:~# cat /etc/network/interfaces
auto eno3
iface eno3 inet static
address 11.12.112.14
netmask 255.255.255.0
up ip route add 11.12.112.0/20 via 11.12.112.1 dev eno3
up ip route add 11.12.96.0/20 via 11.12.112.1 dev eno3
up ip route add 11.12.80.0/20 via 11.12.112.1 dev eno3
up ip route add 172.27.136.0/24 via 11.12.112.1 dev eno3