一,建立拓扑
二,1.配置公网接口IP地址
[R2-LoopBack0]ip add 2.2.2.2 24
[R2-GigabitEthernet0/0/1]ip add 23.1.1.1 24
[R3-GigabitEthernet0/0/0]ip add 23.1.1.2 24
[R3-LoopBack0]ip add 3.3.3.3 24
[R3-GigabitEthernet0/0/1]ip add 34.1.1.1 24
[R4-GigabitEthernet0/0/0]ip add 34.1.1.2 24
[R4-LoopBack0]ip add 4.4.4.4 24
[R4-GigabitEthernet4/0/0]ip add 47.1.1.1 24
[R7-GigabitEthernet0/0/0]ip add 47.1.1.2 24
2.开启OSPF
[R2]ospf 1 router-id 2.2.2.2
[R2-ospf-1-area-0.0.0.0]network 23.1.1.1 0.0.0.0
[R2-ospf-1-area-0.0.0.0]network 2.2.2.2 0.0.0.0
[R3]ospf 1 router-id 3.3.3.3
[R3-ospf-1-area-0.0.0.0]network 23.1.1.2 0.0.0.0
[R3-ospf-1-area-0.0.0.0]network 3.3.3.3 0.0.0.0
[R3-ospf-1-area-0.0.0.0]network 34.1.1.1 0.0.0.0
[R4]ospf 1 router-id 4.4.4.4
[R4-ospf-1-area-0.0.0.0]network 34.1.1.2 0.0.0.0
[R4-ospf-1-area-0.0.0.0]network 4.4.4.4 0.0.0.0
[R4-ospf-1-area-0.0.0.0]network 47.1.1.1 0.0.0.0
[R4-ospf-1]silent-interface GigabitEthernet 4/0/0
配置缺省
[R7]ip route-static 0.0.0.0 0 47.1.1.1
测试ping
3.在r2/3/4上配置MPLS
[R2]mpls lsr-id 2.2.2.2
[R2]mpls
Info: Mpls starting, please wait... OK!
[R2-mpls]mpls ldp
[R2-mpls-ldp]int g0/0/1
[R2-GigabitEthernet0/0/1]mpls
[R2-GigabitEthernet0/0/1]mpls ldp
[R3]mpls lsr-id 3.3.3.3
Info: Mpls starting, please wait... OK!
[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
[R3-GigabitEthernet0/0/1]mpls ldp
[R4]mpls lsr-id 4.4.4.4
Info: Mpls starting, please wait... OK!
[R4-mpls]mpls ldp
[R4-mpls-ldp]int g0/0/0
[R4-GigabitEthernet0/0/0]mpls
[R4-GigabitEthernet0/0/0]mpls ldp
检查邻居
4,创建vPn,并且配置bgp
[R2]ip vpn-instance b1
[R2-vpn-instance-b1]ipv4-family
[R2-vpn-instance-b1-af-ipv4]route-distinguisher 1:1
[R2-vpn-instance-b1-af-ipv4]vpn-target 1:1
[R2]ip vpn-instance a1
[R2-vpn-instance-a1]ipv4-family
[R2-vpn-instance-a1-af-ipv4]route-distinguisher 2:2
[R2-vpn-instance-a1-af-ipv4]vpn-target 2:2
[R2-GigabitEthernet0/0/0]ip binding vpn-instance b1
[R2-GigabitEthernet0/0/0]ip add 192.168.2.2 24
[R2-GigabitEthernet0/0/2]ip binding vpn-instance a1
[R2-GigabitEthernet0/0/2]ip add 192.168.2.2 24
[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 vpnv4
[R2-bgp-af-vpnv4]peer 4.4.4.4 enable
[R4]ip vpn-instance b2
[R4-vpn-instance-b2]ipv4-family
[[R4-vpn-instance-b2-af-ipv4]route-distinguisher 1:1
[R4-vpn-instance-b2-af-ipv4]vpn
[R4-vpn-instance-b2-af-ipv4]vpn-target 1:1
[R4]ip vpn-instance a2
[R4-vpn-instance-a2]ipv4-family
[R4-vpn-instance-a2-af-ipv4]route-distinguisher 2:2
[R4-vpn-instance-a2-af-ipv4]vpn-target 2:2
[R4-GigabitEthernet0/0/1]ip binding vpn-instance b2
[R4-GigabitEthernet0/0/1]ip add 192.168.3.1 24
[R4-GigabitEthernet0/0/2]ip binding vpn-instance a2
[R4-GigabitEthernet0/0/2]ip add 192.168.3.1 24
[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,5,6,7配置IP
[R1-LoopBack0]ip add 192.168.1.1 24
[R1-GigabitEthernet0/0/1]ip add 192.168.2.1 24
[R6-LoopBack0]ip add 192.168.1.1 24
[R6-GigabitEthernet0/0/2]ip add 192.168.2.1 24
[R5-GigabitEthernet0/0/0]ip add 192.168.3.2 24
[R5-LoopBack0]ip add 192.168.4.1 24
[R7-GigabitEthernet0/0/2]ip add 192.168.3.2 24
[R7-LoopBack0]ip add 192.168.4.2 24
5,R2和R6配置RIP协议,R7和R4配置OSPF协议
[R6]rip 1
[R6-rip-1]ver 2
[R6-rip-1]network 192.168.1.0
[R6-rip-1]network 192.168.2.0
[R2]rip 1 vpn-instance a1
[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.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 2 vpn-instance a2
[R4-ospf-2-area-0.0.0.0]network 192.168.3.1 0.0.0.0
6,R2和R4上进行双向重发布
[R2]rip 1
[R2-rip-1]import-route bgp
[R2]bgp 1
[R2-bgp]ipv4-family vpn-instance a1
[R2-bgp-a1]import-route rip 1
[R4]bgp 1
[R4-bgp]ipv4-family vpn-instance a2
[R4-bgp-a2]import-route ospf 2
[R4]ospf 2 vpn-instance a2
[R4-ospf-2]import-route bgp
测试
7,最后一步,配置静态路由并进行重发布直连和静态路由。
[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 b1 192.168.1.0 24 192.168.2.1
[R2]bgp 1
[R2-bgp]ipv4-family vpn-instance b1
[R2-bgp-b1]import-route static
[R2-bgp-b1]import-route direct
[R4]ip route-static vpn-instance b2 192.168.4.0 24 192.168.3.2
[R4]bgp 1
[R4-bgp]ipv4-family vpn-instance b2
[R4-bgp-b2]import-route direct
[R4-bgp-b2]import-route static
[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
测试