linux route命令使用
轉(zhuǎn)自:http://linux008.blog.51cto.com/2837805/550596
說明:route命令是打印和操作ip路由表
描述:route操作基于內(nèi)核ip路由表,它的主要作用是創(chuàng)建一個(gè)靜態(tài)路由讓指定一個(gè)主機(jī)或者一個(gè)網(wǎng)絡(luò)通過一個(gè)網(wǎng)絡(luò)接口,如eth0。當(dāng)使用"add"或者"del"參數(shù)時(shí),路由表被修改,如果沒有參數(shù),則顯示路由表當(dāng)前的內(nèi)容。
參數(shù)說明:add:添加一條新路由。
del:刪除一條路由。
-net:目標(biāo)地址是一個(gè)網(wǎng)絡(luò)。
-host:目標(biāo)地址是一個(gè)主機(jī)。
netmask:當(dāng)添加一個(gè)網(wǎng)絡(luò)路由時(shí),需要使用網(wǎng)絡(luò)掩碼。
gw:路由數(shù)據(jù)包通過網(wǎng)關(guān)。注意,你指定的網(wǎng)關(guān)必須能夠達(dá)到。
metric:設(shè)置路由跳數(shù)。
實(shí)例:
1、route add -net 192.168.2.0 netmask 255.255.255.0 dev eth0
添加一條到達(dá)192.168.2.0網(wǎng)絡(luò)的路由,指定網(wǎng)絡(luò)掩碼為255.255.255.0,數(shù)據(jù)包通過網(wǎng)絡(luò)接口eth0。
2、route add -net 192.57.66.0 netmask 255.255.255.0 gw 192.168.2.1
添加一條到達(dá)192.57.66.0網(wǎng)絡(luò)的路由,指定網(wǎng)絡(luò)掩碼為255.255.255.0,數(shù)據(jù)包通過網(wǎng)關(guān)地址192.168.2.1。
3、route add -host 192.57.66.200 gw 192.168.2.1
所有去往192.57.66.200主機(jī)的數(shù)據(jù)包發(fā)往網(wǎng)關(guān)地址192.168.2.1。
4、route add default gw 192.168.1.1
添加一條默認(rèn)網(wǎng)關(guān),所有的數(shù)據(jù)包將被轉(zhuǎn)發(fā)到192.168.1.1。
路由表內(nèi)容說明:
查看路由
# route -n
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
192.57.66.200 192.168.1.1 255.255.255.255 UGH 0 0 0 eth0
192.168.1.0 0.0.0.0 255.255.255.0 U 0 0 0 eth0
169.254.0.0 0.0.0.0 255.255.0.0 U 0 0 0 eth0
0.0.0.0 192.168.1.1 0.0.0.0 UG 0 0 0 eth0
Destination:目標(biāo)網(wǎng)絡(luò)或主機(jī)。
Gateway:網(wǎng)關(guān)地址。
Genmask:目標(biāo)網(wǎng)絡(luò)的網(wǎng)絡(luò)掩碼。"255.255.255.255"表示一個(gè)主機(jī)。"0.0.0.0"表示網(wǎng)關(guān)。
Flags:標(biāo)記。
U、路由被啟用。
H、目標(biāo)是一個(gè)主機(jī)
G、使用網(wǎng)關(guān)。