路由器:路由器是一种典型的网络连接设备,用来进行路由选择和报文转发。
路由器与它直接相连的网络的跳数为0,通过一台路由器可达的网络的跳数为1.
      路由协议:路由器之间维护路由表的规则,用以发现路由,生成路由表,并引导报文转发。
      路由器决策路由关键是路由表,转发报文关键是FIB表(Forwarding Information Base)表。每个路由器至少维护着一张路由表和一张FIB表。
      路由表中通常包含:
链路层协议发现的路由(接口路由或直连路由)
网络管理员人工配置的静态路由
动态路由协议主动发现的路由
 
FIB表指明分组到某网段或某主机应通过路由器的物理接口或逻辑接口发送,到达计划路径的下一个路由器,当然也可以不经过路由器直达直接相连网络中的主机。
一台路由器保存着一张本地核心(管理)路由表,路由协议也维护着自己的路由表。即
本地核心路由表
      用来保护协议路由和决策优选路由,负责把优选路由下发到FIB,由FIB负责指导转发。具体通过display ip routing-table,查看
各种路由协议的优先级和度量值选取路由。
协议路由表
     即协议主动发现的路由。路由协议可以引入并发布其它协议生成的路由。
例如:查看路由表
< quidway>dis ip routing-table
Route Flags: R - relay, D - download to fib
------------------------------------------------------------------------------
Routing Tables: Public
        Destinations : 20       Routes : 20
Destination/Mask    Proto  Pre  Cost     Flags NextHop         Interface
  10.201.54.215/32  Static 60   0          RD  10.201.81.19    GigabitEthernet1/0/23
  10.201.57.128/27  Static 60   0          RD  10.201.81.19    GigabitEthernet1/0/23
    10.201.62.0/26  Static 60   0          RD  10.201.81.19    GigabitEthernet1/0/23
    10.201.63.4/32  Static 60   0          RD  10.201.81.19    GigabitEthernet1/0/23
   10.201.81.16/29  Direct 0    0           D  10.201.81.20    GigabitEthernet1/0/23
   10.201.81.20/32  Direct 0    0           D  127.0.0.1       InLoopBack0
   10.201.81.23/32  Direct 0    0           D  127.0.0.1       InLoopBack0
   10.201.81.24/30  Direct 0    0           D  10.201.81.25    Vlanif30
   10.201.81.25/32  Direct 0    0           D  127.0.0.1       InLoopBack0
   10.201.81.26/32  Direct 0    0           D  10.201.81.26    Vlanif30
   10.201.81.27/32  Direct 0    0           D  127.0.0.1       InLoopBack0
  10.201.93.241/32  Direct 0    0           D  127.0.0.1       InLoopBack0
  10.201.93.242/32  Static 60   0          RD  10.201.81.26    Vlanif30
      127.0.0.0/8   Direct 0    0           D  127.0.0.1       InLoopBack0
      127.0.0.1/32  Direct 0    0           D  127.0.0.1       InLoopBack0
127.255.255.255/32  Direct 0    0           D  127.0.0.1       InLoopBack0
      138.1.1.1/32  Static 60   0          RD  10.201.81.19    GigabitEthernet1/0/23
      138.2.1.1/32  Static 60   0          RD  10.201.81.19    GigabitEthernet1/0/23
      138.7.1.1/32  Static 60   0          RD  10.201.81.19    GigabitEthernet1/0/23
