一:使用 route 命令添加(臨時路由)
使用route 命令添加的路由在機(jī)器重啟或者網(wǎng)卡重啟后路由就失效了,方法:
//添加到主機(jī)的路由
# route add –host 192.168.168.110 dev eth0
# route add –host 192.168.168.119 gw 192.168.168.1
//添加到網(wǎng)絡(luò)的路由
# route add –net IP netmask MASK eth0
# route add –net IP netmask MASK gw IP
# route add –net IP/24 eth1
//添加默認(rèn)網(wǎng)關(guān)
# route add default gw IP
//刪除路由
# route del –host 192.168.168.110 dev eth0
免費(fèi)視頻教程推薦:linux視頻教程
二:在linux下設(shè)置永久路由的方法:
1、在/etc/rc.local里添加
方法:
route add -net 192.168.3.0/24 dev eth0
route add -net 192.168.2.0/24 gw 192.168.2.254
route add –net 180.200.0.0 netmask 255.255.0.0 gw 10.200.6.201 dev eth0 metric 1
參數(shù)說明:
route add:命令關(guān)鍵字,表示增加路由,若要刪除路由,則為route del;
-host/-net:表示路由目標(biāo)是主機(jī)還是網(wǎng)段;
netmask:表示路由目標(biāo)為網(wǎng)段時才會使用到,表示路由目標(biāo)網(wǎng)段的子網(wǎng)掩碼;
gw:命令關(guān)鍵字,后面跟下一跳網(wǎng)關(guān);
dev:命令關(guān)鍵字,后面跟具體設(shè)備名,表示路由是從該設(shè)備出去。
metric:為路由指定所需躍點數(shù)的整數(shù)值(范圍是 1 ~ 9999),它用來在路由表里的多個路由中選擇與轉(zhuǎn)發(fā)包中的目標(biāo)地址最為匹配的路由。所選的路由具有最少的躍點數(shù)。躍點數(shù)能夠反映躍點的數(shù)量、路徑的速度、路徑可靠性、路徑吞吐量以及管理屬性。
2、在/etc/sysconfig/network里添加到末尾
方法:
GATEWAY=gw-ip
或者
GATEWAY=gw-dev
3、
/etc/sysconfig/static-routes :
any net 192.168.3.0/24 gw 192.168.3.254
any net 10.250.228.128 netmask 255.255.255.192 gw 10.250.228.129
如果在rc.local中添加路由可能會造成NFS無法自動掛載問題,所以使用static-routes方法是最好的。無論重啟系統(tǒng)和service network restart 都會生效。
本文由網(wǎng)上采集發(fā)布,不代表我們立場,轉(zhuǎn)載聯(lián)系作者并注明出處:http://m.webhosting0.com/shbk/39464.html