BGP之选路MED

原理概述
当一台BGP路由器中存在多条去往同一目标网络的BGP路由时,BGP协议会对这些BGP路由的属性进行比较,以确定去往该目标网络的最优BGP路由。BGP路由属性的比较顺序为Preferred Value属性、Local Preference属性、路由生成方式、AS_Path属性、Origin属性、MED属性、BGP对等体类型等。
MED (MULTI_EXIT_DISC)也称为多出口鉴别器,它是一个4字节的整数,取值范围为0~4294967295。缺省情况下,MED 的值为0,但通过命令default med value可对其进行修改。MED的数值越小,表明相应的路由优先级越高,因此MED也常被称为Cost。MED属性的主要作用是用来控制来自邻居AS的流量从哪个入口进入到本AS中。
缺省情况下,只有去往同一目标网络的多条路由均来自同一个邻居AS时,BGP才会比较这些路由的MED值,但是,配置命令compare-different-as-med后,则会比较来自不同邻居AS的目标网络相同的BGP路由的MED值。注意,MED属性只会影响相邻两个AS,收到MED属性的AS不会把此属性再继续传递给别的AS。


实验目的
理解MED属性对BGP路径选择的影响掌握修改MED属性的方法
掌握通过修改MED值实现流量分担的方法实验内容


本实验包含了4个AS,所有的路由器都运行BGP,所有的BGP邻居关系都使用直连物理接口来建立。R1上的Loopback 1、Loopback 2、Loopback 3接口用来分别模拟3个网络172.16.1.0/24、172.16.2.0/24、192.168.1.0/24,这3个网络都被通告进BGP进程。对于通信的需求是:从AS 200去往172.16.1.0/24 的数据流量需经由R1的GE 0/0/2接口进入 AS 100,从 AS 200去往172.16.2.0/24 的数据流量需经由R1的GE 0/0/0接口进入 AS 100,从 AS 400 去往192.168.1.0/24的数据流量需先通过R4,然后经由Rl的GE 0/0/1接口进入AS 100,所有需求都应通过修改MED属性值来实现。

1、基础配置
R1:
sys
sysname R1
int loop 0
ip add 10.0.1.1 32
int loop 1
ip add 172.16.1.1 24
int loop 2
ip add 172.16.2.1 24
int loop 3
ip add 192.168.1.1 24
int g0/0/2
ip add 10.0.12.1 24
int g0/0/0
ip add 10.0.13.1 24
int g0/0/1
ip add 10.0.14.1 24
q
bgp 100
 router-id 10.0.1.1
 peer 10.0.12.2 as-number 200
 peer 10.0.13.3 as-number 200
 peer 10.0.14.4 as-number 300
 #
 ipv4-family unicast
  undo synchronization
  network 10.0.1.1 255.255.255.255
  network 172.16.1.0 255.255.255.0
  network 172.16.2.0 255.255.255.0
  network 192.168.1.0
  peer 10.0.12.2 enable
  peer 10.0.13.3 enable
  peer 10.0.14.4 enable


R2:
sys
sysname R2
int loop 0
ip add 10.0.2.2 32
int g0/0/2
ip add 10.0.12.2 24
int g0/0/0
ip add 10.0.23.2 24
int g0/0/1
ip add 10.0.25.2 24
q
bgp 200
 router-id 10.0.2.2
 peer 10.0.12.1 as-number 100
 peer 10.0.23.3 as-number 200
 peer 10.0.25.5 as-number 400
 #
 ipv4-family unicast
  undo synchronization
  network 10.0.2.2 255.255.255.255
  peer 10.0.12.1 enable
  peer 10.0.23.3 enable
  peer 10.0.23.3 next-hop-local
  peer 10.0.25.5 enable


R3:
sys
sysname R3
int loop 0
ip add 10.0.3.3 32
int g0/0/1
ip add 10.0.13.3 24
int g0/0/0
ip add 10.0.23.3 24
int g0/0/2
ip add 10.0.35.3 24
q
bgp 200
 router-id 10.0.3.3
 peer 10.0.13.1 as-number 100
 peer 10.0.23.2 as-number 200
 peer 10.0.35.5 as-number 400
 #
 ipv4-family unicast
  undo synchronization
  network 10.0.3.3 255.255.255.255
  peer 10.0.13.1 enable
  peer 10.0.23.2 enable
  peer 10.0.23.2 next-hop-local
  peer 10.0.35.5 enable



R4:
sys
sysname R4
int loop 0
ip add 10.0.4.4 32
int g0/0/0
ip add 10.0.14.4 24
int g0/0/1
ip add 10.0.45.4 24
q
bgp 300
 peer 10.0.14.1 as-number 100
 peer 10.0.45.5 as-number 400
 #
 ipv4-family unicast
  undo synchronization
  network 10.0.4.4 255.255.255.255
  peer 10.0.14.1 enable
  peer 10.0.45.5 enable




