r1
GigabitEthernet0/0/0 192.168.2.1/24 up up
GigabitEthernet0/0/1 unassigned down down
GigabitEthernet0/0/2 unassigned down down
LoopBack0 192.168.1.1/24 up up(s)
r2
GigabitEthernet0/0/0 192.168.2.2/24 up up
GigabitEthernet0/0/1 192.168.2.2/24 up up
GigabitEthernet0/0/2 23.1.1.1/24 up up
LoopBack0 2.2.2.2/24 up up(s)
r3
GigabitEthernet0/0/0 23.1.1.2/24 up up
GigabitEthernet0/0/1 34.1.1.1/24 up up
GigabitEthernet0/0/2 unassigned down down
LoopBack0 3.3.3.3/24 up up(s)
r4
GigabitEthernet0/0/0 34.1.1.2/24 up up
GigabitEthernet0/0/1 192.168.3.2/24 up up
GigabitEthernet0/0/2 unassigned up down
GigabitEthernet4/0/0 192.168.3.2/24 up up
LoopBack0 4.4.4.4/24 up up(s)
r5
GigabitEthernet0/0/0 192.168.3.1/24 up up
GigabitEthernet0/0/1 unassigned down down
GigabitEthernet0/0/2 unassigned down down
LoopBack0 192.168.4.1/24 up up(s)
r2
ip vpn-instance aa
ipv4-family
route-distinguisher 1:1
vpn-target 1:1 export-extcommunity
vpn-target 1:1 import-extcommunity
interface GigabitEthernet0/0/0
ip binding vpn-instance aa
ip address 192.168.2.2 255.255.255.0
ipv4-family vpn-instance aa
import-route direct
import-route static
ip route-static vpn-instance aa 192.168.1.0 255.255.255.0 192.168.2.1
r4
ip vpn-instance aa
ipv4-family
route-distinguisher 1:1
vpn-target 1:1 export-extcommunity
vpn-target 1:1 import-extcommunity
interface GigabitEthernet0/0/1
ip binding vpn-instance aa
ip address 192.168.3.2 255.255.255.0
ipv4-family vpn-instance aa
import-route direct
import-route static
ip route-static vpn-instance aa 192.168.4.0 255.255.255.0 192.168.3.1
ce端
ip route-static 192.168.3.0 255.255.255.0 192.168.2.2
ip route-static 192.168.4.0 255.255.255.0 192.168.2.2
r2
ip vpn-instance b
ipv4-family
route-distinguisher 1:2
vpn-target 1:1 2:2 export-extcommunity
vpn-target 1:1 2:2 import-extcommunity
interface GigabitEthernet0/0/1
ip binding vpn-instance b
ip address 192.168.2.2 255.255.255.0
rip 1 vpn-instance b
network 192.168.0.0
import-route bgp
ip vpn-instance b
ipv4-family
route-distinguisher 1:2
vpn-target 2:2 export-extcommunity
vpn-target 2:2 import-extcommunity
interface GigabitEthernet4/0/0
ip binding vpn-instance b
ip address 192.168.3.2 255.255.255.0
ipv4-family vpn-instance b
import-route ospf 2
ospf 2 vpn-instance b
import-route bgp
area 0.0.0.0
network 192.168.3.1 0.0.0.0
B路由表
[Huawei]display bgp vpnv4 vpn-instance b routing-table
BGP Local router ID is 23.1.1.1
Status codes: * - valid, > - best, d - damped,
h - history, i - internal, s - suppressed, S - Stale
Origin : i - IGP, e - EGP, ? - incomplete
VPN-Instance b, Router ID 23.1.1.1:
Total Number of Routes: 5
Network NextHop MED LocPrf PrefVal Path/Ogn
*> 192.168.1.0 192.168.2.1 0 0 ?
*> 192.168.2.0 192.168.2.2 0 0 ?
*> 192.168.2.2/32 127.0.0.1 0 0 ?
*>i 192.168.3.0 4.4.4.4 0 100 0 ?
*>i 192.168.4.0 4.4.4.4 0 100 0 ?
r7可以访问公网环回
[r7]ip route-static 0.0.0.0 0 47.0.0.1
测试
<Huawei>ping 192.168.4.1
PING 192.168.4.1: 56 data bytes, press CTRL_C to break
Reply from 192.168.4.1: bytes=56 Sequence=1 ttl=252 time=60 ms
Reply from 192.168.4.1: bytes=56 Sequence=2 ttl=252 time=80 ms
Reply from 192.168.4.1: bytes=56 Sequence=3 ttl=252 time=70 ms
Reply from 192.168.4.1: bytes=56 Sequence=4 ttl=252 time=50 ms
Reply from 192.168.4.1: bytes=56 Sequence=5 ttl=252 time=70 ms
--- 192.168.4.1 ping statistics ---
5 packet(s) transmitted
5 packet(s) received
0.00% packet loss
round-trip min/avg/max = 50/66/80 ms
测试
<r6>ping 192.168.4.1
PING 192.168.4.1: 56 data bytes, press CTRL_C to break
Reply from 192.168.4.1: bytes=56 Sequence=1 ttl=252 time=60 ms
Reply from 192.168.4.1: bytes=56 Sequence=2 ttl=252 time=80 ms
Reply from 192.168.4.1: bytes=56 Sequence=3 ttl=252 time=70 ms
Reply from 192.168.4.1: bytes=56 Sequence=4 ttl=252 time=50 ms
Reply from 192.168.4.1: bytes=56 Sequence=5 ttl=252 time=70 ms
--- 192.168.4.1 ping statistics ---
5 packet(s) transmitted
5 packet(s) received
0.00% packet loss
round-trip min/avg/max = 50/66/80 ms