广域网技术 · 2026年5月24日 · VirtLab

MPLS VPN 原理与配置:企业广域网连接技术详解

深入讲解 MPLS 技术原理、MPLS VPN 工作机制以及在网络仿真平台中的配置实验。

MPLS VPN 网络架构

MPLS VPN 原理与配置:企业广域网连接技术详解

MPLS VPN 是企业广域网连接的主流技术之一。本文将详细介绍 MPLS 技术原理、MPLS VPN 的工作方式以及在仿真平台中的配置方法。

MPLS 技术基础

MPLS 工作原理

┌─────────────────────────────────────────────────────────┐
│                    MPLS 标签交换                         │
│                                                          │
│  ┌─────┐      ┌─────┐      ┌─────┐      ┌─────┐        │
│  │ CE1 │─────▶│ PE1 │─────▶│  P  │─────▶│ PE2 │─────▶ CE2
│  └──┬──┘      └──┬──┘      └──┬──┘      └──┬──┘        │
│     │            │            │            │             │
│  原始IP   Label:20   Label:30   Label:40   原始IP      │
│  Packet      Push        Swap        Pop    Packet      │
│                                                          │
│  ┌───────────────────────────────────────────────────┐  │
│  │            MPLS 标签结构 (32-bit)                  │  │
│  │  ┌────────┬────────┬────────┬────────┐             │  │
│  │  │Label(20)│EXP(3) │  BS(1) │  TTL(8)│            │  │
│  │  └────────┴────────┴────────┴────────┘             │  │
│  └───────────────────────────────────────────────────┘  │
└─────────────────────────────────────────────────────────┘

MPLS 术语

术语说明
LDPLabel Distribution Protocol,标签分发协议
LSRLabel Switching Router,标签交换路由器
LERLabel Edge Router,标签边缘路由器
LFIBLabel Forwarding Information Base,标签转发表
FIBForwarding Information Base,转发信息库
LIBLabel Information Base,标签信息库

标签分发流程

┌─────────────────────────────────────────────────────────┐
│                    LDP 邻居建立                          │
│                                                          │
│     PE1                        PE2                       │
│   ┌─────┐                    ┌─────┐                   │
│   │     │─── TCP 646 端口 ──▶│     │                   │
│   │ LDP │◀──────────────────│ LDP │                   │
│   │     │                    │     │                   │
│   └──┬──┘                    └──┬──┘                   │
│      │                           │                       │
│  ┌───┴───────────────────────────┴────┐                │
│  │           LDP 会话建立               │                │
│  │                                       │                │
│  │  1. 发现邻居 (Discovery)              │                │
│  │  2. 建立会话 (Session)                │                │
│  │  3. 标签分发 (Advertisement)           │                │
│  │  4. 保持活跃 (Keepalive)               │                │
│  └───────────────────────────────────────┘                │
└─────────────────────────────────────────────────────────┘

MPLS VPN 架构

运营商 VPN 架构

┌─────────────────────────────────────────────────────────┐
│                    MPLS VPN 架构                        │
│                                                          │
│    Site A                              Site B           │
│  ┌────────┐                        ┌────────┐           │
│  │  CE1   │                        │  CE2   │           │
│  └───┬────┘                        └───┬────┘           │
│      │                                 │                 │
│  ┌───┴─────────────────────────────────┴────┐            │
│  │              客户网络 (VRF-A)              │            │
│  │                                             │            │
│  │  ┌───────┐   ┌───────┐   ┌───────┐        │            │
│  │  │ RD    │   │ RT    │   │ MP-BGP│        │            │
│  │  │65001:1│   │Import │   │       │        │            │
│  │  │       │   │65001:1│   │       │        │            │
│  │  └───────┘   └───────┘   └───────┘        │            │
│  └────────────────────────────────────────────┘            │
│                          │                                │
│                     ┌─────┴─────┐                          │
│                     │    PE1    │                          │
│                     │  ( LSR )  │                          │
│                     └─────┬─────┘                          │
│                           │                                │
│                    ┌──────┴──────┐                          │
│                    │   骨干网络   │                          │
│                    │  ( MPLS )   │                          │
│                    └──────┬──────┘                          │
│                           │                                │
│                     ┌─────┴─────┐                          │
│                     │    PE2    │                          │
│                     │  ( LSR )  │                          │
│                     └─────┬─────┘                          │
│                           │                                │
│  ┌────────────────────────────────────────────┐            │
│  │              客户网络 (VRF-A)              │            │
│  │                                             │            │
│  │  ┌───────┐   ┌───────┐   ┌───────┐        │            │
│  │  │ RD    │   │ RT    │   │ MP-BGP│        │            │
│  │  │65001:1│   │Export │   │       │        │            │
│  │  │       │   │65001:1│   │       │        │            │
│  │  └───────┘   └───────┘   └───────┘        │            │
│  └────────────────────────────────────────────┘            │
│                          │                                │
│                      ┌───┴────┐                          │
│                      │  CE2   │                          │
│                      └────────┘                          │
└─────────────────────────────────────────────────────────┘

VRF 概念

VRF(Virtual Routing and Forwarding)是一种在单个物理路由器上创建多个隔离路由表的技术。

组件说明
VRF隔离的路由转发表
RDRoute Distinguisher,路由区分符(64-bit)
RTRoute Target,路由目标(控制路由导入导出)
MP-BGPMulticast Protocol BGP,多协议 BGP

MPLS VPN 配置

PE 路由器配置

基本 MPLS 配置

! PE1 基本配置
hostname PE1
!
ip cef
!
mpls label protocol ldp
mpls ldp router-id Loopback0 force
!
interface Loopback0
 ip address 10.1.1.1 255.255.255.255
