这是一篇合作实验文章,由 LittleWolf 与 Jamesits 共同完成。本文演示如何完全基于开源 Debian Linux + FRRouting(FRR) 构建一套完整的 MPLS L3VPN 运营商级实验网络。
MPLS 是一种工作在 2.5 层的标签交换技术。早期 IP 转发主要依赖软件执行逐跳最长前缀匹配,查表开销较大;引入 MPLS 后,核心路由器只需检索简洁的标签转发表(LFIB)即可完成转发。如今随着硬件 ASIC 转发普及,纯 MPLS 提速的意义已经弱化,但基于 MPLS 灵活扩展出来的 BGP/MPLS L3VPN、流量工程(TE)等业务架构依然是运营商网络的核心基石。
为什么用 Debian Linux + FRR 学习 MPLS L3VPN?
MPLS VPN 的出现主要是为了解决传统 VPN 技术的一些固有缺陷,其中最重要的是地址重叠的问题。必须有一种技术可以保证不同的用户 VPN 可以使用相同的私有地址空间,而且可以在公共的骨干网络上互相不影响地交换数据。
新华三官网 — L3 VPN 基础
商业平台(如 Cisco IOS-XE、Juniper vMX)虽然具备成熟的 MPLS L3VPN 能力,但正版授权费用动辄数万元,对个人学习者门槛较高。借助 Linux 内核原生 MPLS 模块与开源路由套件 FRRouting(FRR),我们无需任何商业授权即可在 EVE-NG 或 KVM 中搭建高度仿真的 VPNv4 网络。
实验拓扑与重叠网段规划
编译安装 FRRouting 并在 sysctl 中开启内核 MPLS 模块(Debian 默认内核已自带)的具体步骤,可参考 Jamesits 撰写的前置教程:《使用 Linux 作为 MPLS 路由器》。
由于 Linux 的 Persistent Net Device Naming 命名机制,EVE-NG 拓扑中的 e0、e1、e2 接口在 Debian 系统内分别对应 ens3、ens4、ens5。
一、配置 Underlay IGP:IS-IS Level-2 骨干域
在内核层面配好接口 IP 地址后,使用 vtysh 配置 IS-IS Level-2 作为 Underlay IGP(相比 OSPF,IS-IS 更适用于大型运营商骨干网):
#P interface dummy0 ip router isis 1 ! interface ens3 ip router isis 1 isis circuit-type level-2-only ! interface ens4 ip router isis 1 isis circuit-type level-2-only ! interface ens5 ip router isis 1 isis circuit-type level-2-only ! router isis 1 is-type level-2-only net 47.0000.0000.0000.0001.00 #PE1 interface dummy0 ip router isis 1 isis circuit-type level-2-only ! interface ens3 ip router isis 1 isis circuit-type level-2-only ! router isis 1 is-type level-2-only net 47.0000.0000.0000.0002.00 #PE2 interface dummy0 ip router isis 1 isis circuit-type level-2-only ! interface ens3 ip router isis 1 isis circuit-type level-2-only ! router isis 1 is-type level-2-only net 47.0000.0000.0000.0003.00 #RR interface dummy0 ip router isis 1 isis circuit-type level-2-only ! interface ens3 ip router isis 1 isis circuit-type level-2-only ! router isis 1 is-type level-2-only net 47.0000.0000.0000.0004.00
在核心路由器 P 上检查 IS-IS 邻居与路由表,确认骨干网环回口全网可达:
localhost# show ip route isis
Codes: K - kernel route, C - connected, S - static, R - RIP,
O - OSPF, I - IS-IS, B - BGP, E - EIGRP, N - NHRP,
T - Table, v - VNC, V - VNC-Direct, A - Babel, D - SHARP,
F - PBR, f - OpenFabric,
> - selected route, * - FIB route, q - queued route, r - rejected route
I>* 10.0.0.1/32 [115/20] via 192.168.2.1, ens4, 00:05:18
I>* 10.0.0.3/32 [115/20] via 192.168.3.2, ens5, 00:03:04
I>* 10.0.0.4/32 [115/20] via 192.168.1.1, ens3, 00:17:05
I 192.168.1.0/24 [115/20] via 192.168.1.1, ens3 inactive, 00:17:05
I 192.168.2.0/24 [115/20] via 192.168.2.1, ens4 inactive, 00:05:18
I 192.168.3.0/24 [115/20] via 192.168.3.2, ens5 inactive, 00:03:04
localhost# show isis neighbor
Area 1:
System Id Interface L State Holdtime SNPA
localhost ens3 2 Up 29 0050.0100.0800
localhost ens4 2 Up 29 0050.0100.0300
localhost ens5 2 Up 29 0050.0100.0600
二、开启 Linux 内核 MPLS 输入与 FRR LDP 信令
接下来在所有骨干节点上通过 sysctl 开启对应物理接口的 MPLS 报文接收开关,并在 FRR 中启用 mpls ldp(注意下述第 4 组为路由反射器 RR 10.0.0.4):
#P sysctl net.mpls.conf.ens3.input=1 sysctl net.mpls.conf.ens4.input=1 sysctl net.mpls.conf.ens5.input=1 #vtysh.cli mpls ldp router-id 10.0.0.2 address-family ipv4 discovery transport-address 10.0.0.2 interface ens3 interface ens4 interface ens5 #PE1 sysctl net.mpls.conf.ens3.input=1 #vtysh.cli mpls ldp router-id 10.0.0.1 address-family ipv4 discovery transport-address 10.0.0.1 interface ens3 #PE2 sysctl net.mpls.conf.ens3.input=1 #vtysh.cli mpls ldp router-id 10.0.0.3 address-family ipv4 discovery transport-address 10.0.0.3 interface ens3 #RR (10.0.0.4) sysctl net.mpls.conf.ens3.input=1 #vtysh.cli mpls ldp router-id 10.0.0.4 address-family ipv4 discovery transport-address 10.0.0.4 interface ens3
在核心路由器 P 上检查 LDP 邻居表,确认 3 个会话均为 OPERATIONAL:
localhost# show mpls ldp nei AF ID State Remote Address Uptime ipv4 10.0.0.1 OPERATIONAL 10.0.0.1 00:01:53 ipv4 10.0.0.3 OPERATIONAL 10.0.0.3 00:00:05 ipv4 10.0.0.4 OPERATIONAL 10.0.0.4 00:00:46
三、配置 iBGP VPNv4 路由反射器与 PE 会话
由于骨干节点属于同一个自治域(AS 65000),我们采用 iBGP + Route Reflector(RR) 架构部署 MP-BGP VPNv4。核心 P 路由器不运行 BGP,仅基于 MPLS 标签高速转发:
#RR #vtysh.cli router bgp 65000 no bgp default ipv4-unicast neighbor 10.0.0.1 remote-as 65000 neighbor 10.0.0.1 update-source dummy0 neighbor 10.0.0.3 remote-as 65000 neighbor 10.0.0.3 update-source dummy0 address-family ipv4 vpn neighbor 10.0.0.1 activate neighbor 10.0.0.1 route-reflector-client neighbor 10.0.0.3 activate neighbor 10.0.0.3 route-reflector-client #PE1 & PE2 #vtysh.cli router bgp 65000 no bgp default ipv4-unicast neighbor 10.0.0.4 remote-as 65000 neighbor 10.0.0.4 update-source dummy0 address-family ipv4 vpn neighbor 10.0.0.4 activate
注:本实验拓扑不涉及全局 IPv4 公网路由传递,因此关闭了默认的 ipv4-unicast 地址族;但在生产环境中,通常仍会按规范显式规划所需地址族。配置完成后在 RR 上核对 VPNv4 会话状态:
#RR #vtysh.cli localhost# show bgp summary IPv4 VPN Summary: BGP router identifier 192.168.1.1, local AS number 65000 vrf-id 0 BGP table version 0 RIB entries 0, using 0 bytes of memory Peers 2, using 41 KiB of memory Neighbor V AS MsgRcvd MsgSent TblVer InQ OutQ Up/Down State/PfxRcd 10.0.0.1 4 65000 4 4 0 0 0 00:01:08 0 10.0.0.3 4 65000 3 3 0 0 0 00:00:37 0 Total number of neighbors 2
四、配置 Linux 内核 VRF 设备与 FRR VPNv4 导入导出
在 Debian Linux 上,VRF 是通过 iproute2 创建独立的 VRF 虚拟路由设备并绑定独立路由表(table 100、table 200)实现的。注意 PE1 两侧连接 blue 和 red 客户时甚至使用了完全相同的接口网段 10.10.1.1/24,而 PE2 同样使用 10.10.2.1/24,这正是 VRF 隔离能力的直观体现:
#PE1 # linux shell # VRF BLUE ip link add blue type vrf table 100 ip link set blue up ip route add vrf blue unreachable default metric 4278198272 ip link set ens4 vrf blue ip link set ens4 up ip addr add 10.10.1.1/24 dev ens4 # VRF RED ip link add red type vrf table 200 ip link set red up ip route add vrf red unreachable default metric 4278198272 ip link set ens5 vrf red ip link set ens5 up ip addr add 10.10.1.1/24 dev ens5 #PE2 #Linux shell #VRF RED ip link add red type vrf table 200 ip link set red up ip route add vrf red unreachable default metric 4278198272 ip link set ens4 vrf red ip link set ens4 up ip addr add 10.10.2.1/24 dev ens4 #VRF BLUE ip link add blue type vrf table 100 ip link set blue up ip route add vrf blue unreachable default metric 4278198272 ip link set ens5 vrf blue ip link set ens5 up ip addr add 10.10.2.1/24 dev ens5
客户侧边缘路由器已预配置好与 PE 的 eBGP 会话并宣告了各自内网网段(Customer-Blue 为私网 AS 65531,Customer-Red 为私网 AS 65530)。下面在 PE1 和 PE2 的 FRR 中配置 VRF 实例下的 eBGP 邻居以及 export vpn / import vpn(配置过程中若遇到 zebra 临时告警,可通过 show run 核对配置是否已成功写入):
#PE1 #vtysh.cli router bgp 65000 vrf blue neighbor 10.10.1.2 remote-as 65531 bgp router-id 10.10.1.1 ! address-family ipv4 unicast label vpn export auto rd vpn export 65000:100 rt vpn both 65000:100 export vpn import vpn exit-address-family ! router bgp 65000 vrf red neighbor 10.10.1.2 remote-as 65530 bgp router-id 10.10.1.1 ! address-family ipv4 unicast label vpn export auto rd vpn export 65000:200 rt vpn both 65000:200 export vpn import vpn exit-address-family #PE2 #vtysh.cli router bgp 65000 vrf blue bgp router-id 10.10.2.1 neighbor 10.10.2.2 remote-as 65531 ! address-family ipv4 unicast label vpn export auto rd vpn export 65000:100 rt vpn both 65000:100 export vpn import vpn exit-address-family ! router bgp 65000 vrf red bgp router-id 10.10.2.1 neighbor 10.10.2.2 remote-as 65530 ! address-family ipv4 unicast label vpn export auto rd vpn export 65000:200 rt vpn both 65000:200 export vpn import vpn exit-address-family
在 PE1 与 PE2 上使用 show ip bgp vrf all summary 验证各实例下的 BGP 邻居与路由接收数量:
#PE1 localhost# show ip bgp vrf all summary Instance default: IPv4 VPN Summary: BGP router identifier 192.168.2.1, local AS number 65000 vrf-id 0 BGP table version 0 RIB entries 5, using 920 bytes of memory Peers 1, using 20 KiB of memory Neighbor V AS MsgRcvd MsgSent TblVer InQ OutQ Up/Down State/PfxRcd 10.0.0.4 4 65000 82 80 0 0 0 01:13:17 2 Total number of neighbors 1 Instance blue: IPv4 Unicast Summary: BGP router identifier 10.10.1.1, local AS number 65000 vrf-id 9 BGP table version 2 RIB entries 3, using 552 bytes of memory Peers 1, using 20 KiB of memory Neighbor V AS MsgRcvd MsgSent TblVer InQ OutQ Up/Down State/PfxRcd 10.10.1.2 4 65531 31 26 0 0 0 00:20:18 1 Total number of neighbors 1 Instance red: IPv4 Unicast Summary: BGP router identifier 10.10.1.1, local AS number 65000 vrf-id 10 BGP table version 4 RIB entries 3, using 552 bytes of memory Peers 1, using 20 KiB of memory Neighbor V AS MsgRcvd MsgSent TblVer InQ OutQ Up/Down State/PfxRcd 10.10.1.2 4 65530 37 30 0 0 0 00:18:32 1 Total number of neighbors 1 #PE2 localhost# show ip bgp vrf all su Instance default: IPv4 VPN Summary: BGP router identifier 192.168.3.2, local AS number 65000 vrf-id 0 BGP table version 0 RIB entries 5, using 920 bytes of memory Peers 1, using 20 KiB of memory Neighbor V AS MsgRcvd MsgSent TblVer InQ OutQ Up/Down State/PfxRcd 10.0.0.4 4 65000 80 76 0 0 0 01:11:57 2 Total number of neighbors 1 Instance blue: IPv4 Unicast Summary: BGP router identifier 10.10.2.1, local AS number 65000 vrf-id 10 BGP table version 1 RIB entries 1, using 184 bytes of memory Peers 1, using 20 KiB of memory Neighbor V AS MsgRcvd MsgSent TblVer InQ OutQ Up/Down State/PfxRcd 10.10.2.2 4 65531 11 8 0 0 0 00:05:43 1 Total number of neighbors 1 Instance red: IPv4 Unicast Summary: BGP router identifier 10.10.2.1, local AS number 65000 vrf-id 9 BGP table version 2 RIB entries 3, using 552 bytes of memory Peers 1, using 20 KiB of memory Neighbor V AS MsgRcvd MsgSent TblVer InQ OutQ Up/Down State/PfxRcd 10.10.2.2 4 65530 11 9 0 0 0 00:05:43 1 Total number of neighbors 1
五、排查同 AS 客户站点路由丢失:as-override 机制
此时我们抽查客户侧的 ShenZhen-Edge,却发现 BGP 表中只有本地宣告的 172.19.1.0/24,并没有收到厦门站点发来的 172.19.2.0/24:
#ShenZhen-Edge
Router#show ip bgp
Network Next Hop Metric LocPrf Weight Path
*> 172.19.1.0/24 0.0.0.0 0 32768 i
原因在于 BGP 的 eBGP 防环机制。观察 172.19.2.0/24 的 AS_PATH 路径:AS 65531 <- AS 65000 <- AS 65531 i。当深圳路由器收到路径中已包含自身 ASN(65531)的路由更新时,会将其判定为环路并直接丢弃。解决这一问题有两种常见思路:
- CE 侧配置
allowas-in:允许接收路径中含自身 ASN 的路由,放宽了防环检查,存在一定环路风险; - PE 侧配置
as-override:由运营商 PE 在发送路由给 CE 时,将 AS_PATH 中相同的客户 ASN 替换为运营商自己的 ASN(65000),既保留环路防护又完美解决多点同 AS 互访。
因此我们在 PE1 和 PE2 的两个 VRF 邻居中启用 as-override:
#PE1 #vtysh.cli router bgp 65000 vrf blue ! address-family ipv4 unicast neighbor 10.10.1.2 as-override exit-address-family ! router bgp 65000 vrf red ! address-family ipv4 unicast neighbor 10.10.1.2 as-override exit-address-family #PE2 #vtysh.cli router bgp 65000 vrf blue ! address-family ipv4 unicast neighbor 10.10.2.2 as-override exit-address-family ! router bgp 65000 vrf red ! address-family ipv4 unicast neighbor 10.10.2.2 as-override exit-address-family
配置生效后再次查看 ShenZhen-Edge 的 BGP 表,远端路由 172.19.2.0/24 已被正常接收,AS_PATH 变为 65000 65000 i:
#Shenzhen-edge
Router#show ip bgp
BGP table version is 5, local router ID is 172.19.1.1
Network Next Hop Metric LocPrf Weight Path
*> 172.19.1.0/24 0.0.0.0 0 32768 i
*> 172.19.2.0/24 10.10.1.1 0 0 65000 65000 i
六、重叠地址端到端通信与隔离验证(nc 实测)
最后在四台末端 Linux 主机上使用 nc 对同一目标 IP 与端口 172.19.2.2:8888 发起 TCP 通信测试,验证 VRF Blue(Linux9 深圳 → Linux12 厦门) 与 VRF Red(Linux11 北京 → Linux10 四川) 虽使用完全相同的私有网段,数据依然准确送达各自对应租户且互不干扰:
# Linux9 (Customer-Blue, ShenZhen) -> Linux12 (Customer-Blue, Xiamen) root@localhost:~# echo "This is VRF BLUE shenzhen" This is VRF BLUE shenzhen root@localhost:~# nc 172.19.2.2 8888 message from VRF BLUE, shenzhen edge # Linux12 (Listening in VRF BLUE) root@localhost:~# echo "This is VRF BLUE xiamen" This is VRF BLUE xiamen root@localhost:~# nc -l -p 8888 message from VRF BLUE, shenzhen edge # Linux11 (Customer-Red, Beijing) -> Linux10 (Customer-Red, Sichuan) root@localhost:~# echo "This is VRF RED beijing" This is VRF RED beijing root@localhost:~# nc 172.19.2.2 8888 message from VRF RED, beijing edge # Linux10 (Listening in VRF RED) root@localhost:~# echo "This is VRF RED sichuan" This is VRF RED sichuan root@localhost:~# nc -l -p 8888 message from VRF RED, beijing edge
可以看到两端重叠子网中的数据均已准确隔离并送达对应租户节点,基于 Debian Linux + FRR 的 MPLS L3VPN 网络搭建完成。在此再次感谢 Jamesits 的协作与技术支持。
参考资料
- 《使用 Linux 作为 MPLS 路由器》 — Jamesits
- 《MPLS 及 LDP 协议基础》 — 新华三官网
- 《L3 VPN 基础》 — 新华三官网