萬盛學電腦網

 萬盛學電腦網 >> 網絡應用技術 >> 應用教程 >> 多個IP選擇線路的解決辦法之route命令

多個IP選擇線路的解決辦法之route命令

   一台電腦兩條線路一個電信IP一個聯通的IP,解決訪問電信的時候自動走電信線路,訪問聯通的時候自動走聯通的線路,我們可以用到下面這個命令

  ROUTEDOS命令我們都可以在 Cmd 下用 route /? 來查看他的幫助信息

  先看一下他的幫助

  Manipulates network routing tables.

  ROUTE [-f] [-p] [command [destination]

  [MASK netmask] [gateway] [METRIC metric] [IF interface]

  -f Clears the routing tables of all gateway entries. If this is

  used in conjunction with one of the commands, the tables are

  cleared prior to running the command.

  -p When used with the ADD command, makes a route persistent across

  boots of the system. By default, routes are not preserved

  when the system is restarted. Ignored for all other commands,

  which always affect the appropriate persistent routes. This

  option is not supported in Windows 95.

  command One of these:

  PRINT Prints a route

  ADD Adds a route

  DELETE Deletes a route

  CHANGE Modifies an existing route

  destination Specifies the host.

  MASK Specifies that the next parameter is the 'netmask' value.

  netmask Specifies a subnet mask value for this route entry.

  If not specified, it defaults to 255.255.255.255.

  gateway Specifies gateway.

  interface the interface number for the specified route.

  METRIC specifies the metric, ie. cost for the destination.

  All symbolic names used for destination are looked up in the network database

  file NETWORKS. The symbolic names for gateway are looked up in the host name

  database file HOSTS.

  If the command is PRINT or DELETE. Destination or gateway can be a wildcard,

  (wildcard is specified as a star '*'), or the gateway argument may be omitted.

  If Dest contains a * or ?, it is treated as a shell pattern, and only

  matching destination routes are printed. The '*' matches any string,

  and '?' matches any one char. Examples: 157.*.1, 157.*, 127.*, *224*.

  Diagnostic Notes:

  Invalid MASK generates an error, that is when (DEST & MASK) != DEST.

  Example> route ADD 157.0.0.0 MASK 155.0.0.0 157.55.80.1 IF 1

  The route addition failed: The specified mask parameter is invalid

  (Destination & Mask) != Destination.

  Examples:

  > route PRINT

  > route ADD 157.0.0.0 MASK 255.0.0.0 157.55.80.1 METRIC 3 IF 2

  destination^ ^mask ^gateway metric^ ^

  Interface^

  If IF is not given, it tries to find the best interface for a given

  gateway.

  > route PRINT

  > route PRINT 157* .... Only prints those matching 157*

  > route CHANGE 157.0.0.0 MASK 255.0.0.0 157.55.80.5 METRIC 2 IF 2

  CHANGE is used to modify gateway and/or metric only.

  > route PRINT

  > route DELETE 157.0.0.0

  > route PRINT

  route - 顯示 / 操作IP選路表

  總覽 SYNOPSIS

  route [-CFvnee]

  route [-v] [-A family] add [-net|-host] target [netmask Nm] [gw Gw] [metric N] [mss M] [window W] [irtt I][reject] [mod] [dyn] [reinstate] [[dev] If]

  route [-v] [-A family] del [-net|-host] target [gw Gw][netmask Nm] [metric N] [[dev] If]

  route [-V] [--version] [-h] [--help]

  描述 DESCRIPTION

  route程序對內核的IP選路表進行操作。它主要用於通過已用ifconfig(8)程序配置好的接口來指定的主機或網絡設置靜態路由。

  選項 OPTIONS

  -v

  選用細節操作模式

  -A family

  用指定的地址族(如`inet',`inet6')。

  -n

  以數字形式代替解釋主機名形式來顯示地址。此項對試圖檢測對域名服務器進行路由發生故障的原因非常有用。

  -e

  用netstat(8)的格式來顯示選路表。-ee將產生包括選路表所有參數在內的大量信息。

  -net

  路由目標為網絡。

  -host

  路由目標為主機。

  -F

  顯示內核的FIB選路表。其格式可以用-e 和 -ee選項改變。

  -C

  顯示內核的路由緩存。

  del

  刪除一條路由。

  add

  添加一條路由。

  target

  指定目標網絡或主機。可以用點分十進制形式的IP地址或主機/網絡名。

  netmask Nm

  為添加的路由指定網絡掩碼。

  gw Gw

  為發往目標網絡/主機的任何分組指定網關。注意:指定的網關首先必須是可達的。也就是說必須為該網關預先指定一條靜態路由。如果你為本地接口之一指定這個網關地址的話,那麼此網關地址將用於決定此接口上的分組將如何進行路由。這是BSD風格所兼容的。

  metric M

  把選路表中的路由值字段(由選路進程使用)設為M。

  mss M

  把基於此路由之上的連接的TCP最大報文段長度設為M字節。這通常只用於優化選路設置。默認值為536。

  window W

  把基於此路由之上的連接的TCP窗口長度設為W字節。這通常只用於AX.25網絡和不能處理背對背形式的幀的設備。

  irtt I

  把基於此路由之上的TCP連接的初始往返時間設為I毫秒(1-12000)。這通常也只用於AX.25網絡。如果省略此選項,則使用RFC1122的缺省值300ms。

  reject

  設置一條阻塞路由以使一條路由查找失敗。這用於在使用缺省路由前先屏蔽掉一些網絡。但這並不起到防火牆的作用。

  mod, dyn, reinstate

  設置一條動態的或更改過的路由。這些標志通常只由選路進程來設置。這只用於診斷目的,

  dev If

  強制使路由與指定的設備關聯,因為否則內核會自己來試圖檢測相應的設備(通常檢查已存在的路由和加入路由的設備的規格)。在多數正常的網絡上無需使用。

  如果dev If是命令行上最後一個指定的選項,那麼可以省略關鍵字dev,因為它是缺省值。否則路由修改對象(metric - netmask- gw - dev)無關緊要。

  范例 EXAMPLES

  route add -net 127.0.0.0

  加入正常的環回接口項,它使用掩碼255.0.0.0(由目標地址決定了它是A類網絡)並與設備"lo"相關聯(假定該設備先前已由ifconfig(8)正確設置)。

  route add -net 192.56.76.0 netmask 255.255.255.0 dev eth0

  向"eth0"添加一條指向網絡192.56.76.x的路由。其中的C類子網掩碼並不必須,因為192.*是個C類的IP地址。在此關鍵字"dev"可省略。

  route add default gw mango-gw

  加入一條缺省路由(如果無法匹配其它路由則用它)。使用此路由的所有分組將通過網關"mango-gw"進行傳輸。實際使用此路由的設備取決於如何到達"mango-gw" - 先前必須設好到"mango-gw"的靜態路由。

  route add ipx4 sl0

  向SLIP接口添加一條指向"ipx4"的路由(假定"ipx4"是使用SLIP的主機)。

  route add -net 192.57.66.0 netmask 255.255.255.0 gw ipx4

  此命令為先前SLIP接口的網關ipx4添加到網絡"192.57.66.x"的路由。

  route add 224.0.0.0 netmask 240.0.0.0 dev eth0

  此命令為"eth0"設定所有D類地址(用於組播)的路由。這是用於組播內核的正確配置行。

  route add 10.0.0.0 netmask 255.0.0.0 reject

  此命令為私有網絡"10.x.x.x."設置一條阻塞路由。

  輸出信息 OUTPUT

  內核選路表的輸出信息由以下欄目組成:

  Destination

  目標網絡或目標主機。

  Gateway

  網關地址或'*'(如未設)。

  Genmask

  目標網絡的子網掩碼;'255.255.255.255'為主機,'0.0.0.0'為缺省路由。

  Flags

  可能出現的標志有:

  U (route is up) 路由正常

  H (target is a host) 主機路由

  G (use gateway) 使用網關的間接路由

  R (reinstate route for dynamic routing) 為動態選路恢復路由

  D (dynamically installed by daemon or redirect) 該路由由選路進程或重定向動態創建

  M (modified from routing daemon or rederict) 該路由已由選路進程或重定向修改

  ! (reject route) 阻塞路由

  Metric

  通向目標的距離(通常以跳來計算)。新內核不

copyright © 萬盛學電腦網 all rights reserved