R5:
sys
sysname R5
int loop 0
ip add 10.0.5.5 32
int g0/0/2
ip add 10.0.25.5 24
int g0/0/1
ip add 10.0.35.5 24
int g0/0/0
ip add 10.0.45.5 24
q
bgp 400
 router-id 10.0.5.5
 peer 10.0.25.2 as-number 200
 peer 10.0.35.3 as-number 200
 peer 10.0.45.4 as-number 300
 #
 ipv4-family unicast
  undo synchronization
  network 10.0.5.5 255.255.255.255
  peer 10.0.25.2 enable
  peer 10.0.35.3 enable
  peer 10.0.45.4 enable

 

可以看到,R2、R3、R4、R5上都接收到了R1的4个网段的路由信息。仔细观察发现,无论是通过EBGP邻居还是IBGP邻居接收到的路由条目,以及路由器自身产生的BGP路由条目,其MED字段的值均为0。如果接收到的路由条目经过了一个AS进行中转,那么 MED值将会丢失,设置为空。在BGP选择最住路径时,MED值为空实际上等同于值为0。

 在,AS 100的管理员要求AS 200访问172.16.1.0/24网络的流量从R1的GE 0/0/2接口进入AS 100,访问172.16.2.0/24网络的流量从R1的GE O/0/0接口进入AS 100。

ip ip-prefix 1 permit 172.16.1.0 24
ip ip-prefix 2 permit 172.16.2.0 24
route-policy 1 permit node 10
if-match ip-prefix 1
apply cost 100
route-policy 1 permit node 20
if-match ip-prefix 2
apply cost 200
route-policy 1 permit node 30

route-policy 2 permit node 10
if-match ip-prefix 2
apply cost 100
route-policy 2 permit node 20
if-match ip-prefix 1
apply cost 200
route-policy 2 permit node 30
bgp 100
peer 10.0.12.2 route-policy 1 export
peer 10.0.13.3 route-policy 2 export

 在PrefVal属性、LocPrf属性、路由生成方式、AS_Path属性、Origin属性都相同的情况下,BGP会选择最小MED值的路由作为最优路由。可以看到,在R2的BGP路由表中,去往172.16.1.0/24的下一跳为10.0.12.1,MED值为100,也就是选择了R1的GE0/0/2接口作为进入AS 100的入口;去往172.16.2.0/24的下一跳为10.0.23.3,MED值为100,也就是选择了R1的GE O/0/0接口作为进入AS 100的入口。
根据相同的原理,R3选择了去往目标网络172.16.1.0/24的下一跳为10.0.23.2,也就是选择了R1的GE 0/0/2接口作为进入AS 100的入口;去往目标网络172.16.2.0/24的下一跳为10.0.13.1,也就是选择了R1的GE 0/0/0接口作为进入AS 100的入口。

可以观察到,R2和 R3去往172.16.1.0/24 网络的路由都携带了MED属性,而R5去往172.16.1.0/24网络的路由,没有MED值,这说明BGP路由的MED属性只传递给邻居AS,邻居AS不会将收到的MED属性再传递给其他AS。

 可以看到,在R5的 BGP路由表中有多条去往192.168.1.0/24网络的路由。我们知道,通过PrefVal属性、LocPrf属性、路由生成方式、AS_Path属性、Origin属性的比较都无法选出最优路由时,BGP将会比较MED属性。但是,在默认情况下,BGP不会比较来自不同 AS 的路由的MED属性,所以R5无法通过比较MED属性选择出去往192.168.1.0/24 网络的最优路由。为此,BGP会继续依次比较邻居类型、到达下一跳的IGP开销值等,最后的结果是,R5选择了Router-ID最小的路由器R2发布的路由作为最优路由。
现在,网络管理员希望AS 400去往192.168.1.0/24网络的流量经由R4,然后通过R1的GE 0/0/1接口进入 AS 100,采用的方法是修改R2、R3和R4 在传递关于192.168.1.0/24的路由信息给R5时的MED属性值。

 

R2:
ip ip-prefix 1 permit 192.168.1.0 24
route-policy 1 permit node 10
if-match ip-prefix 1
apply cost 200
route-policy 1 permit node 20
bgp 200
peer 10.0.25.5 route-policy 1 export
R3:
ip ip-prefix 1 permit 192.168.1.0 24
route-policy 1 permit node 10
if-match ip-prefix 1
apply cost 200
route-policy 1 permit node 20
bgp 200
peer 10.0.35.5 route-policy 1 export
R4
ip ip-prefix 1 permit 192.168.1.0 24
route-policy 1 permit node 10
if-match ip-prefix 1
apply cost 100
route-policy 1 permit node 20
bgp 300
peer 10.0.45.5 route-policy 1 export

在R5上,配置compare-different-as-med命令,让R5强制比较来自不同AS 且去往同一目标网络的路由的MED属性值。

  • 8
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值