一、實驗目標
- 掌握綜合路由的配置方法;
- 掌握查看通過路由重分布學習產生的路由;
- 熟悉廣域網線纜的連接方式;
二、實驗背景
假設某公司通過一台三層交換機連到公司出口路由器R1上,路由器R1再和公司外的另一台路由器R2連接。三層與R1間運行RIPv2路由協議,R1與R2間運行OSPF路由協議。現要做適當配置,實現公司內部主機與公司外部主機之間的相互通信。
三、技術原理
為了支持本設備能夠運行多個路由協議進程,系統軟件提供路由信息從一個路由進程重分布到另外一個路由進程的功能。比如你可以將OSPF路由域的路由重新分布后通告RIP路由域中,也可以將RIP路由域的路由重新分布后通告到OSPF路由域中。路由的相互重分布可以在所有的IP路由協議之間進行。
要把路由從一個路由域分布到另一個路由域,並且進行控制路由重分布,在路由進程配置模式中執行以下命令:
redistribute protocol [metric metric] [metric-type metric-type] [match internal | external type | nssa-external type] [tag tag] [route-map route-map-name] [subnets]
四、實驗步驟
實驗拓撲
1、PC與交換機間用直連線連接;PC與路由、路由與路由之間用交叉線連接。
2、在三層上划分2個VLAN,運行RIPv2協議;R2運行OSPF協議;
3、在路由器R1上左側配置RIPv2路由協議;右側配置OSPF協議;
4、在R1路由器進程中引入外部路由,進行路由重分布;
5、將PC1、PC2主機默認網關分別設置為與直連網絡設備接口IP地址;
6、驗證PC1、PC2主機之間可以互相通信;
S3560:
Switch>en
Switch#conf t
Enter configuration commands, one per line. End with CNTL/Z.
Switch(config)#hostname S3560
S3560(config)#vlan 10
S3560(config-vlan)#exit
S3560(config)#vlan 20
S3560(config-vlan)#exit
S3560(config)#interface fa0/10
S3560(config-if)#switchport access vlan 10
S3560(config-if)#exit
S3560(config)#interface fa0/20
S3560(config-if)#switchport access vlan 20
S3560(config-if)#exit
S3560(config)#interface 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 address 192.168.1.1 255.255.255.0 //配置vlan 10虛接口IP地址
S3560(config-if)#exit
S3560(config)#interface vlan 20
%LINK-5-CHANGED: Interface Vlan20, changed state to upS3560(config-if)#
S3560(config-if)#ip address 192.168.2.1 255.255.255.0 //配置vlan 20虛接口IP地址
S3560(config-if)#no shut
S3560(config-if)#exit
S3560(config)#router rip //配置RIPv2協議
S3560(config-router)#network 192.168.1.0
S3560(config-router)#network 192.168.2.0
S3560(config-router)#version 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#
S3560#
S3560#
%LINK-5-CHANGED: Interface FastEthernet0/20, changed state to up
%LINEPROTO-5-UPDOWN: Line protocol on Interface FastEthernet0/20, changed state to up
%LINEPROTO-5-UPDOWN: Line protocol on Interface Vlan20, changed state to up
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#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:28, Vlan20
R 192.168.4.0/24 [120/2] via 192.168.2.2, 00:00:28, Vlan20
S3560#
S3560#show running-config
Building configuration...
Current configuration : 1276 bytes
!
version 12.2
no service timestamps log datetime msec
no service timestamps debug datetime msec
no service password-encryption
!
hostname S3560
!
...
!
interface FastEthernet0/1
!
...
!
interface FastEthernet0/10
switchport access vlan 10
!
...
!
interface FastEthernet0/20
switchport access vlan 20
!
...
!
interface Vlan1
no ip address
shutdown
!
interface Vlan10
ip address 192.168.1.1 255.255.255.0
!
interface Vlan20
ip address 192.168.2.1 255.255.255.0
!
router rip
version 2
network 192.168.1.0
network 192.168.2.0
!
ip classless
!
...
!
line con 0
line vty 0 4
login
!
!
!
end
S3560#
R1:
Router>en
Router#conf t
Enter configuration commands, one per line. End with CNTL/Z.
Router(config)#hostname R1
R1(config)#interface fa0/0
R1(config-if)#no shutdown
%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)#ip address 192.168.2.2 255.255.255.0
R1(config-if)#exit
R1(config)#interface fa0/1
R1(config-if)#no shutdown
%LINK-5-CHANGED: Interface FastEthernet0/1, changed state to up
R1(config-if)#ip address 192.168.3.1 255.255.255.0
R1(config-if)#exit
R1(config)#router rip //R1左側配置RIPv2路由協議
R1(config-router)#network 192.168.2.0
R1(config-router)#version 2
R1(config-router)#exit
R1(config)#router ospf 1 //R1右側配置OSPF路由協議
R1(config-router)#network 192.168.3.1 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:14, FastEthernet0/0
C 192.168.2.0/24 is directly connected, FastEthernet0/0
C 192.168.3.0/24 is directly connected, FastEthernet0/1
R1#
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:06, 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:01:22, FastEthernet0/1
R1#ping 192.168.1.2 //從R1 ping左側主機,可以ping通
Type escape sequence to abort.
Sending 5, 100-byte ICMP Echos to 192.168.1.2, timeout is 2 seconds:
..!!!
Success rate is 60 percent (3/5), round-trip min/avg/max = 3/5/8 ms
R1#ping 192.168.4.2 //從R1 ping右側主機,可以ping通
//此時左側主機ping不通右側主機
Type escape sequence to abort.
Sending 5, 100-byte ICMP Echos to 192.168.4.2, timeout is 2 seconds:
.!!!!
Success rate is 80 percent (4/5), round-trip min/avg/max = 3/5/7 ms
R1#
R1#
R1#conf t
Enter configuration commands, one per line. End with CNTL/Z.
R1(config)#router rip
R1(config-router)#redistribute ospf 1
R1(config-router)#exit
R1(config)#router ospf 1
R1(config-router)#redistribute rip ?
metric Metric for redistributed routes
metric-type OSPF/IS-IS exterior metric type for redistributed routes
subnets Consider subnets for redistribution into OSPF
tag Set tag for routes redistributed into OSPF
<cr>
R1(config-router)#redistribute rip subnets
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:03, 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:41, FastEthernet0/1
R1#
R1#
R1#show running-config
Building configuration...
Current configuration : 643 bytes
!
version 12.4
no service timestamps log datetime msec
no service timestamps debug datetime msec
no service password-encryption
!
hostname R1
!
...
!
interface FastEthernet0/0
ip address 192.168.2.2 255.255.255.0
duplex auto
speed auto
!
interface FastEthernet0/1
ip address 192.168.3.1 255.255.255.0
duplex auto
speed auto
!
interface Vlan1
no ip address
shutdown
!
router ospf 1
log-adjacency-changes
redistribute rip subnets
network 192.168.3.0 0.0.0.255 area 0
!
router rip
version 2
redistribute ospf 1
network 192.168.2.0
!
ip classless
!
...
!
line con 0
line vty 0 4
login
!
!
!
end
R1#
R2:
Router>en
Router#conf t
Enter configuration commands, one per line. End with CNTL/Z.
Router(config)#hostname R2
R2(config)#interface fa0/1
R2(config-if)#ip address 192.168.4.1 255.255.255.0
R2(config-if)#no shutdown
%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)#exit
R2(config)#interface fa0/0
R2(config-if)#ip address 192.168.3.2 255.255.255.0
R2(config-if)#no shutdown
%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)#
R2(config-if)#exit
R2(config)#router ospf
% Incomplete command.
R2(config)#router ospf 1 //配置R2 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/0
C 192.168.4.0/24 is directly connected, FastEthernet0/1
R2#
00:06:39: %OSPF-5-ADJCHG: Process 1, Nbr 192.168.3.1 on FastEthernet0/0 from LOADING to FULL, Loading Done
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:00:05, FastEthernet0/0
O E2 192.168.2.0/24 [110/20] via 192.168.3.1, 00:00:05, FastEthernet0/0
C 192.168.3.0/24 is directly connected, FastEthernet0/0
C 192.168.4.0/24 is directly connected, FastEthernet0/1
R2#
PC1:
Packet Tracer PC Command Line 1.0
PC>ipconfig
IP Address......................: 192.168.1.2
Subnet Mask.....................: 255.255.255.0
Default Gateway.................: 192.168.1.1
PC>ping 192.168.4.2 //路由重分布前,左右主機無法ping通
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>ping 192.168.4.2 //路由重分布后,左右主機可以ping通
Pinging 192.168.4.2 with 32 bytes of data:
Reply from 192.168.4.2: bytes=32 time=15ms TTL=125
Reply from 192.168.4.2: bytes=32 time=10ms TTL=125
Reply from 192.168.4.2: bytes=32 time=16ms TTL=125
Reply from 192.168.4.2: bytes=32 time=10ms TTL=125
Ping statistics for 192.168.4.2:
Packets: Sent = 4, Received = 4, Lost = 0 (0% loss),
Approximate round trip times in milli-seconds:
Minimum = 10ms, Maximum = 16ms, Average = 12ms
PC>