需求:
1、 上半部分运行RIPv2,下半区域运行OSPF,在R3、R5上做双点双向重分布;
2、 在R3或者R5上观察去往1.1.1.0/32条目得最优路径,通过修改重分布不同协议时的AD值来让R3或者R5上1.1.1.0/32的路径为实际最优路径;
3、 只针对1.1.1.1/32和2.2.2.2/32的路由条目修改其重分布进OSPF时的AD值为125;
4、 R4上拒绝将192.168.12.0/24、192.168.23.0/24、192.168.15.0/24的路由放入路由表中。
=============================================================
需求1:
R3(config)#router rip
R3(config-router)#version 2
R3(config-router)#no auto-summary
R3(config-router)#network 192.168.23.0
R3(config-router)#redistribute ospf 1 metric 5
R3(config)#router ospf 1
R3(config-router)#router-id 3.3.3.3
R3(config-router)#network 192.168.34.0 0.0.0.255 area 0
R3(config-router)#redistribute rip subnets
-->R3上RIP、OSPF双向重分布
R5(config)#router rip
R5(config-router)#version 2
R5(config-router)#no auto-summary
R5(config-router)#network 192.168.15.0
R5(config-router)#redistribute ospf 1 metric 5
R5(config)#router ospf 1
R5(config-router)#router-id 5.5.5.5
R5(config-router)#network 192.168.45.0 0.0.0.255 area 0
R5(config-router)#redistribute rip subnets
-->R5上RIP、OSPF双向重分布
-----------------------------------------------------------------------------------------
R3#sh ip route 1.1.1.1
Routing entry for 1.1.1.1/32
Known via "rip", distance 120, metric 2
Redistributing via rip, ospf 1
Advertised by ospf 1 subnets
Last update from 192.168.23.2 on Serial1/0, 00:00:14 ago
Routing Descriptor Blocks:
* 192.168.23.2, from 192.168.23.2, 00:00:14 ago, via Serial1/0
Route metric is 2, traffic share count is 1
-->R3上单独查看1.1.1.1/32的路由条目,可以看它的下一跳是192.168.23.2,走的是R2,这是正常的。再到R5上查看1.1.1.1/32的路由条目;

R5#sh ip route 1.1.1.1
Routing entry for 1.1.1.1/32
Known via "ospf 1", distance 110, metric 20, type extern 2, forward metric 128
Redistributing via rip
Advertised by rip metric 5
Last update from 192.168.45.4 on Serial1/0, 00:20:51 ago
Routing Descriptor Blocks:
* 192.168.45.4, from 3.3.3.3, 00:20:51 ago, via Serial1/0
Route metric is 20, traffic share count is 1
-->R5上可以看到去往1.1.1.1/32是走的R4-->R3-->R2-->R1,很明显绕了一圈,这明显不对的!
用traceroute跟踪一下:

R5#traceroute 1.1.1.1
Type escape sequence to abort.
Tracing the route to 1.1.1.1
1 192.168.45.4 64 msec 60 msec 24 msec
2 192.168.34.3 176 msec 72 msec 68 msec
3 192.168.23.2 68 msec 136 msec 100 msec
4 192.168.12.1 140 msec * 120 msec
-->果然绕了一个大圈。下面配置来避免这种情况的发生:

R5(config)#router ospf 1
R5(config-router)#distance ospf external 125
-->修改OSPF外部路由的AD值,这里因为R5学到的RIP的AD为120,而通过OSPF内部学到路由的AD为110,比较1.1.1.1/32的路由AD,R5会错误的选择OSPF内部宣告的条目。

R3(config)#router ospf 1
R3(config-router)#distance ospf external 125
-->R3上也要做与R5相同的配置!否则R3会错误的选择路由条目。
再来验证一下配置结果是否正确:
R3#traceroute 1.1.1.1
Type escape sequence to abort.
Tracing the route to 1.1.1.1
1 192.168.23.2 8 msec 8 msec 24 msec
2 192.168.12.1 368 msec * 84 msec

R5#traceroute 1.1.1.1
Type escape sequence to abort.
Tracing the route to 1.1.1.1
1 192.168.15.1 100 msec * 72 msec
-->R3和R5上都正常。
-----------------------------------------------------------------------------------------------------------
R3(config)#access-list 1 permit 1.1.1.1
R3(config)#access-list 1 permit 2.2.2.2
R3(config)#router ospf 1
R3(config-router)#no distance ospf external 125 -->去掉上个需求的配置
R3(config-router)#distance 125 5.5.5.5 0.0.0.0 1 -->这里需要填写另一个ASBR的RID,并引用控制列表,该命令只在本地有效。

R5(config)#access-list 1 permit 1.1.1.1.
R5(config)#access-list 1 permit 2.2.2.2
R5(config)#router ospf 1
R5(config-router)#no distance ospf external 125
R5(config-router)#distance 125 3.3.3.3 0.0.0.0 1