255.255.255.255/32  Direct 0    0           D  127.0.0.1       InLoopBack0
解释:
Route Flags:路由标记,R表示该路由是迭代路由,D表示该路由下发到FIB表。
Routing Tables:说明路由表是公网路由表还是私网路由表。
Destinations:目的网络或者主机的总数。
Routes:路由总数。
Destination/Mask:目的地址和子网掩码。
Proto:协议,说明是直连、静态还是动态路由。
Pre:本条路由加入路由表的优先级。它包括前面所讲的所有路由,加上优先级,优先级高(数值小)的便是当前的最佳路由。各协议的路由优先级如下表:
表1-1 路由协议及缺省时的路由优先级
路由协议或路由种类 相应路由的优先级
DIRECT                              0
OSPF                                10
IS-IS                                 15
STATIC                             60
RIP                                  100
OSPF ASE                        150
OSPF NSSA                      150
IBGP                                 255
EBGP                                255
注意:除直连路由(DIRECT)外,各种路由协议的优先级都可由用户手工进行配置。
Cost:路由开销。当到达同一目的地的多条路由具有相同的优先级时,它就派上用场了。路由开销小的将成为当前的最佳路由。
提醒:Pre用于不同路由协议间路由优先级的比较,cost即用于同一种路由协议内部不同路由优先级的比较。
Flags:路由标记,即路由表头的Route Flags,表示路由信息所处状态。
NextHop:下一跳地址。说明IP包经过的下一个路由器。
Interface:下一跳可达的出接口。说明IP包将从下一个路由器哪一个接口转发。
不过上面的路由表只是路由表简表,它只显示激活的路由,而完整的路由表还包括未激活的路由。可以通过命令display ip routing-table verbose查看。
例如:
dis ip routing-table verbose
Route Flags: R - relay, D - download to fib
------------------------------------------------------------------------------
Routing Table : Public
        Destinations : 20       Routes : 27

Destination: 10.201.54.215/32
     Protocol: Static          Process ID: 0
   Preference: 60                    Cost: 0
      NextHop: 10.201.81.19     Neighbour: 0.0.0.0
        State: Active Adv GotQ        Age: 8d05h16m34s
          Tag: 0                 Priority: 0
        Label: NULL               QoSInfo: 0x0
 RelayNextHop: 0.0.0.0          Interface: GigabitEthernet1/0/23
     TunnelID: 0x0                  Flags: RD
Destination: 10.201.54.215/32
     Protocol: Static          Process ID: 0
   Preference: 100                   Cost: 0
      NextHop: 10.201.81.26     Neighbour: 0.0.0.0
        State: Inactive Adv GotQ      Age: 8d05h16m34s
          Tag: 0                 Priority: 0
        Label: NULL               QoSInfo: 0x0
 RelayNextHop: 0.0.0.0          Interface: Vlanif30
     TunnelID: 0x0                  Flags: R
Destination: 10.201.57.128/27
     Protocol: Static          Process ID: 0
   Preference: 60                    Cost: 0
      NextHop: 10.201.81.19     Neighbour: 0.0.0.0
        State: Active Adv GotQ        Age: 138d23h14m06s
          Tag: 0                 Priority: 0
        Label: NULL               QoSInfo: 0x0
 RelayNextHop: 0.0.0.0          Interface: GigabitEthernet1/0/23
     TunnelID: 0x0                  Flags: RD
Destination: 10.201.57.128/27
     Protocol: Static          Process ID: 0
   Preference: 100                   Cost: 0
      NextHop: 10.201.81.26     Neighbour: 0.0.0.0
        State: Inactive Adv GotQ      Age: 138d23h14m06s
          Tag: 0                 Priority: 0
        Label: NULL               QoSInfo: 0x0
 RelayNextHop: 0.0.0.0          Interface: Vlanif30
     TunnelID: 0x0                  Flags: R
Destination: 10.201.62.0/26              
     Protocol: Static          Process ID: 0
   Preference: 60                    Cost: 0
      NextHop: 10.201.81.19     Neighbour: 0.0.0.0
        State: Active Adv GotQ        Age: 138d23h14m05s
          Tag: 0                 Priority: 0
        Label: NULL               QoSInfo: 0x0
 RelayNextHop: 0.0.0.0          Interface: GigabitEthernet1/0/23
     TunnelID: 0x0                  Flags: RD
Destination: 10.201.62.0/26
     Protocol: Static          Process ID: 0
   Preference: 100                   Cost: 0
      NextHop: 10.201.81.26     Neighbour: 0.0.0.0
        State: Inactive Adv GotQ      Age: 138d23h14m08s
          Tag: 0                 Priority: 0
        Label: NULL               QoSInfo: 0x0
 RelayNextHop: 0.0.0.0          Interface: Vlanif30
     TunnelID: 0x0                  Flags: R
Destination: 10.201.63.4/32
     Protocol: Static          Process ID: 0
   Preference: 60                    Cost: 0
      NextHop: 10.201.81.19     Neighbour: 0.0.0.0
        State: Active Adv GotQ        Age: 140d23h35m45s
          Tag: 0                 Priority: 0
        Label: NULL               QoSInfo: 0x0
 RelayNextHop: 0.0.0.0          Interface: GigabitEthernet1/0/23
     TunnelID: 0x0                  Flags: RD
