码农后生

  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

BGP

基于BGP组网的HA场景验证(local-pref)

  • BGP中的local-pref值
      用来通告路由的优先程度,仅仅在IBGP对等体之间交换,不通告给其他的AS.也就是说只在本AS内生效
      Local_Pref属性值和weight一样,越高越优先。
      默认100.可选范围是:0-4294967295

作用

  在本AS中决定离开本AS的流量出口是谁;默认本地优先为100,越大越优。通常在in方向上做策略,若限制范围,可以在本AS内的neighbor设置时挂载routermap,配置local-preference属性,来指定从该邻居获取路由的优先级并选路设备。

1,拓扑图

  • 图中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
bgp 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 local-preference 100
route-map map1 permit 10
set local-preference 500

router bgp 100
neighbor 10.10.0.2 route-map map in
neighbor 20.20.0.2 route-map map1 in
 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路由规则,当前优选路由是下一跳为20.20.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现在的优选路由是下一跳为20.20.0.2这条

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

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

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

posted on 2020-09-15 10:08  码农后生  阅读(325)  评论(0编辑  收藏  举报