R3(config)#do sh 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

O E2 192.168.12.0/24 [110/20] via 192.168.34.4, 00:06:43, Serial1/1
1.0.0.0/32 is subnetted, 1 subnets
R 1.1.1.1 [120/2] via 192.168.23.2, 00:00:29, Serial1/0
2.0.0.0/32 is subnetted, 1 subnets
R 2.2.2.2 [120/1] via 192.168.23.2, 00:00:29, Serial1/0
3.0.0.0/32 is subnetted, 1 subnets
C 3.3.3.3 is directly connected, Loopback0
O E2 192.168.15.0/24 [110/20] via 192.168.34.4, 00:06:43, Serial1/1
O 192.168.45.0/24 [110/128] via 192.168.34.4, 00:06:43, Serial1/1
4.0.0.0/32 is subnetted, 1 subnets
O 4.4.4.4 [110/65] via 192.168.34.4, 00:06:43, Serial1/1
C 192.168.23.0/24 is directly connected, Serial1/0
C 192.168.34.0/24 is directly connected, Serial1/1
-->R3上学到1.1.1.1/32和2.2.2.2/32的条目下一跳均为R2,正常。而192.168.12.0/24的下一跳是R4,控制列表奏效。

R5#sh 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.12.0/24 [120/1] via 192.168.15.1, 00:00:21, Serial1/1
1.0.0.0/32 is subnetted, 1 subnets
R 1.1.1.1 [120/1] via 192.168.15.1, 00:00:21, Serial1/1
2.0.0.0/32 is subnetted, 1 subnets
R 2.2.2.2 [120/2] via 192.168.15.1, 00:00:21, Serial1/1
C 192.168.15.0/24 is directly connected, Serial1/1
C 192.168.45.0/24 is directly connected, Serial1/0
4.0.0.0/32 is subnetted, 1 subnets
O 4.4.4.4 [110/65] via 192.168.45.4, 00:06:56, Serial1/0
5.0.0.0/32 is subnetted, 1 subnets
C 5.5.5.5 is directly connected, Loopback0
O E2 192.168.23.0/24 [110/20] via 192.168.45.4, 00:06:56, Serial1/0
O 192.168.34.0/24 [110/128] via 192.168.45.4, 00:06:56, Serial1/0
-->R5上1.1.1.1/32和2.2.2.2/32的下一跳均为R1,正常。

R4#sh 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

O E2 192.168.12.0/24 [110/20] via 192.168.45.5, 00:20:06, Serial1/1
1.0.0.0/32 is subnetted, 1 subnets
O E2 1.1.1.1 [110/20] via 192.168.45.5, 00:09:23, Serial1/1
[110/20] via 192.168.34.3, 00:09:23, Serial1/0
2.0.0.0/32 is subnetted, 1 subnets
O E2 2.2.2.2 [110/20] via 192.168.45.5, 00:09:23, Serial1/1
[110/20] via 192.168.34.3, 00:09:23, Serial1/0
O E2 192.168.15.0/24 [110/20] via 192.168.45.5, 00:20:06, Serial1/1
C 192.168.45.0/24 is directly connected, Serial1/1
4.0.0.0/32 is subnetted, 1 subnets
C 4.4.4.4 is directly connected, Loopback0
O E2 192.168.23.0/24 [110/20] via 192.168.34.3, 00:20:01, Serial1/0
C 192.168.34.0/24 is directly connected, Serial1/0
-->R4上1.1.1.1/32和2.2.2.2/32的路由AD还是OSPF的默认AD,说明distance命令只在本地有效。
------------------------------------------------------------------------------------------
需求4:
R4(config)#ip prefix-list ccnp deny 192.168.12.0/24
R4(config)#ip prefix-list ccnp deny 192.168.23.0/24
R4(config)#ip prefix-lisr ccnp deny 192.168.15.0/24
R4(config)#ip prefix-list ccnp permit 0.0.0.0/0 le 32
R4(config)#router ospf 1
R4(config-router)#distribute-list prefix ccnp in s1/0
R4(config-router)#distribute-list prefix ccnp in s1/1 -->在接口上应用分发列表

R4#sh 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/32 is subnetted, 1 subnets
O E2 1.1.1.1 [110/20] via 192.168.45.5, 00:05:06, Serial1/1
[110/20] via 192.168.34.3, 00:05:06, Serial1/0
2.0.0.0/32 is subnetted, 1 subnets
O E2 2.2.2.2 [110/20] via 192.168.45.5, 00:05:06, Serial1/1
[110/20] via 192.168.34.3, 00:05:06, Serial1/0
C 192.168.45.0/24 is directly connected, Serial1/1
4.0.0.0/32 is subnetted, 1 subnets
C 4.4.4.4 is directly connected, Loopback0
C 192.168.34.0/24 is directly connected, Serial1/0
-->可以看到192.168.12.0/24、192.168.23.0/24、192.168.15.0/24已经从R4路由表中消失。