Destination: 10.201.63.4/32
     Protocol: Static          Process ID: 0
   Preference: 100                   Cost: 0
      NextHop: 10.201.81.26     Neighbour: 0.0.0.0
        State: Inactive Adv GotQ      Age: 140d23h28m08s
          Tag: 0                 Priority: 0
        Label: NULL               QoSInfo: 0x0
 RelayNextHop: 0.0.0.0          Interface: Vlanif30
     TunnelID: 0x0                  Flags: R
Destination: 10.201.81.16/29
     Protocol: Direct          Process ID: 0
   Preference: 0                     Cost: 0
      NextHop: 10.201.81.20     Neighbour: 0.0.0.0
        State: Active Adv             Age: 140d23h35m45s
          Tag: 0                 Priority: 0
        Label: NULL               QoSInfo: 0x0
 RelayNextHop: 0.0.0.0          Interface: GigabitEthernet1/0/23
     TunnelID: 0x0                  Flags:  D
Destination: 10.201.81.20/32
     Protocol: Direct          Process ID: 0
   Preference: 0                     Cost: 0
      NextHop: 127.0.0.1        Neighbour: 0.0.0.0
        State: Active NoAdv           Age: 140d23h35m46s
          Tag: 0                 Priority: 0
        Label: NULL               QoSInfo: 0x0
 RelayNextHop: 0.0.0.0          Interface: InLoopBack0
     TunnelID: 0x0                  Flags:  D
Destination: 10.201.81.23/32
     Protocol: Direct          Process ID: 0
   Preference: 0                     Cost: 0
      NextHop: 127.0.0.1        Neighbour: 0.0.0.0
        State: Active NoAdv           Age: 140d23h35m46s
          Tag: 0                 Priority: 0
        Label: NULL               QoSInfo: 0x0
 RelayNextHop: 0.0.0.0          Interface: InLoopBack0
     TunnelID: 0x0                  Flags:  D
                                         
Destination: 10.201.81.24/30
     Protocol: Direct          Process ID: 0
   Preference: 0                     Cost: 0
      NextHop: 10.201.81.25     Neighbour: 0.0.0.0
        State: Active Adv             Age: 140d23h28m09s
          Tag: 0                 Priority: 0
        Label: NULL               QoSInfo: 0x0
 RelayNextHop: 0.0.0.0          Interface: Vlanif30
     TunnelID: 0x0                  Flags:  D
Destination: 10.201.81.25/32
     Protocol: Direct          Process ID: 0
   Preference: 0                     Cost: 0
      NextHop: 127.0.0.1        Neighbour: 0.0.0.0
        State: Active NoAdv           Age: 140d23h28m09s
          Tag: 0                 Priority: 0
        Label: NULL               QoSInfo: 0x0
 RelayNextHop: 0.0.0.0          Interface: InLoopBack0
     TunnelID: 0x0                  Flags:  D
Destination: 10.201.81.26/32
     Protocol: Direct          Process ID: 0
   Preference: 0                     Cost: 0
      NextHop: 10.201.81.26     Neighbour: 0.0.0.0
        State: Active NoAdv           Age: 140d23h28m05s
          Tag: 0                 Priority: 0
        Label: NULL               QoSInfo: 0x0
 RelayNextHop: 0.0.0.0          Interface: Vlanif30
     TunnelID: 0x0                  Flags:  D
Destination: 10.201.81.27/32
     Protocol: Direct          Process ID: 0
   Preference: 0                     Cost: 0
      NextHop: 127.0.0.1        Neighbour: 0.0.0.0
        State: Active NoAdv           Age: 140d23h28m54s
          Tag: 0                 Priority: 0
        Label: NULL               QoSInfo: 0x0
 RelayNextHop: 0.0.0.0          Interface: InLoopBack0
     TunnelID: 0x0                  Flags:  D
Destination: 10.201.93.241/32
     Protocol: Direct          Process ID: 0
   Preference: 0                     Cost: 0
      NextHop: 127.0.0.1        Neighbour: 0.0.0.0
        State: Active Adv             Age: 140d23h42m01s
          Tag: 0                 Priority: 0
        Label: NULL               QoSInfo: 0x0
 RelayNextHop: 0.0.0.0          Interface: InLoopBack0
     TunnelID: 0x0                  Flags:  D