!
interface GigabitEthernet0/0
 description to-P-router
 ip address 10.1.12.1 255.255.255.0
 mpls ip
 no shutdown
!
interface GigabitEthernet0/1
 description to-CE1
 ip vrf forwarding CUSTOMER_A
 ip address 192.168.1.1 255.255.255.0
 no shutdown

VRF 配置

! 配置 VRF
ip vrf CUSTOMER_A
 rd 65001:100
 route-target export 65001:100
 route-target import 65001:100
!
! 为 CE 配置 OSPF
router ospf 1 vrf CUSTOMER_A
 network 192.168.1.0 0.0.0.255 area 0
!
! 配置 MP-BGP
router bgp 65001
 bgp router-id 10.1.1.1
 neighbor 10.2.2.2 remote-as 65001
 neighbor 10.2.2.2 update-source Loopback0
 !
 address-family vpnv4
  neighbor 10.2.2.2 activate
  neighbor 10.2.2.2 send-community extended
 exit-address-family
 !
 address-family ipv4 vrf CUSTOMER_A
  redistribute ospf 1
 exit-address-family

P 路由器配置(Transit)

! P 路由器配置
hostname P
!
ip cef
!
mpls label protocol ldp
mpls ldp router-id Loopback0 force
!
interface Loopback0
 ip address 10.3.3.3 255.255.255.255
!
interface GigabitEthernet0/0
 description to-PE1
 ip address 10.1.12.2 255.255.255.0
 mpls ip
 no shutdown
!
interface GigabitEthernet0/1
 description to-PE2
 ip address 10.2.23.2 255.255.255.0
 mpls ip
 no shutdown

CE 路由器配置

! CE1 配置
hostname CE1
!
interface GigabitEthernet0/0
 description to-PE1
 ip address 192.168.1.2 255.255.255.0
 no shutdown
!
router ospf 1
 network 192.168.1.0 0.0.0.255 area 0
 network 10.10.10.0 0.0.0.255 area 0
!
! 或者使用静态路由
! ip route 0.0.0.0 0.0.0.0 192.168.1.1

华为设备配置

# 华为 PE 路由器配置
sysname PE1
#
mpls lsr-id 10.1.1.1
mpls
#
mpls ldp
#
interface LoopBack0
 ip address 10.1.1.1 255.255.255.255
#
interface GigabitEthernet0/0/0
 ip address 10.1.12.1 255.255.255.0
 mpls
 mpls ldp
#
# VRF 配置
ip vpn-instance CUSTOMER_A
 route-distinguisher 65001:100
 vpn-target 65001:100 both
#
interface GigabitEthernet0/0/1
 ip binding vpn-instance CUSTOMER_A
 ip address 192.168.1.1 255.255.255.0
#
# BGP VPN 配置
bgp 65001
 peer 10.2.2.2 as-number 65001
 peer 10.2.2.2 connect-interface LoopBack0
 #
 ipv4-family vpnv4
  peer 10.2.2.2 enable
  peer 10.2.2.2 advertise-community
 #
 ipv4-family vpn-instance CUSTOMER_A
  import-route ospf 1

MPLS VPN 验证

验证命令

! 查看 MPLS 转发表
show mpls forwarding-table

! 查看 LDP 邻居
show mpls ldp neighbor

! 查看 LDP 发现
show mpls ldp discovery

! 查看 VRF 信息
show ip vrf

! 查看 BGP VPNv4 邻居
show bgp vpnv4 all neighbors

! 查看 VPNv4 路由
show bgp vpnv4 all

! 查看 VRF 路由表
show ip route vrf CUSTOMER_A

! 查看标签栈
show mpls forwarding-table labels

输出示例

PE1# show mpls forwarding-table
Local  Label    Outgoing Label    Prefix          Out Interface
16     Pop Label  16             10.3.3.3/32     Gi0/0
17     17        Pop Label       10.2.23.0/24     Gi0/0
18     18        18              10.2.2.2/32      Gi0/0
19     Pop Label  No Label        192.168.1.0/24  Gi0/1

PE1# show bgp vpnv4 all summary
Neighbor        V    AS MsgRcvd MsgSent   TblVer  InQ OutQ Up/Down  State/PfxRcd
10.2.2.2        4 65001   1245   1189        9    0    0 00:32:15        5

MPLS TE 流量工程

基本 TE 配置

! 启用 MPLS TE
mpls traffic-eng tunnels
!
interface GigabitEthernet0/0
 mpls traffic-eng tunnels
 ip rsvp bandwidth percent 75
!
! 配置隧道
interface Tunnel0
 ip unnumbered Loopback0
 tunnel destination 10.2.2.2
 tunnel mode mpls traffic-eng
 tunnel mpls traffic-eng path-option 1 explicit name PRIMARY
!
router isis
 metric-style wide
 mpls traffic-eng router-id Loopback0
 mpls traffic-eng level-1

常见问题排查

问题原因解决方案
LDP 邻居无法建立底层网络不通检查 IGP 和路由
MPLS 标签未分配LDP 未启用在接口下启用 mpls ip
VPN 路由不传递BGP 未建立检查 AS 号和邻居
VRF 路由丢失RD/RT 不匹配检查 RT 配置

总结

MPLS VPN 是构建企业广域网的重要技术。通过本文的学习,您已经掌握了 MPLS 的工作原理和 MPLS VPN 的配置方法。建议在仿真平台中多练习,特别是多厂商环境的配置。

#MPLS #VPN #LDP #VRF #BGP #广域网