BGP

基于BGP组网的HA场景验证(MED)

  • MED为BGP中的metric值
      MULTI_EXIT_DISC(多出口标识符)简称MED,MED用于影响相邻两个自治系统的路由决策,被称为外部度量值,其值越小越优先,Cisco中为metric,默认值为0,MED只能在AS之间传递,收到此属性的AS路由器不会再将其传递给任何其它的第三方AS,但会传递给他的iBGP邻居;
      MED的取值范围是0~4294967295(32位)

作用

  其他AS设备进入本AS的流量的入口是谁,值越小越优,默认metric值为0。通常是在out方向做策略。若限制范围,可以在本AS内的neighbor设置时挂载routermap,配置MED属性。

1,拓扑图

BGP MED bgp med什么意思_组网

  • 图中A设备因自己需要设置多网口进行直连,可以直接在宿主机中安装vtysh进行操作,更为简便
  • 拓扑:
      在BGP组网中有四台设备,其中A,B,C建立EBGP连接,B,C,D建立IBGP连接。
      A的自治域设置为100,B、C和D的自治域为50,这三台设备BGP连接使用loopback,其他设备连接使用ip。

2,环境搭建

 2.1 A设备设置
  • vtysh
vtysh
configure terminal
router bgp 100
configure terminalbgp router-id 10.10.0.1
neighbor 10.10.0.2 remote-as 50
neighbor 10.10.0.2 ebgp-multihop 2
neighbor 20.20.0.2 remote-as 50
neighbor 20.20.0.2 ebgp-multihop 2
  • 设置metric
vtysh
configure terminal

route-map map permit 10
set metric 10
route-map map1 permit 10
set metric 100

router bgp 100
neighbor 10.10.0.2 route-map map out
neighbor 20.20.0.2 route-map map1 out
 2.2 B设备设置
  • vtysh
      与A设备建立BGP
vtysh
configure terminal
router bgp 50
router bgp 10.10.0.2
neighbor 10.10.0.1 remote-as 100
neighbor 10.10.0.1 ebgp-mltihop 2

  与D设备建立BGP

vtysh
configure terminal
router bgp 50
neighbor 3.3.3.1 remote-as 50
neighbor 3.3.3.1 update-source lo
//添加默认路由
ip route 3.3.3.0/24 via 192.168.20.10
 2.3 c设备设置
  • vtysh
      与A设备建立BGP
vtysh
configure terminal
router bgp 50
router bgp 20.20.0.2
neighbor 20.20.0.1 remote-as 100
neighbor 20.20.0.1 ebgp-mltihop 2

  与D设备建立BGP

vtysh
configure terminal
router bgp 50
neighbor 3.3.3.1 remote-as 50
neighbor 3.3.3.1 update-source lo
//添加默认路由
ip route 3.3.3.0/24 via 192.168.10.10
 2.4 D设备设置
  • vtysh
router bgp 50
bgp router-id 3.3.3.1 
neighbor 1.1.1.1 remote-as 50
neighbor 1.1.1.1 update-source lo 
neighbor 2.2.2.2 remote-as 50     
neighbor 2.2.2.2 update-source lo

//配置本地BGP发送路由
address-family ipv4 unicast 
network 3.3.3.0/24 
exit-address-family  

//需要增加默认路由
ip route add 1.1.1.0/24 via 192.168.20.20
ip route add 2.2.2.0/24 via 192.168.10.20

3,组网状态

 3.1 A
  • 使用show ip bgp summary 查看BGP neighbor情况
  • 使用show ip bgp 查看BGP路由表,根据BGP路由规则,当前优选路由是下一跳为10.10.0.2这条
 3.2 B
  • 使用show ip bgp summary 查看BGP neighbor情况
  • 使用show ip bgp 查看BGP路由表,根据BGP路由规则
 3.3 C
  • 使用show ip bgp summary 查看BGP neighbor情况
  • 使用show ip bgp 查看BGP路由表,根据BGP路由规则
 3.4 D
  • 使用show ip bgp summary 查看BGP neighbor情况
  • 使用show ip bgp 查看BGP路由表,根据BGP路由规则

4,验证

  由下图A的路由表可以看出,A现在的优选路由是下一跳为10.10.0.2这条

BGP MED bgp med什么意思_路由表_02


  现在拔掉10.10.0.2这根网线,再次查看A设备的路由表

BGP MED bgp med什么意思_路由表_03


  现在插回10.10.0.2这根网线,再次查看A设备的路由表

BGP MED bgp med什么意思_BGP MED_04


  可以看出当B设备重新与A设备建立BGP后,优选路由任然为从B设备学到的

  一条相同的BGP条目通过不同的EBGP邻居学到时,只有在AS号相同时才进行MED比较,当从不同的EBGP邻居收到相同的路由,但是AS号不一样时,是不会比较MED值的,如果路由器上配置了bgp always-compare-med,就会忽略AS号不一样,始终进行MED值的比较。