静态路由与默认配置
A.实验网络拓扑:
建立如图12.2所示的网络,用串口连接DTE和DCE电缆把各路由器两两连接
起来。
图中所有IP地址的子网掩码假设均使用 255.255.255.0,要求通过
配置静态路由,使任意网段的两台计算机之间都能连通。
B.静态路由配置步骤:
(1) 配置路由器名、局域网和广域网口的IP地址,配置计算机的IP地址
注意在实验室环境下必须在DCE电缆一端的路由器端口上配置时钟,本实验
需要在两个端口上配置。
在软件Boson模拟路由器环境下也是如此(比如假定
R3为DCE路由器,在其S0和S1口上配置时钟)。
否则广域网端口和协议状态都会
是关闭的。
请读者自己完成配置。
(2)配置静态路由
图12.2 配置静态路由的网络
配置路由器R1的静态路由:
r1(config)#ip route 11.1.2.0 255.255.255.0 11.1.1.2 //注意这行
r1(config)#ip route 192.168.2.0 255.255.255.0 11.1.1.2
r1(config)#ip route 192.168.3.0 255.255.255.0 11.1.1.2
配置路由器R2的静态路由:
r2(config)#ip route 11.1.1.0 255.255.255.0 11.1.2.2 //注意这行
r2(config)#ip route 192.168.1.0 255.255.255.0 11.1.2.2
r2(config)#ip route 192.168.3.0 255.255.255.0 11.1.2.2
配置路由器R3的静态路由:
r3(config)#ip route 192.168.1.0 255.255.255.0 11.1.1.1
r3(config)#ip route 192.168.2.0 255.255.255.0 11.1.2.1
配置默认网关:
计算机a的默认网关为192.168.1.1;
计算机b的默认网关为192.168.2.1;
计算机c的默认网关为192.168.3.1。
C.测试静态路由配置:
(1) 特权模式下使用show ip route命令查看路由表;
(2) 从任一计算机ping其他计算机的IP地址,应能ping通。
通过查看路由表可以发现,1)静态路由项由“S”标记,目标网络和下一跳地址都是配置时候指定的参数;2)直接连接标记“C”,连接在同一路由器各接口上的不同网络,路由器能自动识别。
即是说,不需指定路由,同一路由器上所连的不同网络的主机之间是可以相互访问的;
3)特别注意,凡是不在同一路由器接口上的网络,都要配置路由,如上R1和R2静态路由配置的第一行。
D.默认路由配置
把在上面的配置中,配置路由器R1的这两行:
router(config)#ip route 192.168.2.0 255.255.255.0 1 1.1.1.2 router(config)#ip route 192.168.3.0 255.255.255.0 11.1.1.2
用如下的默认路由配置来代替:
router(config)#ip route 0.0.0.0 0.0.0.0 11.1.1.2。
配置路由器R2的这三行:
router(config)#ip route 11.1.1.0 255.255.255.0 11.1.2.2
router(config)#ip route 192.168.1.0 255.255.255.0 11.1.2.2 router(config)#ip route 192.168.3.0 255.255.255.0 11.1.2.2
可用如下的默认路由配置来取代:
router2(config)#ip route 0.0.0.0 0.0.0.0 11.1.2.2
注意,路由器R3的静态路由就不要用默认路由配置去取代了,也就是至少要保留一个静态路由配置。
若都配置,静态路由和默认路由同时作为路由项添加到路由器中。
R1的初始配置
R3的部分初始配置
R1在R3与之相连端口配置好后的状态【打开】
R1的初始路由表
R3与R2相连端口的配置及初始路由表
R2的初始配置及路由表
R3与R2相连的端口在R2配置好后的状态
PC1
PC2的初始配置
PC3的初始配置及初步测试
R1静态路由配置
R2静态路由配置
R3静态路由配置
R3(config-if)#int s1
R3(config-if)#ip address 11.1.2.2 255.255.255.0
R3(config-if)#clock rate 50000
R3(config-if)#no shut
%LINK-3-UPDOWN: Interface Serial1, changed state to up
%LINK-3-UPDOWN: Interface Serial1, changed state to down
%LINEPROTO-5-UPDOWN: Line protocol on Interface Serial1, changed state to down R3(config-if)#end
R3#sh 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
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, * - candidate default
U - per-user static route
Gateway of last resort is not set
C 192.168.3.0 is directly connected, Ethernet0
11.0.0.0/24 is subnetted, 2 subnets
C 11.1.1.0 is directly connected, Serial0
C 11.1.2.0 is directly connected, Serial1
R3#config
Configuring from terminal, memory, or network [terminal]?
Enter configuration commands, one per line. End with CNTL/Z.
R3(config)#ip route 192.168.2.0 255.255.255.0 11.1.2.1
R3(config)#ip route 192.168.1.0 255.255.255.0 11.1.1.1
R3(config)#end
R3#sh 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
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, * - candidate default
U - per-user static route
Gateway of last resort is not set
C 192.168.3.0 is directly connected, Ethernet0
11.0.0.0/24 is subnetted, 2 subnets
C 11.1.1.0 is directly connected, Serial0
C 11.1.2.0 is directly connected, Serial1
S 192.168.1.0 [1/0] via 11.1.1.2
S 192.168.2.0 [1/0] via 11.1.2.2
PC1测试结果
PC2测试结果
PC3测试结果。