拓扑图如下:
配置交换机S3560:
Switch>en
Switch#conf t
Enter configuration commands, one per line. End with CNTL/Z.
Switch(config)#host S3560
S3560(config)#vlan 10
S3560(config-vlan)#vlan 20
S3560(config-vlan)#exit
S3560(config)#int fa0/10
S3560(config-if)#switchport mode access
S3560(config-if)#switchport access vlan 10
S3560(config-if)#exit
S3560(config)#int fa0/20
S3560(config-if)#switchport mode access
S3560(config-if)#switchport access vlan 20
S3560(config-if)#exit
S3560(config)#int vlan 10
S3560(config-if)#
%LINK-5-CHANGED: Interface Vlan10, changed state to up
%LINEPROTO-5-UPDOWN: Line protocol on Interface Vlan10, changed state to up
S3560(config-if)#ip add 192.168.1.1 255.255.255.0
S3560(config-if)#no shut
S3560(config-if)#exit
S3560(config)#int vlan 20
S3560(config-if)#
%LINK-5-CHANGED: Interface Vlan20, changed state to up
S3560(config-if)#ip add 192.168.2.1 255.255.255.0
S3560(config-if)#no shut
S3560(config-if)#end
S3560#
%SYS-5-CONFIG_I: Configured from console by console
S3560#show int vlan 10
Vlan10 is up, line protocol is up
Hardware is CPU Interface, address is 0002.1606.0b68 (bia 0002.1606.0b68)
Internet address is 192.168.1.1/24
MTU 1500 bytes, BW 100000 Kbit, DLY 1000000 usec,
reliability 255/255, txload 1/255, rxload 1/255
Encapsulation ARPA, loopback not set
ARP type: ARPA, ARP Timeout 04:00:00
Last input 21:40:21, output never, output hang never
Last clearing of "show interface" counters never
Input queue: 0/75/0/0 (size/max/drops/flushes); Total output drops: 0
Queueing strategy: fifo
Output queue: 0/40 (size/max)
5 minute input rate 0 bits/sec, 0 packets/sec
5 minute output rate 0 bits/sec, 0 packets/sec
1682 packets input, 530955 bytes, 0 no buffer
Received 0 broadcasts (0 IP multicast)
0 runts, 0 giants, 0 throttles
0 input errors, 0 CRC, 0 frame, 0 overrun, 0 ignored
563859 packets output, 0 bytes, 0 underruns
0 output errors, 23 interface resets
0 output buffer failures, 0 output buffers swapped out
S3560#conf t
Enter configuration commands, one per line. End with CNTL/Z.
S3560(config)#ip routing
!--- 启用三层交换机路由功能
S3560(config)#router rip !--- 运行RIP路由协议
S3560(config-router)#network 192.168.1.0
!--- 发布直连网段
S3560(config-router)#network 192.168.2.0
!--- 发布直连网段
S3560(config-router)#version 2 !--- 更改RIP协议的版本号为版本2
S3560(config-router)#end
S3560#
%SYS-5-CONFIG_I: Configured from console by console
S3560#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
C 192.168.1.0/24 is directly connected, Vlan10
S3560#
配置路由器R1:
Router>en
Router#conf t
Enter configuration commands, one per line. End with CNTL/Z.
Router(config)#host R1
R1(config)#int fa0/0
R1(config-if)#ip add 192.168.2.2 255.255.255.0
R1(config-if)#no shut
R1(config-if)#
%LINK-5-CHANGED: Interface FastEthernet0/0, changed state to up
%LINEPROTO-5-UPDOWN: Line protocol on Interface FastEthernet0/0, changed state to up
R1(config-if)#int fa0/1
R1(config-if)#ip add 192.168.3.1 255.255.255.0
R1(config-if)#no shut
R1(config-if)#
%LINK-5-CHANGED: Interface FastEthernet0/1, changed state to up
R1(config-if)#exit
R1(config)#router rip !--- 因为S3560与R1之间运行的是RIP路由协议,所以要运行RIP路由协议
R1(config-router)#network 192.168.2.0 !--- 发布直连网段
R1(config-router)#version 2 !--- 更改RIP协议的版本号为版本2
R1(config-router)#router ospf 1 !--- 因为R1与R2之间运行的是OSPF路由协议,所以要运行OSPF路由协议
R1(config-router)#network 192.168.3.0 0.0.0.255 area 0 !--- 发布直连网段
R1(config-router)#end
R1#
%SYS-5-CONFIG_I: Configured from console by console
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 192.168.1.0/24 [120/1] via 192.168.2.1, 00:00:23, FastEthernet0/0
C 192.168.2.0/24 is directly connected, FastEthernet0/0
R1#
配置路由器R2:
Router>en
Router#conf t
Enter configuration commands, one per line. End with CNTL/Z.
Router(config)#host R2
R2(config)#int fa0/1
R2(config-if)#ip add 192.168.3.2 255.255.255.0
R2(config-if)#no shut
R2(config-if)#
%LINK-5-CHANGED: Interface FastEthernet0/1, changed state to up
%LINEPROTO-5-UPDOWN: Line protocol on Interface FastEthernet0/1, changed state to up
R2(config-if)#int fa0/0
R2(config-if)#ip add 192.168.4.1 255.255.255.0
R2(config-if)#no shut
R2(config-if)#
%LINK-5-CHANGED: Interface FastEthernet0/0, changed state to up
%LINEPROTO-5-UPDOWN: Line protocol on Interface FastEthernet0/0, changed state to up
R2(config-if)#exit
R2(config)#router ospf 1 !--- 运行OSPF路由协议
R2(config-router)#network 192.168.3.0 0.0.0.255 area 0 !--- 发布直连网段
R2(config-router)#network 192.168.4.0 0.0.0.255 area 0 !--- 发布直连网段
R2(config-router)#end
R2#
%SYS-5-CONFIG_I: Configured from console by console
R2#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
C 192.168.3.0/24 is directly connected, FastEthernet0/1
C 192.168.4.0/24 is directly connected, FastEthernet0/0
R2#
以上指令查看R2的路由表发现只有两条直连网段
在R1路由器上没有进行路由重分布配置之前测试一下网络的通讯状况:
回过头来查看一下路由器R1的路由表
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 192.168.1.0/24 [120/1] via 192.168.2.1, 00:00:09, FastEthernet0/0
C 192.168.2.0/24 is directly connected, FastEthernet0/0
C 192.168.3.0/24 is directly connected, FastEthernet0/1
O 192.168.4.0/24 [110/2] via 192.168.3.2, 00:02:36, FastEthernet0/1
R1#
以上指令查看R1的路由表发现4条路由网段
在路由器R1上ping一下两台计算机,测试一下连通状态
R1#ping 192.168.1.2
Type escape sequence to abort.
Sending 5, 100-byte ICMP Echos to 192.168.1.2, timeout is 2 seconds:
.....
Success rate is 0 percent (0/5)
R1#ping 192.168.4.2
Type escape sequence to abort.
Sending 5, 100-byte ICMP Echos to 192.168.4.2, timeout is 2 seconds:
.....
Success rate is 0 percent (0/5)
R1#
测试结果表明此时R1路由器是可以ping到两台计算机的
但是从计算机PC1上去ping计算机PC2,会显示目标主机不可到达。
PC>ipconfig
FastEthernet0 Connection:(default port)
Link-local IPv6 Address.........: FE80::260:70FF:FE00:C3CC
IP Address......................: 192.168.1.2
Subnet Mask.....................: 255.255.255.0
Default Gateway.................: 192.168.1.1
PC>ping 192.168.4.2
Pinging 192.168.4.2 with 32 bytes of data:
Reply from 192.168.1.1: Destination host unreachable.
Reply from 192.168.1.1: Destination host unreachable.
Reply from 192.168.1.1: Destination host unreachable.
Reply from 192.168.1.1: Destination host unreachable.
Ping statistics for 192.168.4.2:
Packets: Sent = 4, Received = 0, Lost = 4 (100% loss),
PC>
最后回过头来再次查看交换机S3560路由表,发现只有2条路由,所以两台计算机之间不能通讯。
S3560>en
S3560#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
C 192.168.1.0/24 is directly connected, Vlan10
C 192.168.2.0/24 is directly connected, Vlan20
S3560#
在路由器R1上配置路由重分布:
路由器把路由从一个路由域分布到另一个路由域
也就是路由器把路由信息从一个路由进程重分布到另外一个路由进程
R1#conf t
Enter configuration commands, one per line. End with CNTL/Z.
R1(config)#router rip !--- 运行RIP路由协议,进入到RIP路由进程
R1(config-router)#redistribute ospf 1 metric 1 !--- 将RIP路由进程重分布到另外一个路由进程号1
R1(config-router)#exit
R1(config)#router ospf 1 !--- 运行OSPF路由协议,进入到OSPF路由进程号1
R1(config-router)#redistribute rip subnets !--- 将OSPF路由进程重分布到另外一个RIP路由进程,并且对RIP的子网有效
R1(config-router)#end
R1#
%SYS-5-CONFIG_I: Configured from console by console
R1#
在路由器R2上查看路由表信息:
R2>en
R2#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
O E2 192.168.1.0/24 [110/20] via 192.168.3.1, 00:02:24, FastEthernet0/1
O E2 192.168.2.0/24 [110/20] via 192.168.3.1, 00:02:24, FastEthernet0/1
C 192.168.3.0/24 is directly connected, FastEthernet0/1
C 192.168.4.0/24 is directly connected, FastEthernet0/0
R2#
在交换机上S3560查看路由表信息:
S3560>en
S3560#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
C 192.168.1.0/24 is directly connected, Vlan10
C 192.168.2.0/24 is directly connected, Vlan20
R 192.168.3.0/24 [120/1] via 192.168.2.2, 00:00:19, Vlan20
R 192.168.4.0/24 [120/1] via 192.168.2.2, 00:00:19, Vlan20
S3560#
测试跨路由协议网络之间的通讯:
PC>ipconfig
FastEthernet0 Connection:(default port)
Link-local IPv6 Address.........: FE80::260:70FF:FE00:C3CC
IP Address......................: 192.168.1.2
Subnet Mask.....................: 255.255.255.0
Default Gateway.................: 192.168.1.1
PC>ping 192.168.4.2
Pinging 192.168.4.2 with 32 bytes of data:
Reply from 192.168.4.2: bytes=32 time=0ms TTL=255
Reply from 192.168.4.2: bytes=32 time=0ms TTL=255
Reply from 192.168.4.2: bytes=32 time=0ms TTL=255
Reply from 192.168.4.2: bytes=32 time=0ms TTL=255
Ping statistics for 192.168.4.2:
Packets: Sent = 4, Received = 4, Lost = 0 (0% loss),
Approximate round trip times in milli-seconds:
Minimum = 0ms, Maximum = 0ms, Average = 0ms
PC>
测试结果表明路由重分布配置完全正确。