学习精彩网络技术老师:华为HCIA和HCIP数通eNSP实战视频课、华三、锐捷、WLAN、IPv6等全套视频课程
利用MED属性可以灵活控制路由选择。
组网需求
MED属性相当于IGP使用的度量值(Metric),它用于判断流量进入AS时的最佳路由。当一个运行BGP的路由器通过不同的EBGP对等体得到目的地址相同但下一跳不同的多条路由时,在其它条件相同的情况下,将优先选择MED值较小者作为最佳路由。
如图1所示,所有NE都配置BGP,NEA在AS65008中,NEB和NEC在AS65009中。NEA与NEB、NEC之间运行EBGP,NEB和NEC之间运行IBGP。此时,NEA发送至目的地址为172.16.1.0的流量可以从NEB或NEC进入AS65009。在其它条件相同的情况下,用户可以通过在NEB或NEC修改发送至NEA的MED值来选择流量进入AS65009的入口设备,实现对网络的控制。
本例中interface1,interface2分别代表GE0/1/0,GE0/2/0。
配置注意事项
无
配置思路
采用如下的思路配置BGP的MED属性控制路由选择:
在DeviceA和DeviceB、DeviceA和DeviceC之间配置EBGP连接;在DeviceB和DeviceC之间配置IBGP连接。
通过使用路由策略增大DeviceB发送给DeviceA的MED值,这样可以使DeviceA选择DeviceC作为流量发往AS65009的入口设备。
数据准备
为完成此配置例,需准备如下的数据:
- DeviceA的Router ID为1.1.1.1,所在AS号为65008。
- DeviceB、DeviceC的Router ID分别为2.2.2.2、3.3.3.3,所在AS号为65009。
- DeviceB修改后的MED值为100。
操作步骤
- 配置各接口的IP地址(略)
- 配置BGP连接
# 配置DeviceA。
[~DeviceA] bgp 65008
[*DeviceA-bgp] router-id 1.1.1.1
[*DeviceA-bgp] peer 10.1.1.1 as-number 65009
[*DeviceA-bgp] peer 10.1.2.1 as-number 65009
[*DeviceA-bgp] commit
[~DeviceA-bgp] quit
# 配置DeviceB。
[~DeviceB] bgp 65009
[*DeviceB-bgp] router-id 2.2.2.2
[*DeviceB-bgp] peer 10.1.1.2 as-number 65008
[*DeviceB-bgp] peer 172.16.1.2 as-number 65009
[*DeviceB-bgp] ipv4-family unicast
[*DeviceB-bgp-af-ipv4] network 172.16.1.0 255.255.255.0
[*DeviceB-bgp-af-ipv4] commit
[~DeviceB-bgp-af-ipv4] quit
[~DeviceB-bgp] quit
# 配置DeviceC。
[~DeviceC] bgp 65009
[*DeviceC-bgp] router-id 3.3.3.3
[*DeviceC-bgp] peer 10.1.2.2 as-number 65008
[*DeviceC-bgp] peer 172.16.1.1 as-number 65009
[*DeviceC-bgp] ipv4-family unicast
[*DeviceC-bgp-af-ipv4] network 172.16.1.0 255.255.255.0
[*DeviceC-bgp-af-ipv4] commit
[~DeviceC-bgp-af-ipv4] quit
[~DeviceC-bgp] quit
# 查看DeviceA的路由表。
[~DeviceA] display bgp routing-table 172.16.1.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 172.16.1.0/24:
From: 10.1.1.1 (2.2.2.2)
Route Duration: 0d00h00m56s
Direct Out-interface: GigabitEthernet0/1/0
Original nexthop: 10.1.1.1
Qos information : 0x0
AS-path 65009, origin igp, MED 0, pref-val 0, valid, external, best, select, pre 255
Advertised to such 2 peers:
10.1.1.1
10.1.2.1
BGP routing table entry information of 172.16.1.0/24:
From: 10.1.2.1 (3.3.3.3)
Route Duration: 0d00h00m06s
Direct Out-interface: GigabitEthernet0/2/0
Original nexthop: 10.1.2.1
Qos information : 0x0
AS-path 65009, origin igp, MED 0, pref-val 0, valid, external, pre 255, not preferred for router ID
Not advertised to any peers yet
从路由表中可以看出,到目的地址172.16.1.0/24有两条有效路由,其中下一跳为10.1.1.1的路由是最优路由(因为DeviceB的Router ID要小一些)。
- 配置MED属性
# 通过策略配置DeviceB发送给DeviceA的MED值。
[~DeviceB] route-policy 10 permit node 10
[*DeviceB-route-policy] apply cost 100
[*DeviceB-route-policy] commit
[~DeviceB-route-policy] quit
[~DeviceB] bgp 65009
[*DeviceB-bgp] ipv4-family unicast
[*DeviceB-bgp-af-ipv4] peer 10.1.1.2 route-policy 10 export
[~DeviceB-bgp-af-ipv4] commit
# 查看DeviceA的路由表。
[~DeviceA] display bgp routing-table 172.16.1.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 172.16.1.0/24:
From: 10.1.2.1 (3.3.3.3)
Route Duration: 0d00h07m45s
Direct Out-interface: GigabitEthernet0/2/0
Original nexthop: 10.1.2.1
Qos information : 0x0
AS-path 65009, origin igp, MED 0, pref-val 0, valid, external, best, select, pre 255
Advertised to such 2 peers:
10.1.1.1
10.1.2.1
BGP routing table entry information of 172.16.1.0/24:
From: 10.1.1.1 (2.2.2.2)
Route Duration: 0d00h00m08s
Direct Out-interface: GigabitEthernet0/1/0
Original nexthop: 10.1.1.1
Qos information : 0x0
AS-path 65009, origin igp, MED 100, pref-val 0, valid, external, pre 255, not preferred for MED
Not advertised to any peers yet
从路由表中可以看出,由于下一跳为10.1.1.1(DeviceB)的路由MED值为100,而下一跳为10.1.2.1的MED值为0,所以BGP优先选择MED值较小的路由。
配置文件
DeviceA的配置文件
#
sysname DeviceA
#
interface GigabitEthernet0/1/0
undo shutdown
ip address 10.1.1.2 255.255.255.0
#
interface GigabitEthernet0/2/0
undo shutdown
ip address 10.1.2.2 255.255.255.0
#
bgp 65008
router-id 1.1.1.1
peer 10.1.1.1 as-number 65009
peer 10.1.2.1 as-number 65009
#
ipv4-family unicast
peer 10.1.1.1 enable
peer 10.1.2.1 enable
#
return
DeviceB的配置文件
#
sysname DeviceB
#
interface GigabitEthernet0/1/0
undo shutdown
ip address 172.16.1.1 255.255.255.0
#
interface GigabitEthernet0/2/0
undo shutdown
ip address 10.1.1.1 255.255.255.0
#
bgp 65009
router-id 2.2.2.2
peer 172.16.1.2 as-number 65009
peer 10.1.1.2 as-number 65008
#
ipv4-family unicast
undo synchronization
network 172.16.1.0 255.255.255.0
peer 172.16.1.2 enable
peer 10.1.1.2 enable
peer 10.1.1.2 route-policy 10 export
#
route-policy 10 permit node 10
apply cost 100
#
return
DeviceC的配置文件
#
sysname DeviceC
#
interface GigabitEthernet0/1/0
undo shutdown
ip address 172.16.1.2 255.255.255.0
#
interface GigabitEthernet0/2/0
undo shutdown
ip address 10.1.2.1 255.255.255.0
#
bgp 65009
router-id 3.3.3.3
peer 172.16.1.1 as-number 65009
peer 10.1.2.2 as-number 65008
#
ipv4-family unicast
undo synchronization
network 172.16.1.0 255.255.255.0
peer 172.16.1.1 enable
peer 10.1.2.2 enable
#
return