Destination: 10.201.93.242/32
     Protocol: Static          Process ID: 0
   Preference: 60                    Cost: 0
      NextHop: 10.201.81.26     Neighbour: 0.0.0.0
        State: Active Adv GotQ        Age: 138d23h13m26s
          Tag: 0                 Priority: 0
        Label: NULL               QoSInfo: 0x0
 RelayNextHop: 0.0.0.0          Interface: Vlanif30
     TunnelID: 0x0                  Flags: RD
Destination: 127.0.0.0/8
     Protocol: Direct          Process ID: 0
   Preference: 0                     Cost: 0
      NextHop: 127.0.0.1        Neighbour: 0.0.0.0
        State: Active NoAdv           Age: 140d23h42m07s
          Tag: 0                 Priority: 0
        Label: NULL               QoSInfo: 0x0
 RelayNextHop: 0.0.0.0          Interface: InLoopBack0
     TunnelID: 0x0                  Flags:  D
Destination: 127.0.0.1/32
     Protocol: Direct          Process ID: 0
   Preference: 0                     Cost: 0
      NextHop: 127.0.0.1        Neighbour: 0.0.0.0
        State: Active NoAdv           Age: 140d23h42m10s
          Tag: 0                 Priority: 0
        Label: NULL               QoSInfo: 0x0
 RelayNextHop: 0.0.0.0          Interface: InLoopBack0
     TunnelID: 0x0                  Flags:  D
Destination: 127.255.255.255/32
     Protocol: Direct          Process ID: 0
   Preference: 0                     Cost: 0
      NextHop: 127.0.0.1        Neighbour: 0.0.0.0
        State: Active NoAdv           Age: 140d23h42m10s
          Tag: 0                 Priority: 0
        Label: NULL               QoSInfo: 0x0
 RelayNextHop: 0.0.0.0          Interface: InLoopBack0
     TunnelID: 0x0                  Flags:  D
Destination: 138.1.1.1/32
     Protocol: Static          Process ID: 0
   Preference: 60                    Cost: 0
      NextHop: 10.201.81.19     Neighbour: 0.0.0.0
        State: Active Adv GotQ        Age: 140d23h36m37s
          Tag: 0                 Priority: 0
        Label: NULL               QoSInfo: 0x0
 RelayNextHop: 0.0.0.0          Interface: GigabitEthernet1/0/23
     TunnelID: 0x0                  Flags: RD
Destination: 138.1.1.1/32
     Protocol: Static          Process ID: 0
   Preference: 100                   Cost: 0
      NextHop: 10.201.81.26     Neighbour: 0.0.0.0
        State: Inactive Adv GotQ      Age: 140d23h29m01s
          Tag: 0                 Priority: 0
        Label: NULL               QoSInfo: 0x0
 RelayNextHop: 0.0.0.0          Interface: Vlanif30
     TunnelID: 0x0                  Flags: R
Destination: 138.2.1.1/32
     Protocol: Static          Process ID: 0
   Preference: 60                    Cost: 0
      NextHop: 10.201.81.19     Neighbour: 0.0.0.0
        State: Active Adv GotQ        Age: 140d23h36m38s
          Tag: 0                 Priority: 0
        Label: NULL               QoSInfo: 0x0
 RelayNextHop: 0.0.0.0          Interface: GigabitEthernet1/0/23
     TunnelID: 0x0                  Flags: RD
Destination: 138.2.1.1/32
     Protocol: Static          Process ID: 0
   Preference: 100                   Cost: 0
      NextHop: 10.201.81.26     Neighbour: 0.0.0.0
        State: Inactive Adv GotQ      Age: 140d23h29m01s
          Tag: 0                 Priority: 0
        Label: NULL               QoSInfo: 0x0
 RelayNextHop: 0.0.0.0          Interface: Vlanif30
     TunnelID: 0x0                  Flags: R
