静态路由<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

静态路由介绍

路由器在转发数据时,要先在路由表(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 <?xml:namespace prefix = st1 ns = "urn:schemas-microsoft-com:office:smarttags" />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 接口。