BGP 下一跳改为自己实验


简单说明

BGP nexthop属性是一个公认必选属性,它是去往目的路由下一跳路由器的IP地址。该地址并不一定是邻居路由器的地址。该属性需要遵守如下规则:

  • 从EBGP邻居学习到的路由会传递给我的EBGP邻居,下一跳改变,变成自己的IP地址。

  • 从EBGP邻居学习到的路由会传递给我的IBGP邻居,下一跳不变,还是EBGP邻居,需要使用next-hop-self改变。

  • 从IBGP邻居学习到的路由会传递给我的EBGP邻居,下一跳改变,变成自己的IP。

  • 特殊协议特殊对待,比如对于evpn协议强制不能修改该属性。因为该属性表示的是源vtep的IP地址,如果修改该属性将会导致vxlan隧道建立错误。

今天我们重点套路第二条:从EBGP邻居学习到的路由会传递给我的IBGP邻居,下一跳不变,还是EBGP邻居,需要使用next-hop-self改变。

实验TOPO

image-20200114195138106

实验说明:如上图所示三个路由器,RTA和RTB在自治区AS65001中,两者运行IBGP协议。RTC在自治区AS65002中,与RTB之间运行EBGP协议,建立EBGP邻居。RTC发布路由6.6.6.0/24,希望RTB在收到该路由后将下一跳改为自己。

实验配置

RTA

RTA# show running-config 
Building configuration...

Current configuration:
!
frr version 7.1
frr defaults traditional
hostname 97c64887c9b7
log syslog informational
no ipv6 forwarding
hostname RTA
service integrated-vtysh-config
!
router bgp 65001
 neighbor 10.1.1.2 remote-as internal
!
line vty
!
end
RTA# 

RTB

RTB# show running-config 
Building configuration...

Current configuration:
!
frr version 7.1
frr defaults traditional
hostname 7e9362cc0fca
log syslog informational
no ipv6 forwarding
hostname RTB
service integrated-vtysh-config
!
router bgp 65001
 neighbor 10.1.1.1 remote-as internal
 neighbor 10.1.2.2 remote-as external
!
line vty
!
end
RTB# 

RTC

RTC# show running-config 
Building configuration...

Current configuration:
!
frr version 7.1
frr defaults traditional
hostname d4996181649f
log syslog informational
no ipv6 forwarding
hostname RTC
service integrated-vtysh-config
!
interface lo
 ip address 6.6.6.6/24
!
router bgp 65002
 neighbor 10.1.2.1 remote-as external
 !
 address-family ipv4 unicast
  network 6.6.6.0/24
 exit-address-family
!
line vty
!
end
RTC# 

查看RTA路由

RTA# show ip bgp         
BGP table version is 0, local router ID is 172.17.0.2, vrf id 0
Default local pref 100, local AS 65001
Status codes:  s suppressed, d damped, h history, * valid, > best, = multipath,
               i internal, r RIB-failure, S Stale, R Removed
Nexthop codes: @NNN nexthop's vrf id, < announce-nh-self
Origin codes:  i - IGP, e - EGP, ? - incomplete

   Network          Next Hop            Metric LocPrf Weight Path
  i6.6.6.0/24       10.1.2.2                 0    100      0 65002 i

Displayed  1 routes and 1 total paths
RTA# 
RTA# show ip route bgp
RTA# 

从上面可以看出bgp路由表中已经存在了6.6.6.0/24的路由,其下一跳为10.1.2.2。但是在路由表中却没有该路由,这是因为在RTA上下一跳10.1.2.2不可达,对于下一跳不可达的路由,路由器时不会安装的。所以需要在RTA上解决下一跳10.1.2.2的可达问题,可以设置静态路由。

设置静态路由

RTA(config)# ip route 10.1.2.0/24 10.1.1.2 eth1
RTA(config)# 
RTA# show ip bgp                       
BGP table version is 1, local router ID is 172.17.0.2, vrf id 0
Default local pref 100, local AS 65001
Status codes:  s suppressed, d damped, h history, * valid, > best, = multipath,
               i internal, r RIB-failure, S Stale, R Removed
Nexthop codes: @NNN nexthop's vrf id, < announce-nh-self
Origin codes:  i - IGP, e - EGP, ? - incomplete

   Network          Next Hop            Metric LocPrf Weight Path
*>i6.6.6.0/24       10.1.2.2                 0    100      0 65002 i

Displayed  1 routes and 1 total paths
RTA# show ip route bgp
Codes: K - kernel route, C - connected, S - static, R - RIP,
       O - OSPF, I - IS-IS, B - BGP, E - EIGRP, N - NHRP,
       T - Table, v - VNC, V - VNC-Direct, A - Babel, D - SHARP,
       F - PBR, f - OpenFabric,
       > - selected route, * - FIB route, q - queued route, r - rejected route

B>  6.6.6.0/24 [200/0] via 10.1.2.2 (recursive), 00:00:23
  *                      via 10.1.1.2, eth1, 00:00:23
RTA# 

从上面可以看出通过添加静态路由后,RTA安装了6.6.6.0/24路由,且有10.1.2.2 (recursive)字段,表示递归解决下一跳。

那有没有其它办法呢?从递归路由来看,对于RTA来说,其最近的下一跳应该是"via 10.1.1.2, eth1",即与RTB连接的RTB接口IP地址,如果让RTB在发布路由的时候将其下一跳改为自己,那岂不就可以啦。是的,BGP提供这个功能。

配置RTB的next hop self属性

RTA# configure terminal                
RTA(config)# no ip route 10.1.2.0/24 10.1.1.2 eth1
RTA(config)# exit
RTA# 
RTB# configure terminal
RTB(config)# router bgp 65001
RTB(config-router)# address-family ipv4 unicast 
RTB(config-router-af)# neighbor 10.1.1.1 next-hop-self 
RTB(config-router-af)# 
RTA# show ip bgp                          
BGP table version is 3, local router ID is 172.17.0.2, vrf id 0
Default local pref 100, local AS 65001
Status codes:  s suppressed, d damped, h history, * valid, > best, = multipath,
               i internal, r RIB-failure, S Stale, R Removed
Nexthop codes: @NNN nexthop's vrf id, < announce-nh-self
Origin codes:  i - IGP, e - EGP, ? - incomplete

   Network          Next Hop            Metric LocPrf Weight Path
*>i6.6.6.0/24       10.1.1.2                 0    100      0 65002 i

Displayed  1 routes and 1 total paths
RTA# show ip route bgp                    
Codes: K - kernel route, C - connected, S - static, R - RIP,
       O - OSPF, I - IS-IS, B - BGP, E - EIGRP, N - NHRP,
       T - Table, v - VNC, V - VNC-Direct, A - Babel, D - SHARP,
       F - PBR, f - OpenFabric,
       > - selected route, * - FIB route, q - queued route, r - rejected route
B>* 6.6.6.0/24 [200/0] via 10.1.1.2, eth1, 00:00:43
RTA# 

从上面的信息可以看出,在RTA的bgp路由表中,6.6.6.0/24的下一跳被改为了10.1.1.2。


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM