一,拓扑![](https://img-blog.csdnimg.cn/direct/4fd05e5c1da94926961cd9b42b2ad0e9.png)
二,要求
1,r4为ISP上只配ip,r3与其他设备之间只使用公有IP2,r3-r5/6/7为MGRE环境,r3为中心
3,整个OSPF的ip地址基于172.16.0.0/16划分
所以设备都可以访问r4的环回4减少LSA的数量加快收敛保障更新安全、
5,全网可达
三,配置
[r1]interface GigabitEthernet 0/0/0
[r1-GigabitEthernet0/0/0]ip address 172.16.0.2
[r1]interface LoopBack 0
[r1-LoopBack0]ip address 172.16.16.1 20ospf 1
area 0.0.0.1
[r1-ospf-1-area-0.0.0.1]stub ---末梢区域
network 172.16.0.2 0.0.0.0
network 172.16.16.1 0.0.0.0[r2]interface GigabitEthernet 0/0/0
[r2-GigabitEthernet0/0/0]ip address 172.16.0.3 23[r2]interface LoopBack 0
[r2-LoopBack0]ip address 172.16.32.1 20ospf 1
area 0.0.0.1
[r2-ospf-1-area-0.0.0.1]stub ---末梢区域
network 172.16.0.3 0.0.0.0
network 172.16.32.1 0.0.0.0[r3]interface Serial 4/0/0
[r3-Serial4/0/0]ip address 16.0.0.1 24
[r3]interface GigabitEthernet 0/0/0
[r3-GigabitEthernet0/0/0]ip address 172.16.0.1 23
[r3]interface LoopBack 0
[r3-LoopBack0]ip address 172.16.48.1 20[r3]ip route-static 0.0.0.0 0 16.0.0.2
[r3]interface Tunnel 0/0/0
[r3-Tunnel0/0/0]ip address 172.16.224.1 20
[r3-Tunnel0/0/0]tunnel-protocol gre p2mp
[r3-Tunnel0/0/0]source 16.0.0.1
[r3-Tunnel0/0/0]ospf network-type broadcast ---修改接口类型
[r3-Tunnel0/0/0]nhrp entry multicast dynamic ---开启伪广播[r3]acl 2000---easyip
[r3-acl-basic-2000]rule permit source any
[r3]interface Serial 4/0/0
[r3-Serial4/0/0]nat outbound 2000----nat
[r3]ospf 1 router-id 1.1.1.1
[r3-ospf-1]default-route-advertise---下发缺省
[r3-ospf-1]area 0
[r3-ospf-1-area-0.0.0.0]network 192.168.224.1 0.0.0.0
[r3-ospf-1-area-0.0.0.0]network 192.168.48.1 0.0.0.0
[r3-ospf-1]area 1
[r3-ospf-1-area-0.0.0.1]stub no-summary ----完全末梢区域
[r3-ospf-1-area-0.0.0.1]network 172.16.0.1 0.0.0.0
[r4]interface Serial 3/0/0
[r4-Serial3/0/0]ip address 16.0.0.2 24
[r4]interface Serial 3/0/1
[r4-Serial3/0/1]ip address 36.0.0.2 24
[r4-Serial3/0/1]interface Serial 4/0/0
[r4-Serial4/0/0]ip address 46.0.0.2 24
[r4]interface GigabitEthernet 0/0/0
[r4-GigabitEthernet0/0/0]ip address 26.0.0.2 24
[r4]interface LoopBack 0
[r4-LoopBack0]ip address 172.16.208.1 20[r5]interface Serial 4/0/0
[r5-Serial4/0/0]ip address 46.0.0.1 24
[r5]interface LoopBack 0
[r5-LoopBack0]ip address 172.16.80.1 20[r5]ip route-static 0.0.0.0 0 46.0.0.2
[r5]interface Tunnel 0/0/0
[r5-Tunnel0/0/0]ip address 172.16.224.4 20
[r5-Tunnel0/0/0]tunnel-protocol gre p2mp
[r5-Tunnel0/0/0]source Serial 4/0/0
[r5-Tunnel0/0/0]nhrp entry 172.16.224.1 16.0.0.1 register
[r5-Tunnel0/0/0]ospf network-type broadcast
[r5-Tunnel0/0/0]ospf dr-priority 0----放弃DR选举(DR要是中心)[r5]ospf 1
[r5-ospf-1]area 0
[r5-ospf-1-area-0.0.0.0]network 172.16.224.4 0.0.0.0
[r5-ospf-1-area-0.0.0.0]network 172.16.80.1 0.0.0.0
[r6]interface Serial 4/0/0
[[r6]i-Serial4/0/0]ip address 36.0.0.1 24
[[r6]]interface GigabitEthernet 0/0/1
[[r6]i-GigabitEthernet0/0/1]ip address 172.16.8.1 23
[[r6]]interface LoopBack 0
[[r6]-LoopBack0]ip address 172.16.96.1 20[r6]ip route-static 0.0.0.0 0 36.0.0.2
[r6]interface Tunnel 0/0/0
[r6-Tunnel0/0/0]ip address 172.16.224.3 20
[r6-Tunnel0/0/0]tunnel-protocol gre p2mp
[r6-Tunnel0/0/0]source Serial 4/0/0
[r6-Tunnel0/0/0]nhrp entry 172.16.224.1 16.0.0.1 register
[r6-Tunnel0/0/0]ospf network-type broadcast
[r6-Tunnel0/0/0]ospf dr-priority 0[r6]acl 2000
[r6-acl-basic-2000]rule permit source any
[r6]interface Serial 4/0/0
[r6-Serial4/0/0]nat outbound 2000[r6]ospf 1
[r6-ospf-1]default-route-advertise
[r6-ospf-1]area 0
[r6-ospf-1-area-0.0.0.0]network 172.16.96.1 0.0.0.0
[r6-ospf-1-area-0.0.0.0]network 172.16.224.3 0.0.0.0
[r6-ospf-1-area-0.0.0.0]q
[r6-ospf-1]area 2
[r6-ospf-1-area-0.0.0.2]nssa no-summary
[r6-ospf-1-area-0.0.0.2]network 172.16.8.1 0.0.0.0[r7]interface GigabitEthernet 0/0/0
[r7-GigabitEthernet0/0/0]ip address 26.0.0.1 24
[r7]interface GigabitEthernet 0/0/1
[r7-GigabitEthernet0/0/1]ip address 172.16.2.1 23
[r7]interface LoopBack 0
[r7-LoopBack0]ip address 172.16.64.1 20[r7]ip route-static 0.0.0.0 0 26.0.0.2
[r7]interface Tunnel 0/0/0
[r7-Tunnel0/0/0]ip address 172.16.224.2 20
[r7-Tunnel0/0/0]tunnel-protocol gre p2mp
[r7-Tunnel0/0/0]source GigabitEthernet 0/0/0
[r7-Tunnel0/0/0]nhrp entry 172.16.224.1 16.0.0.1 register
[r7-Tunnel0/0/0]ospf network-type broadcast
[r7-Tunnel0/0/0]ospf dr-priority 0[r7]acl 2000
[r7-acl-basic-2000]rule permit source any
[r7]interface GigabitEthernet 0/0/0
[r7-GigabitEthernet0/0/0]nat outbound 2000[r7]ospf 1 router-id 2.2.2.2
[r7-ospf-1]default-route-advertise
[r7-ospf-1]area 0
[r7-ospf-1-area-0.0.0.0]network 172.16.224.2 0.0.0.0
[r7-ospf-1-area-0.0.0.0]network 172.16.64.1 0.0.0.0
[r7-ospf-1-area-0.0.0.0]q
[r7-ospf-1]area 3
[r7-ospf-1-area-0.0.0.3]nssa no-summary---- 完全的非完全末梢区域
[r7-ospf-1-area-0.0.0.3]network 172.16.2.1 0.0.0.0
[r8]interface GigabitEthernet 0/0/0
[r8-GigabitEthernet0/0/0]ip address 172.16.2.2 23
[r8]interface GigabitEthernet 0/0/1
[r8-GigabitEthernet0/0/1]ip address 172.16.4.1 23
[r8]interface LoopBack 0
[r8-LoopBack0]ip address 172.16.112.1 20ospf 1
area 0.0.0.3
[r8-ospf-1-area-0.0.0.3]nssa ---非完全末梢区域
network 172.16.2.2 0.0.0.0
network 172.16.4.1 0.0.0.0
network 172.16.112.1 0.0.0.0
[r9]interface GigabitEthernet 0/0/0
[r9-GigabitEthernet0/0/0]ip address 172.164.4.2 23
[r9]interface GigabitEthernet 0/0/1
[r9-GigabitEthernet0/0/1]ip address 172.16.6.1 23
[r9]interface LoopBack 0
[r9-LoopBack0]ip address 172.16.192.1 20[r9]ospf 1
[r9-ospf-1]import-route ospf 2----将通过OSPF 2学习到的路由以及本地发布到OSPF 1的路由信息重新引入到OSPF 1当中
[r9-ospf-1]area 3
[r9-ospf-1-area-0.0.0.3]nssa
network 172.16.4.2 0.0.0.0
network 172.16.192.1 0.0.0.0
[r9-ospf-1]area 4
[r9-ospf-1-area-0.0.0.4]abr-summary 172.16.6.0 255.255.224.0----域外路由汇总[r9]ospf 2
[r9-ospf-2]default-route-advertise
[r9-ospf-2]import-route ospf 1----将通过OSPF 1学习到的路由以及本地发布到OSPF 2的路由信息重新引入到OSPF 1当中
[r9-ospf-2]area 4
[r9-ospf-2-area-0.0.0.4]network 172.16.6.1 0.0.0.0
[r10]interface GigabitEthernet 0/0/0
[r10-GigabitEthernet0/0/0]ip address 172.16.6.2 23
[r10]interface LoopBack 0
[r10-LoopBack0]ip address 172.16.128.1 20ospf 1
area 0.0.0.4
network 172.16.6.2 0.0.0.0
network 172.16.128.1 0.0.0.0[r12]interface GigabitEthernet 0/0/0
[r12-GigabitEthernet0/0/0]ip address 172.16.8.2 23
[r12]interface GigabitEthernet 0/0/1
[r12-GigabitEthernet0/0/1]ip address 172.16.10.1 23
[r12]interface LoopBack 0
[r12-LoopBack0]ip address 172.16.144.1 20ospf 1
area 0.0.0.2
[r12-ospf-1-area-0.0.0.2]nssa
network 172.16.8.2 0.0.0.0
network 172.16.10.1 0.0.0.0
network 172.16.144.1 0.0.0.0
[r13]interface GigabitEthernet 0/0/0
[r13-GigabitEthernet0/0/0]ip address 172.16.10.2 23
[r13]interface LoopBack 0
[r13-LoopBack0]ip address 172.16.160.1 20
[r13]interface LoopBack 1
[r13-LoopBack1]ip address 172.16.176.1 20ospf 1
[r13-ospf-1]import-route rip 1
area 2
[r13-ospf-1-area-0.0.0.2]nssa
[r13-ospf-1-area-0.0.0.2]network 172.16.10.2 0.0.0.0[r13]rip 1
[r13-rip-1]ver
[r13-rip-1]verify-source
[r13-rip-1]version 2
[r13-rip-1]network 172.16.0.0
四,测试
都可以ping通R4的环回