1.配置IP地址
R1
环回0:192.168.1.1/24
G0/0/0:192.168.2.1/24R2
环回0:2.2.2.2/24
G0/0/0:192.168.2.2/24
G0/0/1:172.16.2.2/24
G0/0/2:23.0.0.1/24R3
环回0:3.3.3.3/24
G0/0/0:23.0.0.2/24
G0/0/1:34.0.0.1/24R4
环回0:4.4.4.4/24
G0/0/0:192.168.3.1/24
G0/0/1:172.16.3.1/24
G0/0/2:34.0.0.2/24
G4/0/0:47.0.0.1/24R5
环回0:192.168.4.1/24
G0/0/0:192.168.3.2/24R6
环回0:172.16.1.1/24
G0/0/0:172.16.2.1/24R7
环回0:172.16.4.1/24
G0/0/0:172.16.3.2/24
G0/0/1:47.0.0.2/24
2.对骨干网络进行ospf宣告
以r2为例
[r2]ospf 1 router-id 2.2.2.2
[r2-ospf-1]area 0
[r2-ospf-1-area-0.0.0.0]network 2.2.2.2 0.0.0.0
[r2-ospf-1-area-0.0.0.0]network 23.0.0.0 0.0.0.255
3.创建mpls
以r2为例
[r2]mpls lsr-id 2.2.2.2
[r2]mpls
[r2]mpls ldp
[r2-GigabitEthernet0/0/1]mpls
[r2-GigabitEthernet0/0/1]mpls ldp
4.配置vpn
客户A
以r2为例
[r2]ip vpn-instance a
[r2-vpn-instance-a1]route-distinguisher 1:5
[r2-vpn-instance-a1-af-ipv4]vpn-target 1:1 export-extcommunity
[r2-vpn-instance-a1-af-ipv4]vpn-target 1:1 import-extcommunity
[r2-vpn-instance-a1-af-ipv4]q
[r2-vpn-instance-a1]q
[r2]int g 0/0/0
[r2-GigabitEthernet0/0/0]ip binding vpn-instance a
[r2-GigabitEthernet0/0/0]ip ad 192.168.2.2 24
客户B
以r2为例
[r2]ip vpn-instance b
[r2-vpn-instance-b1]route-distinguisher 6:7
[r2-vpn-instance-b1-af-ipv4]vpn-target 2:2 export-extcommunity
[r2-vpn-instance-b1-af-ipv4]vpn-target 2:2 import-extcommunity
[r2-vpn-instance-b1-af-ipv4]q
[r2-vpn-instance-b1]q
[r2]int g 0/0/1
[r2-GigabitEthernet0/0/1]ip binding vpn-instance b
[r2-GigabitEthernet0/0/1]ip ad 172.16.2.2 24
写静态路由
[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
[r4]ip route-static vpn-instance a 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
在客户B宣告所有路由信息
路由器包括R2/6/4/7(仅以下面两个为例)
[r2]rip 1 v
[r2]rip 1 vpn-instance b
[r2-rip-1]v 2
[r2-rip-1]network 172.16.0.0
[r4]ospf 2 vpn-instance b router-id 4.4.4.4
[r4-ospf-2]area 0
[r4-ospf-2-area-0.0.0.0]network 172.16.0.0 0.0.255.255
MP-BGP建邻
r2为例
[r2]bgp 1
[r2-bgp]router-id 2.2.2.2
[r2-bgp]peer 4.4.4.4 as 1
[r2-bgp]peer 4.4.4.4 connect-interface LoopBack 0
[r2-bgp]ipv4-family vpnv4
[r2-bgp-af-vpnv4]peer 4.4.4.4 enable
MP-BGP路由发布
客户A
r2为例
[r2]bgp 1
[r2-bgp]ipv4-family vpn-instance a
[r2-bgp-a1]import-route direct
[r2-bgp-a1]import-route static
客户B
R4为例
[r4]bgp 1
[r4-bgp]ipv4-family vpn-instance b
[r4-bgp-b]import-route ospf 2
[r4-bgp-b]q
[r4-bgp]q
[r4]ospf 2
[r4-ospf-2]import-route bgp
R7访问公网
[r7]ip route-static 0.0.0.0 0 47.0.0.1
结果