18 · Configuring Static Routing設定靜態路由

Verifying Static and Default Route Configuration驗證靜態與預設路由設定

Most routing tables contain a combination of directly connected routes, static routes, and dynamic routes. However, the routing table must first contain the directly connected networks that are used to access the remote networks before any static or dynamic routing can be used.

大多數路由表都包含直接連接路由、靜態路由與動態路由的組合。不過,在使用任何靜態或動態路由之前,路由表必須先包含用來存取遠端網路的直接連接網路。

Verifying Static Route Configuration

驗證靜態路由設定

RouterA# show ip route
Codes: L - local, C - connected, S - static, R - RIP, M - mobile, B - BGP
       D - EIGRP, EX - EIGRP external, O - OSPF, IA - OSPF inter area 
       N1 - OSPF NSSA external type 1, N2 - OSPF NSSA external type 2
<... output omitted ...> 
Gateway of last resort is not set
 
   10.0.0.0/24 is subnetted, 1 subnets
C    10.0.0.0 is directly connected, FastEthernet0/0
   172.16.0.0/24 is subnetted, 2 subnets
S    172.16.1.0/24 [1/0] via 172.16.2.1
C    172.16.2.0/24 is directly connected, Serial0/0/0
L    172.16.2.2/32 is directly connected, Serial0/0/0

To verify static routes in the routing table, examine the routing table with the show ip route command.

若要驗證路由表中的靜態路由,可用 show ip route 指令檢視路由表。

  • The static route includes the network address, subnet mask (in prefix form), and IPv4 address of the next-hop router or exit interface.靜態路由包含網路位址、子網路遮罩(以前綴形式表示),以及下一跳路由器或出口介面的 IPv4 位址。
  • The static route is denoted with the code "S" in the routing table.靜態路由在路由表中以代碼「S」標示。

Routing tables must contain directly connected networks that are used to connect remote networks before static or dynamic routing can be used. This means that a route will not appear in the routing table of the router if the exit interface used for that specific route is disabled (administratively down) or does not have an IP address assigned. The interface state needs to be up/up.

在使用靜態或動態路由之前,路由表必須包含用來連接遠端網路的直接連接網路。這代表如果某條路由所使用的出口介面被停用(管理性關閉)或未指派 IP 位址,該路由就不會出現在路由器的路由表中。介面狀態必須為 up/up。

A static route includes the network address and prefix of the remote network, along with the IPv4 address of the next-hop router or exit interface. Static routes are denoted with the code "S" in the routing table, as shown in the figure.

靜態路由包含遠端網路的網路位址與前綴,以及下一跳路由器或出口介面的 IPv4 位址。靜態路由在路由表中以代碼「S」標示,如圖所示。

If you configure a static route to use an egress interface instead of a next-hop IPv4 address, the routing table entry is changed accordingly.

如果將靜態路由設定為使用出口介面而非下一跳 IPv4 位址,路由表項目會相應改變。

For example, if this default route pointing to the exit interface (Serial0/0/1) is configured on router B:

例如,如果在路由器 B 上設定了這個指向出口介面(Serial0/0/1)的預設路由:

RouterB(config)# ip route 0.0.0.0 0.0.0.0 Serial0/0/1

The corresponding routing table entry of the static route in the routing table of router B is:

路由器 B 路由表中該靜態路由對應的項目為:

RouterB# show ip route
Codes: L - local, C - connected, S - static, R - RIP, M - mobile, B - BGP
       D - EIGRP, EX - EIGRP external, O - OSPF, IA - OSPF inter area 
       N1 - OSPF NSSA external type 1, N2 - OSPF NSSA external type 2 
       E1 - OSPF external type 1, E2 - OSPF external type 2 
       i - IS-IS, su - IS-IS summary, L1 - IS-IS level-1, L2 - IS-IS level-2 
       ia - IS-IS inter area, * - candidate default, U - per-user static route 
       o - ODR, P - periodic downloaded static route, H - NHRP, l - LISP 
       + - replicated route, % - next hop override 

Gateway of last resort is 0.0.0.0 to network 0.0.0.0

S*    0.0.0.0/0 is directly connected, Serial0/0/1
      172.16.0.0/16 is variably subnetted, 4 subnets, 2 masks 
C        172.16.1.0/24 is directly connected, FastEthernet0/0
L        172.16.1.1/32 is directly connected, FastEthernet0/0
C        172.16.2.0/24 is directly connected, Serial0/0/1
L        172.16.2.1/32 is directly connected, Serial0/0/1

Note that the entry in the routing table no longer refers to the next-hop IPv4 address but refers directly to the exit interface. This exit interface is the same one to which the static route was resolved when it used the next-hop IPv4 address. Now that the routing table process has a match for a packet and this static route, it is able to resolve the route to an exit interface in a single lookup.

請注意,路由表中的項目不再參照下一跳 IPv4 位址,而是直接參照出口介面。這個出口介面與先前使用下一跳 IPv4 位址時所解析出的出口介面相同。現在路由表處理程序只需一次查詢,就能將封包與此靜態路由比對,並解析出出口介面。

Verifying Default Route Configuration

驗證預設路由設定

To verify the default route configuration, examine the routing table on router B:

若要驗證預設路由設定,可檢視路由器 B 的路由表:

RouterB# show ip route   
Codes: L - local, C - connected, S - static, R - RIP, M - mobile, B - BGP
       D - EIGRP, EX - EIGRP external, O - OSPF, IA - OSPF inter area 
       N1 - OSPF NSSA external type 1, N2 - OSPF NSSA external type 2 
       E1 - OSPF external type 1, E2 - OSPF external type 2 
       i - IS-IS, su - IS-IS summary, L1 - IS-IS level-1, L2 - IS-IS level-2 
       ia - IS-IS inter area, * - candidate default, U - per-user static route 
       o - ODR, P - periodic downloaded static route, H - NHRP, l - LISP 
       + - replicated route, % - next hop override 

Gateway of last resort is 172.16.2.2 to network 0.0.0.0

S*    0.0.0.0/0 [1/0] via 172.16.2.2
      172.16.0.0/16 is variably subnetted, 4 subnets, 2 masks 
C        172.16.1.0/24 is directly connected, FastEthernet0/0
L        172.16.1.1/32 is directly connected, FastEthernet0/0
C        172.16.2.0/24 is directly connected, Serial0/0/1
L        172.16.2.1/32 is directly connected, Serial0/0/1 

The example in the figure shows the router B routing table after configuration of the default route.

圖中的範例顯示設定預設路由後路由器 B 的路由表。

The asterisk (*) indicates that the route is a candidate default route.

星號(*)表示該路由是候選預設路由。

Before static or dynamic routing can be used, what must a routing table contain?在使用靜態或動態路由之前,路由表必須包含什麼?