溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊(cè)×
其他方式登錄
點(diǎn)擊 登錄注冊(cè) 即表示同意《億速云用戶服務(wù)條款》

Linux添加永久靜態(tài)路由信息

發(fā)布時(shí)間:2020-08-10 22:06:42 來源:ITPUB博客 閱讀:150 作者:ywxj_001 欄目:建站服務(wù)器
因?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 eth0
0.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 eth0
0.0.0.0         192.168.123.254 0.0.0.0         UG    0      0        0 eth2

這樣無論是重啟主機(jī)還是重啟網(wǎng)絡(luò)服務(wù)路由信息都不會(huì)丟了。

向AI問一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場,如果涉及侵權(quán)請(qǐng)聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI