靜態路由

靜態路由

靜態路由介紹

路由器在轉發數據時,要先在路由表(routing table)中查找相應的路由。路由器有

這麼三種途徑建立路由:

1直連網絡:路由器自動添加和自己直接連接的網絡的路由

2靜態路由:管理員手動輸入到路由器的路由

3動態路由:由路由協議(routing protocol)動態建立的路由

靜態路由的缺點是不能動態反映網絡拓撲,當網絡拓撲發生變化時,管理員就必須手工

改變路由表;然而靜態路不會佔用路由器太多的CPU RAM 資源,也不佔用線路的帶寬。如
果出於安全的考慮想隱藏網絡的某些部分或者管理員想控制數據轉發路徑,也會使用靜態路

由。在一個小而簡單的網絡中,也常使用靜態路由,因爲配置靜態路由會更爲簡捷。

使用到的命令如下:

ip route           配置靜態路由

show ip route      查看路由表

ip route 使用如下

ip route 目的網絡 掩碼 { 網關地址 | 接口 }

例子:ip route 192.168.1.0 255.255.255.0 s2/0(接口)

例子:ip route 192.168.1.0 255.255.255.0 12.12.12.2(網關地址)

Show ip route 使用如下

R1#show ip route

Codes: C - connected, S - static, I - IGRP, 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, E - EGP

i - IS-IS, 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
Gateway of last resort is not set

R 172.16.0.0/16 [120/2] via 10.1.0.2, 00:00:21, Serial0/0

[120/2] via 10.3.0.2, 00:00:06, Serial0/1

10.0.0.0/16 is subnetted, 4 subnets

R 10.2.0.0 [120/1] via 10.1.0.2, 00:00:21, Serial0/0

C 10.3.0.0 is directly connected, Serial0/1

C 10.1.0.0 is directly connected, Serial0/0

R 10.4.0.0 [120/1] via 10.3.0.2, 00:00:06, Serial0/1

C 192.168.1.0/24 is directly connected, FastEthernet0/0

在輸出中,首先顯示路由條目各種類型的的簡寫,如:“C”爲直連網絡,“S”爲靜態路由。

以上面帶有下劃的路由爲例,“R”表示這條路由是“RIP”協議學習得到的;“10.2.0.0”是

目的網絡;“[120/1]”是管理距離(Administrative Distance AD/ 度量值(Metric);

via 10.1.0.2”是指到達目的網絡的下一跳路由器的IP 地址;“00:00:21”是指路由器最

近一次得知路由到現在的時間;“Serials 0/0”是指到達下一跳應從哪個端口出去。

實驗1:靜態路由

實驗步驟

我們要使得1.1.1.0/242.2.2.0/243.3.3.0/24 網絡之間能夠互相通信。

步驟1:在各路由器上配置IP 地址、保證直連鏈路的連通性

R1(config)#int loopback0

R1(config-if)#ip address 1.1.1.1 255.255.255.0

R1(config)#int s2/0

R1(config-if)#ip address 192.168.12.1 255.255.255.0

R1(config-if)#no shutdown

R2(config)#int loopback0

R2(config-if)#ip address 2.2.2.2 255.255.255.0

R2(config)#int s2/0

R2(config-if)#clock rate 128000

R2(config-if)#ip address 192.168.12.2 255.255.255.0

R2(config-if)#no shutdown

R2(config)#int s2/1

R2(config-if)#clock rate 128000

R2(config-if)#ip address 192.168.23.2 255.255.255.0

R2(config-if)#no shutdown

R3(config)#int loopback0

R3(config-if)#ip address 3.3.3.3 255.255.255.0

R3(config)#int s2/1

R3(config-if)#ip address 192.168.23.3 255.255.255.0

R3(config-if)#no shutdown

2) 步驟2R1 上配置靜態路由

R1(config)#ip route 2.2.2.0 255.255.255.0 s2/0

//下一跳爲接口形式,s2/0 是點對點的鏈路,注意應該是R1 上的s2/0 接口

R1(config)#ip route 3.3.3.0 255.255.255.0 192.168.12.2

//下一跳爲IP 地址形式,192.168.12.2 R2 上的IP 地址

3) 步驟3R2 上配置靜態路由

R2(config)#ip route 1.1.1.0 255.255.255.0 s2/0

R2(config)#ip route 3.3.3.0 255.255.255.0 s2/1

4) 步驟4R3 上配置靜態路由

R3(config)#ip route 1.1.1.0 255.255.255.0 s2/1

R3(config)#ip route 2.2.2.0 255.255.255.0 s2/1

實驗調試

1) 在R1R2R3 上查看路由表

R1#show ip route

Codes: 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

Gateway of last resort is not set

C 192.168.12.0/24 is directly connected, Serial2/0

1.0.0.0/24 is subnetted, 1 subnets

C 1.1.1.0 is directly connected, Loopback0

2.0.0.0/24 is subnetted, 1 subnets

S 2.2.2.0 is directly connected, Serial2/0

3.0.0.0/24 is subnetted, 1 subnets

S 3.3.3.0 [1/0] via 192.168.12.2

R2#show ip route

Codes: 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

Gateway of last resort is not set

C 192.168.12.0/24 is directly connected, Serial2/0

1.0.0.0/24 is subnetted, 1 subnets

S 1.1.1.0 is directly connected, Serial2/0

2.0.0.0/24 is subnetted, 1 subnets

C 2.2.2.0 is directly connected, Loopback0

3.0.0.0/24 is subnetted, 1 subnets

S 3.3.3.0 is directly connected, Serial2/1

C 192.168.23.0/24 is directly connected, Serial0/0/1

R3#show ip route

Codes: 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

Gateway of last resort is not set

1.0.0.0/24 is subnetted, 1 subnets

S 1.1.1.0 is directly connected, Serial2/1

2.0.0.0/24 is subnetted, 1 subnets

S 2.2.2.0 is directly connected, Serial2/1

3.0.0.0/24 is subnetted, 1 subnets

C 3.3.3.0 is directly connected, Loopback0

C 192.168.23.0/24 is directly connected, Serial2/1

R2#ping 1.1.1.1 source loopback 0

R2#ping 3.3.3.3 source loopback 0

//R2 loopback0 應該可以ping R1 R3 lopback0 接口。

R3#ping 1.1.1.1 source loopback 0

R3#ping 2.2.2.2 source loopback 0

//R3 loopback0 也應該可以ping R1 R2 lopback0 接口。

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章