BGP best path selection

Two routers, one requirement, and a decision one of them never made. The gate before the attribute order, and the fault it hides.

In Daveth Pro (Network)6 min video · lab: BGP peering and paths

Watch this lesson

6 min · Video walkthrough

Preview

Upcoming practical lab

BGP peering and paths

After 2 topics: this one and the next · Build lab in the exam's form · Three routers of yours; an inside router, two providers and a customer already running

Locked
View topology, objectives and expected results

A company whose autonomous system number, 4200000100, does not fit in the two bytes older equipment expects. Its core router should never have to be told about a new inside router. Its two edge routers each face a different provider, and one also carries a customer with a private number. OSPF already carries the loopbacks; there is no BGP on your routers.

What you will do

  1. Inside sessions that scale: the core listens for a range and never dials
  2. Two providers and a customer, without the private number leaving
  3. Read why the core prefers one exit
  4. Make the core use both exits
  5. Save it

What it looks like when it works

Every inside session is up without the core naming a neighbor, both providers' routes are in the table, the customer's private AS is gone from what leaves, and the core installs both exits for 203.0.113.0/24.

Two routers, one requirement, and a decision that never happened

An enterprise buys transit from two providers. R1 peers with ISP-A, R2 with ISP-B, and both learn the same content prefix, 203.0.113.0/24. Someone writes down a requirement, all outbound traffic leaves through ISP-A, and configures it correctly. R1 obeys. R2 does not, and every command on R2 says it is healthy.

By the end of this page you will be able to read a BGP table and say, for each path, whether it lost a comparison or was never in one, and then make the two routers agree on purpose, with the attribute whose reach matches the requirement. That distinction is the whole lesson; the failure above is what it looks like when you miss it.

State 1 The network

What is connected to what, and which sessions are BGP?

One network is used for everything on this page. Inside AS 65001, R1 and R2 are the two border routers; OSPF area 0 already runs between them over Gi1, so each knows the other's loopback and R2's LAN, 192.0.2.0/24, at cost 2: one gigabit link plus the loopback. R1 will peer with ISP-A (AS 65010), R2 with ISP-B (AS 65020). Both providers reach the content network, AS 65100, which originates 203.0.113.0/24. Every table, every command output and every packet that follows is derived from this one network; when it is drawn again it is the same network in a later state.

R2# show ip route ospf
      10.0.0.0/8 is subnetted, 1 subnets
O        10.0.0.1/32        [110/2] via 10.0.12.1, 00:01:12, GigabitEthernet1
R1's loopback at cost 2, and the iBGP session will ride on this

Bringing up eBGP, and what each line changes inside R1

A BGP process is not a routing protocol running on interfaces. It is a table and a set of TCP sessions, and a session exists only because a neighbour statement told the router to try. Watch what each stage adds, and what it does not.

First, the process and its identity. The prefix list is written before the process exists, because it is the only prefix this AS will ever offer a provider.

R1> enable
R1# configure terminal
R1(config)# ip prefix-list CORP-OUT seq 5 permit 192.0.2.0/24
R1(config)# router bgp 65001
R1(config-router)# bgp router-id 10.0.0.1
R1(config-router)# bgp log-neighbor-changes

Inside R1: a BGP process for AS 65001 now exists, with an empty table and no sessions. The router ID is pinned to Loopback0; other routers will see it in from … (10.0.0.1), and the eleventh step of path selection compares it. The prefix list exists and is attached to nothing yet.

Second, the neighbour.

R1(config-router)# neighbor 198.51.100.1 remote-as 65010
R1(config-router)# neighbor 198.51.100.1 description ISP-A

R1 now knows that 198.51.100.1 is supposed to be a peer in AS 65010, and because that AS differs from its own, the session will be eBGP. It starts a TCP connection to port 179 and waits. Nothing is Established because this line exists; a neighbour statement is permission to try. No route can arrive yet.

Third, what R1 wants, and the filter on what it says.

R1(config-router)# address-family ipv4 unicast
R1(config-router-af)# neighbor 198.51.100.1 activate
R1(config-router-af)# network 192.0.2.0 mask 255.255.255.0
R1(config-router-af)# neighbor 198.51.100.1 prefix-list CORP-OUT out
R1(config-router-af)# end

network 192.0.2.0 mask 255.255.255.0 puts a locally originated path in R1's table (weight 32768, next hop 0.0.0.0), and only because the exact prefix exists in the RIB, learned through OSPF from R2. If OSPF stopped carrying it, the BGP path would leave with it. The outbound prefix list is not decoration: without it, once R1 learns ISP-B's routes through R2 it would advertise them to ISP-A, and AS 65001 becomes a transit path between two providers on an enterprise link.

Three stages, and the session is still not up. That is the honest state after configuration: the router has been told what to try.