Destination: 138.7.1.1/32
     Protocol: Static          Process ID: 0
   Preference: 60                    Cost: 0
      NextHop: 10.201.81.19     Neighbour: 0.0.0.0
        State: Active Adv GotQ        Age: 140d23h36m38s
          Tag: 0                 Priority: 0
        Label: NULL               QoSInfo: 0x0
 RelayNextHop: 0.0.0.0          Interface: GigabitEthernet1/0/23
     TunnelID: 0x0                  Flags: RD
Destination: 138.7.1.1/32
     Protocol: Static          Process ID: 0
   Preference: 100                   Cost: 0
      NextHop: 10.201.81.26     Neighbour: 0.0.0.0
        State: Inactive Adv GotQ      Age: 140d23h29m01s
          Tag: 0                 Priority: 0
        Label: NULL               QoSInfo: 0x0
 RelayNextHop: 0.0.0.0          Interface: Vlanif30
     TunnelID: 0x0                  Flags: R
Destination: 255.255.255.255/32
     Protocol: Direct          Process ID: 0
   Preference: 0                     Cost: 0
      NextHop: 127.0.0.1        Neighbour: 0.0.0.0
        State: Active NoAdv           Age: 140d23h42m11s
          Tag: 0                 Priority: 0
        Label: NULL               QoSInfo: 0x0
 RelayNextHop: 0.0.0.0          Interface: InLoopBack0
     TunnelID: 0x0                  Flags:  D
解释:
注意这里的Routes比刚才的多了,是因为将未激活的路由条数加进来了。此外,还多出其它一些项目:
Process ID:路由协议的进程号。
Neighbour:邻居。
State:路由的状态,包括有
Active:激活的路由
Invalid:无效的路由
Inactive:非激活的路由
NoAdv:不充许发布的路由
Adv:可以发布的路由
Del:即将要删除的路由
GotQ:迭代到下一跳及出接口的路由,或者迭代到隧道的路由
WatiQ:没有迭代到下一跳及出接口的路由,或者迭代到隧道的路由
Stale:带Stale标记的路由,在GR中使用
Age:路由有存活时间。
Tag:路由管理标识。
Priority:优先级。
Label:MPLS分配的标签。
QoSInfo:QoS信息。
RelayNextHop:迭代下一跳。
Interface:迭代出接口。
Tunnel ID:隧道ID。
SecTunnel ID:备份隧道ID。
BkNextHop:备份出接口。
Route of Packet Load-balance:显示逐包软转发查询时所使用的路由的信息
前面说过,华为路由器还有一个FIB负责指引报文转发。路由表选择出路由后,路由表就会将已经激活的路由下发到FIB中。由于FIB表进行转发。
FIB表根据匹配最长匹配原则。即查找FIB表时,报文的目的地址和FIB中各表项的掩码进行“逻辑与”运算,将得到的地址与FIB表项中的网络地址匹配,并选择最长匹配的FIB表项进行报文转发。

 
 附注:关于迭代路由的解释(摘抄网上的)
我对路由迭代的理解:
      通常路由的下一跳是路由器某个接口的同网段地址,但是存在这样的情形:
     A ____B______D___E
       \____C_____/

    路由器A、B、C、D间运行IGP路由协议,而路由器E不参与,为了使A能到达E,需要在A上配置静态路由,A可以经由B或者C到达D再到达E,那么我们可以在A上配置到E的2条路由:
      E    下一跳B      
      E    下一跳C  (备用)
    
     当A到B的链路出现问题
     A __X_B______D___E
       \____C_____/
   
    下一跳到C的路由起作用了,可以正常工作。
    但是如果是B-D的链路出问题怎么办呢?看下图:
     A ____B__X___D___E
       \____C_____/
      A并不知道这一点,仍然将到E的报文向B转发结果当然是不通了。
      解决的办法就是在A上配置迭代路由
      E    下一跳D
     
      A到E具体走B还是走C取决于A到D是走B还是走C,
      而A到D具体是走B还是走C则由IGP路由协议动态算出,这样无论是A-B的链路出现问题还是B-D的链路出现问题都不会影响A-E的转发。
      有人要问为什么不让E也参与IGP不使用静态路由不就不会出类似问题么?
      1、在真实的组网环境中很可能A\B\C\D属于同一个管理区域,E属于另一个管理区域,互相之间不允许运行IGP路由协议。
      2、A-D间可能采用了某种隧道技术,可能B/C根本就不知道E的存在,使用IGP路由协议也不能解决。