在不同的linux发行版中添加永久静态路由,方式各不一样。

ubuntu/debian

$ sudo vim /etc/network/interfaces
------8<--------
iface eth0 inet static
address 192.168.0.1
netmask 255.255.255.0
broadcast 192.168.0.255
post-up ip route add x.x.x.0/24 via 192.168.0.254 dev eth0
pre-down ip route del x.x.x.0/24
# 192.168.0.254是网关
------>8--------

redhat/centos

$ sudo vim /etc/sysconfig/network/route-eth0
------8<--------
route add -net x.x.x.0/24 via 192.168.0.254 dev eth0
# 192.168.0.254是网关
------>8--------