因?yàn)閘inux服務(wù)器有多網(wǎng)卡,需要有些網(wǎng)卡走指定的路由,就需要單獨(dú)設(shè)置靜態(tài)路由。
通過route add添加的靜態(tài)路由,如果服務(wù)器重啟或者是網(wǎng)卡重啟,這個(gè)靜態(tài)路由就會(huì)丟失。
[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添加靜態(tài)路由。
[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
添加成功,但是重啟網(wǎng)絡(luò)服務(wù)后路由丟失,證明這個(gè)路由是動(dòng)態(tài)參數(shù)。
[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
需要永久添加靜態(tài)路由:
到/etc/sysconfig/network-scripts/下面
[root@test ~]# cd /etc/sysconfig/network-scripts/
加入一條靜態(tài)路由到route-eth0,讓網(wǎng)絡(luò)服務(wù)每次重啟都會(huì)自動(dòng)加載這些信息。保證路由不丟失。
[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
這樣無論是重啟主機(jī)還是重啟網(wǎng)絡(luò)服務(wù)路由信息都不會(huì)丟了。
本文標(biāo)題:Linux添加永久靜態(tài)路由信息-創(chuàng)新互聯(lián)
本文路徑:
http://weahome.cn/article/ccidds.html