六月丁香五月婷婷,丁香五月婷婷网,欧美激情网站,日本护士xxxx,禁止18岁天天操夜夜操,18岁禁止1000免费,国产福利无码一区色费

學(xué)習(xí)啦 > 學(xué)習(xí)電腦 > 操作系統(tǒng) > Linux教程 > linux route命令詳解

linux route命令詳解

時間: 佳洲1085 分享

linux route命令詳解

  route命令是linux下的一個命令,那么它有什么用處呢?下面由學(xué)習(xí)啦小編為大家整理了linux route命令的相關(guān)知識,希望大家喜歡!

  linux route命令

  route命令用于顯示和操作IP路由表。要實現(xiàn)兩個不同的子網(wǎng)之間的通信,需要一臺連接兩個網(wǎng)絡(luò)的路由器,或者同時位于兩個網(wǎng)絡(luò)的網(wǎng)關(guān)來實現(xiàn)。在Linux系統(tǒng)中,設(shè)置路由通常是 為了解決以下問題:該Linux系統(tǒng)在一個局域網(wǎng)中,局域網(wǎng)中有一個網(wǎng)關(guān),能夠讓機器訪問Internet,那么就需要將這臺機器的IP地址設(shè)置為 Linux機器的默認路由。要注意的是,直接在命令行下執(zhí)行route命令來添加路由,不會永久保存,當網(wǎng)卡重啟或者機器重啟之后,該路由就失效了;要想永久保存,有如下方法:

  1.在/etc/rc.local里添加

  2.在/etc/sysconfig/network里添加到末尾

  3./etc/sysconfig/static-router :

  any net x.x.x.x/24 gw y.y.y.y

  格式:route

  格式:/sbin/route

  用于打印路由表(display the current routing table)。

  在非root用戶使用時需要使用完整路徑執(zhí)行route命令。

  命令參數(shù)

  [root@linux ~]# route [-nee]

  [root@linux ~]# route add [-net|-host] [網(wǎng)域或主機] netmask [mask] [gw|dev]

  [root@linux ~]# route del [-net|-host] [網(wǎng)域或主機] netmask [mask] [gw|dev]

  觀察的參數(shù):

  -n :不要使用通訊協(xié)定或主機名稱,直接使用 IP 或 port number;

  -ee :使用更詳細的資訊來顯示

  增加 (add) 與刪除 (del) 路由的相關(guān)參數(shù):

  -net :表示后面接的路由為一個網(wǎng)域;

  -host :表示后面接的為連接到單部主機的路由;

  netmask :與網(wǎng)域有關(guān),可以設(shè)定 netmask 決定網(wǎng)域的大小;

  gw :gateway 的簡寫,后續(xù)接的是 IP 的數(shù)值喔,與 dev 不同;

  dev :如果只是要指定由那一塊網(wǎng)路卡連線出去,則使用這個設(shè)定,后面接 eth0 等

  格式:route -n

  格式:/sbin/route -n

  用于打印路由表,加上-n參數(shù)就是在輸出的信息中不打印主機名而直接打印ip地址。

  格式:route add default gw {IP-ADDRESS} {INTERFACE-NAME}

  用于設(shè)置默認路由,其中,

  參數(shù){IP-ADDRESS): 用于指定路由器(網(wǎng)關(guān))的IP地址;

  參數(shù){INTERFACE-NAME}: 用于指定接口名稱,如eth0。使用/sbin/ifconfig -a可以顯示所有接口信息。

  例:route add default gw mango

  格式:route add -net {NETWORK-ADDRESS} netmask {NETMASK} dev {INTERFACE-NAME}

  添加到指定網(wǎng)絡(luò)的路由規(guī)則,其中

  參數(shù){NETWORK-ADDRESS}: 用于指定網(wǎng)絡(luò)地址

  參數(shù){NETMASK}: 用于指定子網(wǎng)掩碼

  參數(shù){INTERFACE-NAME}: 用于指定接口名稱,如eth0。

  例1:route add -net 192.56.76.0 netmask 255.255.255.0 dev eth0

  例2:route add -net 224.0.0.0 netmask 240.0.0.0 dev eth0

  格式:route add -net {NETWORK-ADDRESS} netmask {NETMASK} reject

  設(shè)置到指定網(wǎng)絡(luò)為不可達,避免在連接到這個網(wǎng)絡(luò)的地址時程序過長時間的等待,直接就知道該網(wǎng)絡(luò)不可達。

  例:route add -net 10.0.0.0 netmask 255.0.0.0 reject

  格式:route del -net {NETWORK-ADDRESS} netmask {NETMASK} dev {INTERFACE-NAME}

  格式:route del -net {NETWORK-ADDRESS} netmask {NETMASK} reject

  用于刪除路由設(shè)置。參數(shù)指定的方式與route add相似。

  輸出詳解

  route命令輸出的路由表字段含義如下:

  Destination 目標

  The destination network or destination host. 目標網(wǎng)絡(luò)或目標主機。

  Gateway 網(wǎng)關(guān)

  The gateway address or '*' if none set. 網(wǎng)關(guān)地址,如果沒有就顯示星號。

  Genmask 網(wǎng)絡(luò)掩碼

  The netmask for the destination net; '255.255.255.255' for a

  host destination and '0.0.0.0' for the default route.

  Flags:總共有多個旗標,代表的意義如下:

  o U (route is up):該路由是啟動的;

  o H (target is a host):目標是一部主機 (IP) 而非網(wǎng)域;

  o G (use gateway):需要透過外部的主機 (gateway) 來轉(zhuǎn)遞封包;

  o R (reinstate route for dynamic routing):使用動態(tài)路由時,恢復(fù)路由資訊的旗標;

  o D (dynamically installed by daemon or redirect):已經(jīng)由服務(wù)或轉(zhuǎn) port 功能設(shè)定為動態(tài)路由

  o M (modified from routing daemon or redirect):路由已經(jīng)被修改了;

  o ! (reject route):這個路由將不會被接受(用來抵擋不安全的網(wǎng)域!)

  o A (installed by addrconf)

  o C (cache entry)

  Metric 距離、跳數(shù)。暫無用。

  The 'distance' to the target (usually counted in hops). It is

  not used by recent kernels, but may be needed by routing dae-

  mons.

  Ref 不用管,恒為0。

  Number of references to this route. (Not used in the Linux ker-nel.)

  Use 該路由被使用的次數(shù),可以粗略估計通向指定網(wǎng)絡(luò)地址的網(wǎng)絡(luò)流量。

  Count of lookups for the route. Depending on the use of -F and

  -C this will be either route cache misses (-F) or hits (-C).

  Iface 接口,即eth0,eth0等網(wǎng)絡(luò)接口名

  Interface to which packets for this route will be sent.

3572972