- 论坛徽章:
- 0
|
转载鸟哥的一些关于route命令的资料:
[color="#000099"]route
顯示/修改路由表( route table
)
[color="#ff0000"]語法:
[root@test
root]# [color="#ffff00"]route [-nee]
[root@test
root]# route add [-net|-host] 目標主機或網域
[netmask] [gw|dev]
[root@test
root]# route del [-net|-host] 目標主機或網域
[netmask] [gw|dev]
[color="#ff6666"]參數說明:
-n :列出的資訊以
IP 來顯示
[color="#ffffcc"]-ee :列出較長列的資訊
[color="#ffffcc"]add :增加路由資訊
[color="#ffffcc"]del :刪除一個路由資訊
-net :增加一個『網域』的路由,例如
C Class 的網域!
-host :增加到某個
IP 主機的路由!
netmask :就是
netmask 呀!
gw :這個是路由的通訊閘!
gw 是以 IP 來建置的
dev :這個是路由的通訊閘!
dev 是以 介面 ( internet ) 代號來建置的!
[color="#ff6666"]範例:
[root@test
root]# [color="#ffff00"]route[color="#ff6666"]
Kernel IP routing
table
Destination
Gateway Genmask
Flags Metric Ref Use Iface
140.116.141.253
*
255.255.255.255 UH 0 0
0 ppp0
192.168.1.0
*
255.255.255.0 U 0
0 0 eth0
127.0.0.0
*
255.0.0.0 U
0 0 0 lo
default
140.116.141.253 0.0.0.0
UG 0 0
0 ppp0
[color="#ffffff"]
[root@test
root]# [color="#ffff00"]route -n
Kernel IP routing
table
Destination
Gateway Genmask
Flags Metric Ref Use Iface
140.116.141.253
0.0.0.0 255.255.255.255
UH 0 0
0 ppp0
192.168.1.0
0.0.0.0 255.255.255.0
U 0 0
0 eth0
127.0.0.0
0.0.0.0 255.0.0.0
U 0 0
0 lo
0.0.0.0
140.116.141.253 0.0.0.0
UG 0 0
0 ppp0
注意到 route,
route -n 這兩個範例喔!使用 -n 與否會使 domain 是否進行查詢,
一般來說,我都喜歡加上
-n 的,因為不必去查詢正反解,顯示速度較快,
此外, default
gateway 就是 0.0.0.0 喔!
[color="#ffffff"]
[root@test
root]# route add -net 192.168.0.0 netmask
255.255.255.0 dev eth0
[color="#ff6666"]# 新增一個路由規則!
[color="#ffffff"]
[root@test
root]# route del -net 192.168.0.0 netmask
255.255.255.0 dev eth0
[color="#ff6666"]# 刪除一個路由囉
[color="#ff6666"]
[root@test
root]#[color="#ffff00"] route add default gw 192.168.1.2
# 增加一個
default gateway 呢!
注意一下,
gw 後面接的是 IP ,而 dev 後面接的則是裝置代號喔!
[color="#ff0000"]說明:
這個指令相當的有用!尤其是新手們最容易犯錯的 gateway 設定錯誤的問題,都可以藉由這一個指令來檢查呢!這個指令有兩個主要的用途:
[color="#000066"]顯示目前主機上面的路由資訊;
修改( 增加或刪除 )主機上面的路由表!『可以建置 router
呦!』
我們來談一談使用 route 時,顯示的內容意義:
[color="#000066"]Destination:目標,可以是
IP 也可以是網域!至於沒有規定到的,則是以 default 來表示!以上面為例,當我的機器要去
192.168.1.0 的時候,則以上表的 192.168.1.0 那一行的設定為主,但如果我要去
tw.yahoo.com 的時候,由於沒有規定到!所以就要以 default 的資訊為主要的路由!因此,我就會經由
140.116.141.253 這個 gateway 來傳送出去我的封包囉!
[color="#000066"]Gateway :該目標要經由哪一個網關傳送?就是這一個設定值啦!
[color="#000066"]Genmask :就是該
Destination 的 netmask 囉!例如 140.116.141.253 為 255.255.255.255 ,因為他是一個
host 而不是一個 network 呀!至於 192.168.1.0 就是 255.255.255.0 這個 C
Class 囉!那如果是 default 的話,就顯示 0.0.0.0 ,也就是不論是哪裡,都出自這一個
gateway 就是了!
[color="#000066"]Flages :旗標,有底下幾種
Flage 呢:
[color="#000066"]U (route is up):該路由已經啟動了;
H (target is a host):目標是一個主機( IP ),例如上面範例中的
140.116.141.253 那一個;
[color="#000066"]G (use gateway):用來作為 gateway 的設定;
[color="#000066"]R (reinstate route for dynamic routing):使用動態路由時,恢復路由資訊的旗標;
D (dynamically installed by daemon or redirect):已經由服務或轉
port 功能設定為 動態路由;
[color="#000066"]M (modified from routing daemon or redirect):路由已經被修改了;
[color="#000066"]! (reject route):這個路由將不會被接受(用來抵擋不安全的網域!)
[color="#000066"]Iface :該設定使用的網路介面為何?
好了,那麼如何增加或刪除路由呢!就由上面的例子就可以知道啦!很簡單的啦!不過需要注意的是,單純有路由功能還不夠!因為還需要有
router
的功能才行!我們將在
router 那個章節再來持續談一談這個問題囉!『註:當您發現下達
route 的時候,顯示的速度很慢時,通常是您的路由資訊有一定的問題存在!果真如此的話,請務必仔細的檢查一下設定,否則對於您的網路速度會有遲滯現象呦!』
本文来自ChinaUnix博客,如果查看原文请点:http://blog.chinaunix.net/u/12592/showart_131920.html |
|