簡單說明
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

實驗說明:如上圖所示三個路由器,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。