1、Mpls vpn 配置实例一.建立 MPLS 域(配置 PE 与 P 之间的 IGP和 MPLS)1.分别在 R2.R3.R4.R5 开启 OSPF 协议分配到 area 0,进入各接口开启 mpls ip,保证 R2 的 loopback 0 地址与 R5 的loopback 0 地址可以互访。R2配置Router#conf tRouter(config)#router ospf 1Router(config-router)#router-id 2.2.2.2Router(config-router)#network 2.2.2.2 0.0.0.0 area 0Router(config-r
2、outer)#network 10.1.23.0 0.0.0.255 area 0Router(config-router)#mpls ldp autoconfigR3配置Router#conf tRouter(config)#router ospf 1Router(config-router)#router-id 3.3.3.3Router(config-router)#network 0.0.0.0 0.0.0.0 area 0Router(config-router)#mpls ldp autoconfigR4配置Router#conf tRouter(config)#router os
3、pf 1Router(config-router)#router-id 4.4.4.4Router(config-router)#network 0.0.0.0 0.0.0.0 area 0Router(config-router)#mpls ldp autoconfigR5配置Router#conf tRouter(config)#router ospf 1Router(config-router)#router-id 5.5.5.5Router(config-router)#network 5.5.5.5 0.0.0.0 area 0Router(config-router)#networ
4、k 10.1.45.0 0.0.0.255 area 0Router(config-router)#mpls ldp autoconfig二.MPLS VPN 部署1 配置 PE 与 CE 之间的路由协议1.接入点使用 rip v2 路由协议接入R2配置R2(config)#ip vrf A /定义 VRF(接入用户名字)R2(config-vrf)#rd 1:100 /定义 RD(区分客户路由 ,不同客户分配不同 RD)R2(config-vrf)#route-target 1:100 /定义 RT(对接 VPN)R2(config)#interface f0/1 /进入 PE链接 CE接口
5、R2(config-if)#ip vrf forwarding A /把接口放入 VRF虚拟环境R5配置R5(config)#ip vrf A /定义 VRF(接入用户名字)R5(config-vrf)#rd 1:100 /定义 RD(区分客户路由 ,不同客户分配不同 RD)R5(config-vrf)#route-target 1:100 /定义 RT(对接 VPN)R5(config)#interface f0/1 /进入 PE链接 CE接口R5(config-if)#ip vrf forwarding A /把接口放入 VRF虚拟环境配置 R1 与 R2 要互相学习路由R1配置R2配置R
6、2(config)#router ripR2(config-router)#version 2R2(config-router)#no auto-summaryR2(config-router)#address-family ipv4 vrf AR2(config-router-af)#network 192.168.1.0配置完后确保 R2 可以学到到 R1 的路由配置 R5 与 R6 要互相学习路由R6配置R5配置R5(config)#router ripR5(config-router)#version 2R5(config-router)#no auto-summaryR5(confi
7、g-router)#address-family ipv4 vrf AR5(config-router-af)#network 192.168.2.0配置完后确保 R5可以学到 R6的路由信息2.接入点使用静态路由接入R2配置R2(config)#ip vrf A /定义 VRF(接入用户名字)R2(config-vrf)#rd 1:200 /定义 RD(区分客户路由 ,不同客户分配不同 RD)R2(config-vrf)#route-target 1:200 /定义 RT(对接 VPN)R2(config)#interface f0/1 /进入 PE链接 CE接口R2(config-if)#
8、ip vrf forwarding B /把接口放入 VRF虚拟环境R5配置R5(config)#ip vrf A /定义 VRF(接入用户名字)R5(config-vrf)#rd 1:200 /定义 RD(区分客户路由 ,不同客户分配不同 RD)R5(config-vrf)#route-target 1:200 /定义 RT(对接 VPN)R5(config)#interface f0/1 /进入 PE链接 CE接口R5(config-if)#ip vrf forwarding B /把接口放入 VRF虚拟环境R2 静态路由配置Router(config)#ip route vrf B 7.
9、7.7.7 255.255.255.255 192.168.3.7R5 静态路由配置Router(config)#ip route vrf B 8.8.8.8 255.255.255.255 192.168.4.83.接入点使用 OSPF 路由协议接入(R7 和 R8 清空静态路由)R2配置R2(config)#ip vrf C /定义 VRF(接入用户名字)R2(config-vrf)#rd 1:300 /定义 RD(区分客户路由 ,不同客户分配不同 RD)R2(config-vrf)#route-target 1:300 /定义 RT(对接 VPN)R2(config)#interface
10、 f0/1 /进入 PE链接 CE接口R2(config-if)#ip vrf forwarding C /把接口放入 VRF虚拟环境R5配置R5(config)#ip vrf C /定义 VRF(接入用户名字)R5(config-vrf)#rd 1:300 /定义 RD(区分客户路由 ,不同客户分配不同 RD)R5(config-vrf)#route-target 1:300 /定义 RT(对接 VPN)R5(config)#interface f0/1 /进入 PE链接 CE接口R5(config-if)#ip vrf forwarding C /把接口放入 VRF虚拟环境R7配置 OSP
11、F路由协议Router(config)#router ospf 2Router(config-router)#router-id 7.7.7.7Router(config-router)#network 0.0.0.0 0.0.0.0 area 0在 R2上输入,可以成功学到 R7的路由Router#show ip route vrf CRouting Table: CCodes: C - connected, S - static, R - RIP, M - mobile, B - BGPD - EIGRP, EX - EIGRP external, O - OSPF, IA - OSPF
12、inter area N1 - OSPF NSSA external type 1, N2 - OSPF NSSA external type 2E1 - OSPF external type 1, E2 - OSPF external type 2i - IS-IS, su - IS-IS summary, L1 - IS-IS level-1, L2 - IS-IS level-2ia - IS-IS inter area, * - candidate default, U - per-user static routeo - ODR, P - periodic downloaded st
13、atic routeGateway of last resort is not set7.0.0.0/32 is subnetted, 1 subnetsO 7.7.7.7 110/2 via 192.168.3.7, 00:01:15, FastEthernet0/2C 192.168.3.0/24 is directly connected, FastEthernet0/2R8配置 OSPF路由协议Router(config)#router ospf 2Router(config-router)#router-id 8.8.8.8Router(config-router)#network
14、0.0.0.0 0.0.0.0 area 0在 R5 上输入,可以成功学到 R8 的路由Router#show ip route vrf CRouting Table: CCodes: C - connected, S - static, R - RIP, M - mobile, B - BGPD - EIGRP, EX - EIGRP external, O - OSPF, IA - OSPF inter area N1 - OSPF NSSA external type 1, N2 - OSPF NSSA external type 2E1 - OSPF external type 1,
15、E2 - OSPF external type 2i - IS-IS, su - IS-IS summary, L1 - IS-IS level-1, L2 - IS-IS level-2ia - IS-IS inter area, * - candidate default, U - per-user static routeo - ODR, P - periodic downloaded static routeGateway of last resort is not set8.0.0.0/32 is subnetted, 1 subnetsO 8.8.8.8 110/2 via 192
16、.168.4.8, 00:03:34, FastEthernet0/2C 192.168.4.0/24 is directly connected, FastEthernet0/22 配置 PE 与 PE 之间的 MP-BGP(R2 和 R5 要互相学习路由)R2配置R2(config)#router bgp 1R2(config-router)#no synchronizationR2(config-router)#no auto-summaryR2(config-router)#bgp router-id 2.2.2.2R2(config-router)#neighbor 5.5.5.5
17、remote-as 1R2(config-router)#neighbor 5.5.5.5 update-source loopback 0R2(config-router)#address-family vpnv4R2(config-router-af)#neighbor 5.5.5.5 activateR2(config-router-af)#neighbor 5.5.5.5 send-communityR5配置R5(config)#router bgp1R5(config-router)#no synchronizationR5(config-router)#no auto-summar
18、yR5(config-router)#bgp router-id 5.5.5.5R5(config-router)#neighbor 2.2.2.2 remote-as 1R5(config-router)#neighbor 2.2.2.2 update-source loopback 0R5(config-router)#address-family vpnv4R5(config-router-af)#neighbor 2.2.2.2 activateR5(config-router-af)#neighbor 2.2.2.2 send-community3.配置 PE 与 BGP 与 IGP
19、 的路由重分发1.接入点使用 rip v2 路由协议接入配置R2 配置(把 R1 的 RIP 导入到 R2 的 BGP)Router(config)#router bgp 1Router(config-router)#address-family ipv4 vrf ARouter(config-router-af)#redistribute rip metric 5Router#show ip bgp vpnv4 allBGP table version is 5, local router ID is 2.2.2.2Status codes: s suppressed, d damped,
20、h history, * valid, best, i - internal,r RIB-failure, S StaleOrigin codes: i - IGP, e - EGP, ? - incompleteNetwork Next Hop Metric LocPrf Weight PathRoute Distinguisher: 1:100 (default for vrf A)* 1.1.1.1/32 192.168.1.1 5 32768 ?* 192.168.1.0 0.0.0.0 0 32768 ?R5 配置(bgp 导入 rip)Router(config)#router r
21、ipRouter(config-router)#address-family ipv4 vrf ARouter(config-router-af)#redistribute bgp 1 metric transparent做完后 R6 可以学到 R1 的路由Router#show ip route Codes: C - connected, S - static, R - RIP, M - mobile, B - BGPD - EIGRP, EX - EIGRP external, O - OSPF, IA - OSPF inter area N1 - OSPF NSSA external t
22、ype 1, N2 - OSPF NSSA external type 2E1 - OSPF external type 1, E2 - OSPF external type 2i - IS-IS, su - IS-IS summary, L1 - IS-IS level-1, L2 - IS-IS level-2ia - IS-IS inter area, * - candidate default, U - per-user static routeo - ODR, P - periodic downloaded static routeGateway of last resort is
23、not set1.0.0.0/32 is subnetted, 1 subnetsR 1.1.1.1 120/6 via 192.168.2.5, 00:00:01, FastEthernet0/16.0.0.0/32 is subnetted, 1 subnetsC 6.6.6.6 is directly connected, Loopback0R 192.168.1.0/24 120/1 via 192.168.2.5, 00:00:01, FastEthernet0/1C 192.168.2.0/24 is directly connected, FastEthernet0/1R5 配置
24、Router(config)#router bgp 1Router(config-router)#address-family ipv4 vrf ARouter(config-router-af)#redistribute rip metric 5R2 配置Router(config)#router ripRouter(config-router)#address-family ipv4 vrf ARouter(config-router-af)#redistribute bgp 1 metric transparent完成后 R1 可以学习到 R6 的路由Router#show ip rou
25、te Codes: C - connected, S - static, R - RIP, M - mobile, B - BGPD - EIGRP, EX - EIGRP external, O - OSPF, IA - OSPF inter area N1 - OSPF NSSA external type 1, N2 - OSPF NSSA external type 2E1 - OSPF external type 1, E2 - OSPF external type 2i - IS-IS, su - IS-IS summary, L1 - IS-IS level-1, L2 - IS
26、-IS level-2ia - IS-IS inter area, * - candidate default, U - per-user static routeo - ODR, P - periodic downloaded static routeGateway of last resort is not set1.0.0.0/32 is subnetted, 1 subnetsC 1.1.1.1 is directly connected, Loopback06.0.0.0/32 is subnetted, 1 subnetsR 6.6.6.6 120/6 via 192.168.1.
27、2, 00:00:14, FastEthernet0/1C 192.168.1.0/24 is directly connected, FastEthernet0/1R 192.168.2.0/24 120/1 via 192.168.1.2, 00:00:14, FastEthernet0/12.接入点使用静态路由接入R2 配置Router(config)#router bgp 1Router(config-router)#address-family ipv4 vrf BRouter(config-router-af)#redistribute static完后可学到 R7 路由Route
28、r#show ip bgp vpnv4 allBGP table version is 13, local router ID is 2.2.2.2Status codes: s suppressed, d damped, h history, * valid, best, i - internal,r RIB-failure, S StaleOrigin codes: i - IGP, e - EGP, ? - incompleteNetwork Next Hop Metric LocPrf Weight PathRoute Distinguisher: 1:100 (default for
29、 vrf A)* 1.1.1.1/32 192.168.1.1 5 32768 ?*i6.6.6.6/32 5.5.5.5 5 100 0 ?* 192.168.1.0 0.0.0.0 0 32768 ?*i192.168.2.0 5.5.5.5 0 100 0 ?Route Distinguisher: 1:200 (default for vrf B)* 7.7.7.7/32 192.168.3.7 0 32768 ?R5 配置Router(config)#router bgp 1Router(config-router)#address-family ipv4 vrf BRouter(c
30、onfig-router-af)#redistribute static完后可学到 R8 路由Router#show ip bgp vpnv4 allBGP table version is 13, local router ID is 2.2.2.2Status codes: s suppressed, d damped, h history, * valid, best, i - internal,r RIB-failure, S StaleOrigin codes: i - IGP, e - EGP, ? - incompleteNetwork Next Hop Metric LocPr
31、f Weight PathRoute Distinguisher: 1:100 (default for vrf A)* 1.1.1.1/32 192.168.1.1 5 32768 ?*i6.6.6.6/32 5.5.5.5 5 100 0 ?* 192.168.1.0 0.0.0.0 0 32768 ?*i192.168.2.0 5.5.5.5 0 100 0 ?Route Distinguisher: 1:200 (default for vrf B)* 7.7.7.7/32 192.168.3.7 0 32768 ?*i8.8.8.8/32 5.5.5.5 0 100 0 ?3.接入点
32、使用 OSPF 路由协议接入(R7 和 R8 清空静态路由)R2 配置Router(config)#router bgp 1Router(config-router)#address-family ipv4 vrf CRouter(config-router-af)#redistribute ospf 2 match internal externalRouter(config)#router ospf 2 vrf CRouter(config-router)#redistribute bgp 1 subnetsR5 配置Router(config)#router bgp 1Router(co
33、nfig-router)#address-family ipv4 vrf CRouter(config-router-af)#redistribute ospf 2 match internal externalRouter(config)#router ospf 2 vrf CRouter(config-router)#redistribute bgp 1 subnets在 R7 上输入,可看到 R7 成功学习到 R8 路由Router#show ip route ospf8.0.0.0/32 is subnetted, 1 subnetsO IA 8.8.8.8 110/3 via 192
34、.168.3.2, 00:00:52, FastEthernet0/2O IA 192.168.4.0/24 110/2 via 192.168.3.2, 00:00:52, FastEthernet0/2在 R8 上输入,可看到 R8 成功学习到 R7 路由Router#show ip route ospf7.0.0.0/32 is subnetted, 1 subnetsO IA 7.7.7.7 110/3 via 192.168.4.5, 00:00:55, FastEthernet0/2O IA 192.168.3.0/24 110/2 via 192.168.4.5, 00:00:55, FastEthernet0/2