组网需求
如图所示,所有路由器都配置BGP,AR1在AS65008中,AR2和AR3在AS65009中。AR1与AR2、AR3之间运行EBGP,AR2和AR3之间运行IBGP。需求从AS65008到AS65009的流量优先通过AR3。
配置思路
采用如下的思路配置BGP的MED属性控制路由选择:
- 在AR1和AR2、AR1和AR3之间配置EBGP连接;在AR2和AR3之间配置IBGP连接。
- 通过使用路由策略增大AR2发送给AR1的MED值,这样可以使AR1选择AR3作为流量发往AS65009的入口设备。
操作步骤
配置IP
AR1
<Huawei>sys [Huawei]sys AR1 [AR1]int g0/0/0 [AR1-GigabitEthernet0/0/0]ip add 12.12.12.1 24 [AR1-GigabitEthernet0/0/0]q [AR1]int g0/0/1 [AR1-GigabitEthernet0/0/1]ip add 13.13.13.1 24 [AR1-GigabitEthernet0/0/1]q
AR2
<Huawei>sys [Huawei]sys AR2 [AR2]int g0/0/0 [AR2-GigabitEthernet0/0/0]ip add 12.12.12.2 24 [AR2-GigabitEthernet0/0/0]q [AR2]int g0/0/1 [AR2-GigabitEthernet0/0/1]ip add 23.23.23.2 24 [AR2-GigabitEthernet0/0/1]q
AR3
<Huawei>sys [Huawei]sys AR3 [AR3]int g0/0/0 [AR3-GigabitEthernet0/0/0]ip add 13.13.13.3 24 [AR3-GigabitEthernet0/0/0]q [AR3]int g0/0/1 [AR3-GigabitEthernet0/0/1]ip add 23.23.23.3 24 [AR3-GigabitEthernet0/0/1]q
配置bgp
AR1
[AR1]bgp 65008 [AR1-bgp]router-id 1.1.1.1 [AR1-bgp]peer 12.12.12.2 as-number 65009 [AR1-bgp]peer 13.13.13.3 as-number 65009 [AR1-bgp]q
AR2
[AR2]bgp 65009 [AR2-bgp]router-id 2.2.2.2 [AR2-bgp]peer 12.12.12.1 as-number 65008 [AR2-bgp]peer 23.23.23.3 as-number 65009 [AR2-bgp]ipv4-family unicast [AR2-bgp-af-ipv4]network 23.23.23.0 255.255.255.0 [AR2-bgp-af-ipv4]q [AR2-bgp]q
AR3
[AR3]bgp 65009 [AR3-bgp]router-id 3.3.3.3 [AR3-bgp]peer 13.13.13.1 as-number 65008 [AR3-bgp]peer 23.23.23.2 as-number 65009 [AR3-bgp]ipv4-family unicast [AR3-bgp-af-ipv4]network 23.23.23.0 255.255.255.0 [AR3-bgp-af-ipv4]q
查看AR1的路由表
[AR1]display bgp routing-table BGP Local router ID is 1.1.1.1 Status codes: * - valid, > - best, d - damped, h - history, i - internal, s - suppressed, S - Stale Origin : i - IGP, e - EGP, ? - incomplete Total Number of Routes: 2 Network NextHop MED LocPrf PrefVal Path/Ogn *> 23.23.23.0/24 12.12.12.2 0 0 65009i * 13.13.13.3 0 0 65009i [AR1]display bgp routing-table 23.23.23.0 24 BGP local router ID : 1.1.1.1 Local AS number : 65008 Paths: 2 available, 1 best, 1 select BGP routing table entry information of 23.23.23.0/24: From: 12.12.12.2 (2.2.2.2) Route Duration: 00h01m53s Direct Out-interface: GigabitEthernet0/0/0 Original nexthop: 12.12.12.2 Qos information : 0x0 AS-path 65009, origin igp, MED 0, pref-val 0, valid, external, best, select, ac tive, pre 255 Advertised to such 2 peers: 13.13.13.3 12.12.12.2 BGP routing table entry information of 23.23.23.0/24: From: 13.13.13.3 (3.3.3.3) Route Duration: 00h14m09s Direct Out-interface: GigabitEthernet0/0/1 Original nexthop: 13.13.13.3 Qos information : 0x0 AS-path 65009, origin igp, MED 0, pref-val 0, valid, external, pre 255, not pre ferred for router ID Not advertised to any peer yet
从路由表中可以看出,到目的地址23.23.23.0/24有两条有效路由,其中下一跳为12.12.12.2的路由是最优路由(因为AR2的Router ID要小一些)。公众号同名
配置MED属性
AR2
#配置路由策略,在路由出口增大开销 [AR2]route-policy AR2 permit node 10 [AR2-route-policy]apply community [AR2-route-policy]apply cost 100 [AR2]bgp 65009 [AR2-bgp]peer 12.12.12.1 route-policy AR2 export [AR2-bgp]q
验证
AR1
<AR1>display bgp routing-table BGP Local router ID is 1.1.1.1 Status codes: * - valid, > - best, d - damped, h - history, i - internal, s - suppressed, S - Stale Origin : i - IGP, e - EGP, ? - incomplete Total Number of Routes: 2 Network NextHop MED LocPrf PrefVal Path/Ogn *> 23.23.23.0/24 13.13.13.3 0 0 65009i * 12.12.12.2 100 0 65009i <AR1>display bgp routing-table 23.23.23.0 24 BGP local router ID : 1.1.1.1 Local AS number : 65008 Paths: 2 available, 1 best, 1 select BGP routing table entry information of 23.23.23.0/24: From: 13.13.13.3 (3.3.3.3) Route Duration: 00h45m33s Direct Out-interface: GigabitEthernet0/0/1 Original nexthop: 13.13.13.3 Qos information : 0x0 AS-path 65009, origin igp, MED 0, pref-val 0, valid, external, best, select, ac tive, pre 255 Advertised to such 2 peers: 13.13.13.3 12.12.12.2 BGP routing table entry information of 23.23.23.0/24: From: 12.12.12.2 (2.2.2.2) Route Duration: 00h15m43s Direct Out-interface: GigabitEthernet0/0/0 Original nexthop: 12.12.12.2 Qos information : 0x0 AS-path 65009, origin igp, MED 100, pref-val 0, valid, external, pre 255, not p referred for MED Not advertised to any peer yet
从路由表中可以看出,由于下一跳为12.12.12.2(AR2)的路由MED值为100,而下一跳为13.13.13.3的MED值为0,所以BGP优先选择MED值较小的路由。