给该网络配置IP
先给公网配置IP,然后在公网配置路由协议,使得公网连通
(OSPF配置)r7本省不能宣告到公网中
将r4 的4/0/0接口调成沉默接口,不给r7发hello包
给r7配置缺省路由指向公网
启用mpls(r2,r3,r4)
[r2]mpls lsr-id 2.2.2.2
[r2-GigabitEthernet0/0/1]mpls ldp
r2]int g0/0/1
[r2-GigabitEthernet0/0/1]mpls
[r2-GigabitEthernet0/0/1]mpls ldp
r3]mpls lsr-id 3.3.3.3
[r3]mpls
[r3-mpls]mpls ldp
[r3-mpls-ldp]int g0/0/0
[r3-GigabitEthernet0/0/0]mpls
[r3-GigabitEthernet0/0/0]mpls ldp
[r3-GigabitEthernet0/0/0]int g0/0/1
[r3-GigabitEthernet0/0/1]mpls ld
[r3-GigabitEthernet0/0/1]mpls ldp
[r4]mpls lsr-id 4.4.4.4
[r4]mpls
[r4-mpls]mpls ldp
[r4-mpls-ldp]int g0/0/0
[r4-GigabitEthernet0/0/0]mpls
[r4-GigabitEthernet0/0/0]mpls ldp
建立VPN
#在r2启用vr空间
[r2]ip vpn-instance b
#配置RD值
[r2-vpn-instance-a]route-distinguisher 2:2
#配置RT值
[r2-vpn-instance-a-af-ipv4]vpn-target 2:2
#将接口0/0/0绑定到vr空间b上
[r2]int g0/0/0
[r2-GigabitEthernet0/0/0]ip binding vpn-instance b
#然后配置IP
[r2-GigabitEthernet0/0/0]ip address 192.168.2.2 24
[r4]ip vpn-instance b
[r4-vpn-instance-b]route-distinguisher 2:2
[r4-vpn-instance-b-af-ipv4]vpn-target 2:2
[r4-GigabitEthernet0/0/1]ip binding vpn-instance b
[r4-GigabitEthernet0/0/1]ip address 192.168.3.1 24
将r1与r5连通
#r2
[r2]bgp 1
[r2-bgp]router-id 2.2.2.2
[r2-bgp]peer 4.4.4.4 as-number 1
[r2-bgp]peer 4.4.4.4 connect-interface LoopBack 0
#传递私网路由
[r2-bgp]ipv4-family vp
[r2-bgp]ipv4-family vpnv4
[r2-bgp-af-vpnv4]peer
[r2-bgp-af-vpnv4]peer 4.4.4.4 enable
#R4
[r4]bgp 1
[r4-bgp]router-id 4.4.4.4
[r4-bgp]peer 2.2.2.2 as-number 1
[r4-bgp]peer 2.2.2.2 connect-interface LoopBack 0
[r4-bgp]ipv4-family vpnv4
[r4-bgp-af-vpnv4]peer 2.2.2.2 enable
#配置静态路由(使r1,r2,r4,r5路由条目齐全)
[r1]ip route-static 192.168.3.0 24 192.168.2.2
[r1]ip route-static 192.168.4.0 24 192.168.2.2
[r2]ip route-static vpn-instance b 192.168.1.0 24 192.168.2.1
[r4]ip route-static vpn-instance b 192.168.4.0 24 192.168.3.2
[r5]ip route-static 192.168.1.0 24 192.168.3.1
[r5]ip route-static 192.168.2.0 24 192.168.3.1
#r2与r4重发布
#把r2vr空间中的直连与静态路由重发布到BGP中去
r2]bgp 1
[r2-bgp]ipv4-family vpn-instance b
[r2-bgp-b]import-route direct
[r2-bgp-b]import-route static
[r4]bgp 1
[r4-bgp]ipv4-family vpn-instance b
[r4-bgp-b]import-route direct
[r4-bgp-b]import-route static
r6与r7连通
#r2与r4上创建vr空间a
r2]ip vpn-instance a
[r2-vpn-instance-a]route-distinguisher 1:1
[r2-vpn-instance-a-af-ipv4]vpn-target 1:1
[r2]int g 0/0/2
[r2-GigabitEthernet0/0/2]ip binding vpn-instance a
[r2-GigabitEthernet0/0/2]ip address 192.168.2.2 24
[r4]ip vpn-instance a
[r4-vpn-instance-a]route-distinguisher 1:1
[r4-vpn-instance-a-af-ipv4]vpn-target 1:1
[r4-vpn-instance-a]int g0/0/2
[r4-GigabitEthernet0/0/2]ip binding vpn-instance a
[r4-GigabitEthernet0/0/2]ip add 192.168.3.1 24
#使用动态路由协议使得r6与r7连通
[r6]rip 1
[r6-rip-1]ver 2
[r6-rip-1]network 192.168.1.0
[r6-rip-1]network 192.168.2.0
#在vr空间a上启用rip协议
[r2]rip 1 vpn-instance a
[r2-rip-1]ver 2
[r2-rip-1]network 192.168.2.0
[r7]ospf 1 router-id 7.7.7.7
[r7-ospf-1]area 0
[r7-ospf-1-area-0.0.0.0]network 192.168.3.2 0.0.0.0
[r7-ospf-1-area-0.0.0.0]network 192.168.4.2 0.0.0.0
#r4上存在ospf进程1,在vr空间a上启用进程2
[r4]ospf 2 vpn-instance a
[r4-ospf-2]area 0
[r4-ospf-2-area-0.0.0.0]network 192.168.3.1 0.0.0.0
#进行双向重发布
[r2]bgp 1
#进入vr空间a
[r2-bgp]ipv4-family vpn-instance a
[r2-bgp-a]import-route rip 1
[r4]ospf 2 vp
[r4]ospf 2 vpn-instance a
[r4-ospf-2]im
[r4-ospf-2]import-route bgp
[r2]rip 1 vp
[r2]rip 1 vpn-instance a
[r2-rip-1]import-route bgp
[r4]bgp 1
[r4-bgp]ipv4-family vpn-instance a
[r4-bgp-a]import-route ospf 2