因为linux服务器有多网卡,需要有些网卡走指定的路由,就需要单独设置静态路由。
通过route add添加的静态路由,如果服务器重启或者是网卡重启,这个静态路由就会丢失。
[root@test ~]# route -n
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
192.168.123.0 0.0.0.0 255.255.255.0 U 0 0 0 eth2
10.0.0.0 0.0.0.0 255.255.0.0 U 0 0 0 eth0
169.254.0.0 0.0.0.0 255.255.0.0 U 0 0 0 eth2
0.0.0.0 192.168.123.254 0.0.0.0 UG 0 0 0 eth2
用route add添加静态路由。
[root@test ~]# route add -net 10.0.0.0 netmask 255.0.0.0 dev eth0
[root@test ~]# route -n
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
192.168.123.0 0.0.0.0 255.255.255.0 U 0 0 0 eth2
10.0.0.0 0.0.0.0 255.255.0.0 U 0 0 0 eth0
169.254.0.0 0.0.0.0 255.255.0.0 U 0 0 0 eth2
10.0.0.0 0.0.0.0 255.0.0.0 U 0 0 0 eth00.0.0.0 192.168.123.254 0.0.0.0 UG 0 0 0 eth2
添加成功,但是重启网络服务后路由丢失,证明这个路由是动态参数。
[root@test ~]# service network restart
Shutting down interface eth0: [ OK ]
Shutting down interface eth2: [ OK ]
Shutting down loopback interface: [ OK ]
Bringing up loopback interface: [ OK ]
Bringing up interface eth0: [ OK ]
Bringing up interface eth2: [ OK ]
[root@test ~]# route -n
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
192.168.123.0 0.0.0.0 255.255.255.0 U 0 0 0 eth2
10.0.0.0 0.0.0.0 255.255.0.0 U 0 0 0 eth0
169.254.0.0 0.0.0.0 255.255.0.0 U 0 0 0 eth2
0.0.0.0 192.168.123.254 0.0.0.0 UG 0 0 0 eth2
需要永久添加静态路由:
到/etc/sysconfig/network-scripts/下面
[root@test ~]# cd /etc/sysconfig/network-scripts/
加入一条静态路由到route-eth0,让网络服务每次重启都会自动加载这些信息。保证路由不丢失。
[root@shwmsdb1 network-scripts]# cat route-eth0
10.0.0.0/8 via 10.0.0.254
[root@test ~]# route -n
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
192.168.123.0 0.0.0.0 255.255.255.0 U 0 0 0 eth2
10.0.0.0 0.0.0.0 255.255.0.0 U 0 0 0 eth0
169.254.0.0 0.0.0.0 255.255.0.0 U 0 0 0 eth2
10.0.0.0 10.0.0.254 255.0.0.0 UG 0 0 0 eth00.0.0.0 192.168.123.254 0.0.0.0 UG 0 0 0 eth2
这样无论是重启主机还是重启网络服务路由信息都不会丢了。
网站栏目:Linux添加永久静态路由信息-创新互联
文章出自:
http://cdweb.net/article/ccidds.html