实验过程涉及知识:分发列表(distribute-list)、管理距离(distance)、邻居关系(neighbor)、访问控制列表(access-list)。
实验过程描述:首先什么都不做,只是让交换机和路由器能互相学习到对方的信息,然后再添加分发列表、管理距离等,最后查看所有设备的路由表以检验实验是否成功。
SW#conf t
SW(config)#vlan 34
SW(config-vlan)#exit
SW(config)#inter vlan 34
SW(config-if)#no shut
SW(config-if)#ip add 192.168.34.3 255.255.255.0
SW(config-if)#exit
SW(config)#inter e0/0
SW(config-if)#sw mo ac
SW(config-if)#sw ac vlan 34
SW(config-if)#exit
SW(config)#inter e0/1
SW(config-if)#sw mo ac
SW(config-if)#sw ac vlan 34
SW(config-if)#exit
SW(config)#inter e0/2
SW(config-if)#no sw
SW(config-if)#ip add 192.168.134.2 255.255.255.0
SW(config-if)#no shut
SW(config-if)#exit
SW(config)#router rip
SW(config-router)#version 2
SW(config-router)#network 192.168.34.0
SW(config-router)#network 192.168.134.0
SW(config-router)#no auto-summary
SW(config-router)#end
R1#conf t
R1(config)#inter loop 0
R1(config-if)#no shut
R1(config-if)#ip add 10.10.34.1 255.255.255.0
R1(config-if)#exit
R1(config)#inter loop 1
R1(config-if)#no shut
R1(config-if)#ip add 20.20.34.1 255.255.255.0
R1(config-if)#exit
R1(config)#inter f0/0
R1(config-if)#ip add 192.168.34.1 255.255.255.0
R1(config-if)#no shut
R1(config-if)#exit
R1(config)#router rip
R1(config-router)#version 2
R1(config-router)#network 192.168.34.0
R1(config-router)#network 10.10.34.0
R1(config-router)#network 20.20.34.0
R1(config-router)#no auto-summary
R1(config-router)#end
R2#conf t
R2(config)#inter loop 0
R2(config-if)#no shut
R2(config-if)#ip add 30.30.34.1 255.255.255.0
R2(config-if)#exit
R2(config)#inter loop 1
R2(config-if)#no shut
R2(config-if)#ip add 40.40.34.1 255.255.255.0
R2(config-if)#exit
R2(config)#inter f0/1
R2(config-if)#ip add 192.168.34.2 255.255.255.0
R2(config-if)#no shut
R2(config-if)#exit
R2(config)#router rip
R2(config-router)#version 2
R2(config-router)#network 192.168.34.0
R2(config-router)#network 30.30.34.0
R2(config-router)#network 40.40.34.0
R2(config-router)#no auto-summary
R2(config-router)#end
配置完基础命令,检查一下交换机的路由表。
SW#show ip route
Codes: L - local, 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, H - NHRP, l - LISP
+ - replicated route, % - next hop override
Gateway of last resort is not set
10.0.0.0/24 is subnetted, 1 subnets
R 10.10.34.0 [120/1] via 192.168.34.1, 00:00:05, Vlan34
20.0.0.0/24 is subnetted, 1 subnets
R 20.20.34.0 [120/1] via 192.168.34.1, 00:00:05, Vlan34
30.0.0.0/24 is subnetted, 1 subnets
R 30.30.34.0 [120/1] via 192.168.34.2, 00:00:03, Vlan34
40.0.0.0/24 is subnetted, 1 subnets
R 40.40.34.0 [120/1] via 192.168.34.2, 00:00:03, Vlan34
192.168.34.0/24 is variably subnetted, 2 subnets, 2 masks
C 192.168.34.0/24 is directly connected, Vlan34
L 192.168.34.3/32 is directly connected, Vlan34
192.168.134.0/24 is variably subnetted, 2 subnets, 2 masks
C 192.168.134.0/24 is directly connected, Ethernet0/2
L 192.168.134.2/32 is directly connected, Ethernet0/2
SW#
给交换机 SW 配置管理距离;给路由器 R1 配置被动端口、分发列表。
SW(config)#router rip
SW(config-router)#distance 100 192.168.34.1 0.0.0.0
R1#conf t
R1(config)#access-list 10 permit 10.10.34.0 0.0.0.255
R1(config)#router rip
R1(config-router)#passive-interface f0/0
R1(config-router)#neighbor 192.168.34.3
R1(config-router)#distribute-list 10 out f0/0
R1(config-router)#end
此时再查看交换机 SW 的路由表,将收不到路由器 R1 的 Loop 1 端口的路由信息(默认被拒绝)。
SW#show ip route
Codes: L - local, 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, H - NHRP, l - LISP
+ - replicated route, % - next hop override
Gateway of last resort is not set
10.0.0.0/24 is subnetted, 1 subnets
R 10.10.34.0 [100/1] via 192.168.34.1, 00:00:01, Vlan34
30.0.0.0/24 is subnetted, 1 subnets
R 30.30.34.0 [120/1] via 192.168.34.2, 00:00:04, Vlan34
40.0.0.0/24 is subnetted, 1 subnets
R 40.40.34.0 [120/1] via 192.168.34.2, 00:00:04, Vlan34
192.168.34.0/24 is variably subnetted, 2 subnets, 2 masks
C 192.168.34.0/24 is directly connected, Vlan34
L 192.168.34.3/32 is directly connected, Vlan34
192.168.134.0/24 is variably subnetted, 2 subnets, 2 masks
C 192.168.134.0/24 is directly connected, Ethernet0/2
L 192.168.134.2/32 is directly connected, Ethernet0/2
SW#
查看路由器 R1 和路由器 R2 的路由表。
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
R 192.168.134.0/24 [120/1] via 192.168.34.3, 00:00:22, FastEthernet0/0
20.0.0.0/24 is subnetted, 1 subnets
C 20.20.34.0 is directly connected, Loopback1
40.0.0.0/24 is subnetted, 1 subnets
R 40.40.34.0 [120/1] via 192.168.34.2, 00:00:24, FastEthernet0/0
10.0.0.0/24 is subnetted, 1 subnets
C 10.10.34.0 is directly connected, Loopback0
C 192.168.34.0/24 is directly connected, FastEthernet0/0
30.0.0.0/24 is subnetted, 1 subnets
R 30.30.34.0 [120/1] via 192.168.34.2, 00:00:00, FastEthernet0/0
R1#
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
R 192.168.134.0/24 [120/1] via 192.168.34.3, 00:00:02, FastEthernet0/1
40.0.0.0/24 is subnetted, 1 subnets
C 40.40.34.0 is directly connected, Loopback1
C 192.168.34.0/24 is directly connected, FastEthernet0/1
30.0.0.0/24 is subnetted, 1 subnets
C 30.30.34.0 is directly connected, Loopback0
R2#