R1# show ip bgp summary
BGP router identifier 10.0.0.1, local AS number 65001
BGP table version is 2, main routing table version 2
1 network entries using 248 bytes of memory
1 path entries using 136 bytes of memory
1/1 BGP path/bestpath attribute entries using 296 bytes of memory
BGP using 680 total bytes of memory
BGP activity 1/0 prefixes, 1/0 paths, scan interval 60 secs
 
Neighbor        V           AS MsgRcvd MsgSent   TblVer  InQ OutQ Up/Down  State/PfxRcd
198.51.100.1    4        65010       0       0        1    0    0 never    Active
Active means trying to connect, not up, not broken

ISP-A answers. OPEN messages cross, carrying AS number, hold time, router ID and capabilities, then KEEPALIVEs, and the session is Established. Now look at what that word does not mean.

R1# show ip bgp summary
BGP router identifier 10.0.0.1, local AS number 65001
BGP table version is 2, main routing table version 2
1 network entries using 248 bytes of memory
1 path entries using 136 bytes of memory
1/1 BGP path/bestpath attribute entries using 296 bytes of memory
BGP using 680 total bytes of memory
BGP activity 1/0 prefixes, 1/0 paths, scan interval 60 secs
 
Neighbor        V           AS MsgRcvd MsgSent   TblVer  InQ OutQ Up/Down  State/PfxRcd
198.51.100.1    4        65010      14      16        2    0    0 00:02:14 0
State/PfxRcd is 0: Established, and nothing received

Established, and the table is empty. Is something wrong? No. An Established session is a channel. Routes arrive in UPDATE messages on that channel, and only if the neighbour has something to send. A filter on the far side, or a neighbour with an empty table, leaves you Established and empty forever. Prefix count is the number to read, not the state.

State 2 ISP-A's UPDATE reaches R1

Where did the route come from, and which of its attributes will matter later?

One UPDATE, from ISP-A to R1, carrying the content prefix with its attributes. The next hop is 198.51.100.1, ISP-A's side of the link, because eBGP sets the next hop to the peering address. The AS_PATH is 65010 65100: ISP-A prepended itself in front of the originator. Origin IGP. No MED, because ISP-A set none. And no local preference: LOCAL_PREF never crosses an AS boundary, so R1 assigns its own default, 100, on arrival.

R1# show ip bgp
BGP table version is 3, local router ID is 10.0.0.1
Status codes: s suppressed, d damped, h history, * valid, > best, i - internal,
              r RIB-failure, S Stale, m multipath, b backup-path, f RT-Filter,
              x best-external, a additional-path, c RIB-compressed,
              t secondary path, L long-lived-stale,
Origin codes: i - IGP, e - EGP, ? - incomplete
RPKI validation codes: V valid, I invalid, N Not found
 
     Network          Next Hop            Metric LocPrf Weight Path
 *>  192.0.2.0/24      0.0.0.0                  0         32768 i
 *>  203.0.113.0/24    198.51.100.1                           0 65010 65100 i
valid and best, but one path, so "best" meant no comparison at all

One path, so it is best by default. Its next hop is on a connected subnet, so the RIB accepts it: B 203.0.113.0/24 [20/0] via 198.51.100.1. Distance 20 because the path is external. That is the first place the control plane becomes forwarding, and the whole entry is worth reading once.

R1# show ip route 203.0.113.0
Routing entry for 203.0.113.0/24
  Known via "bgp 65001", distance 20, metric 0
  Tag 65010, type external
distance 20 = eBGP; the tag is the neighbouring AS
  Last update from 198.51.100.1 00:01:12 ago
  Routing Descriptor Blocks:
  * 198.51.100.1, from 198.51.100.1, 00:01:12 ago, via GigabitEthernet2
      Route metric is 0, traffic share count is 1
      AS Hops 2
      Route tag 65010
      MPLS label: none

Proves: the session to ISP-A reached Established, one prefix was received on it, and the path is installed with the eBGP distance.
Does not prove: that any packet can reach 203.0.113.10 (the RIB entry is a promise about the next hop, not about ISP-A's network beyond it), and nothing about R2, which has no BGP process yet.

R2's configuration mirrors R1's with its own neighbour, 198.51.100.5 in AS 65020. Its UPDATE brings the same prefix with a different next hop and a different AS_PATH, 65020 65100. Each border router now has one path and uses its own provider. Two exits, no coordination, and nobody is wrong yet.

R2# show ip bgp
BGP table version is 3, local router ID is 10.0.0.2
Status codes: s suppressed, d damped, h history, * valid, > best, i - internal,
              r RIB-failure, S Stale, m multipath, b backup-path, f RT-Filter,
              x best-external, a additional-path, c RIB-compressed,
              t secondary path, L long-lived-stale,
Origin codes: i - IGP, e - EGP, ? - incomplete
RPKI validation codes: V valid, I invalid, N Not found
 
     Network          Next Hop            Metric LocPrf Weight Path
 *>  192.0.2.0/24      0.0.0.0                  0         32768 i
 *>  203.0.113.0/24    198.51.100.5                           0 65020 65100 i