Skip to content

Linux Foundations / Follow traffic and find the fault ยท Step 23 of 46

Lesson: Border Gateway Protocol (BGP)Switch
โ† Linux Foundations

Network operations

Border Gateway Protocol (BGP)

Learn how BGP connects separately run networks into the internet and how it picks paths.

The internet is many independently run networks joined together. The Border Gateway Protocol (BGP) is how they tell each other which IP prefixes they can reach.

Autonomous systems

Each participating network is an autonomous system (AS) with an AS number (ASN). ASNs were once 16 bits and can now be 32 bits. The range 64512 to 65534 is set aside for private use, as is a much larger 32-bit range. 64496 to 64511 are reserved for documentation.

Peers

BGP routers do not normally discover each other the way OSPF routers do. An administrator configures each neighbour, also called a peer. The session runs over TCP port 179.

  • eBGP is a session between different autonomous systems.
  • iBGP is a session between routers in the same one.

The AS path

BGP is a path vector protocol. Each route carries an AS path, the list of autonomous systems it has crossed:

203.0.113.0/24   AS path: 64500 64501

The right-most number is the AS that originated the prefix. A router that sees its own ASN in the path rejects the route, which prevents loops.

Choosing a path

BGP is about policy more than speed. When several paths to the same prefix exist, a router compares attributes in a fixed order. Local preference (higher wins), set inside your own AS, is checked before AS path length (shorter wins). Further tie-breakers follow, and details differ between vendors. The shortest AS path is therefore not always chosen.

Longest prefix match still applies when forwarding. This is why a wrong, more specific announcement can draw traffic away from the real owner. A false announcement of this kind is called a route hijack. A related problem, the route leak, is when routes spread further than intended. Operators defend themselves with prefix filters and RPKI origin validation.

A small FRR example

With bgpd enabled, this configures one eBGP neighbour in vtysh:

configure terminal
router bgp 64500
 neighbor 192.0.2.2 remote-as 64501
 address-family ipv4 unicast
  network 203.0.113.0/24

show bgp summary lists neighbours and their state. By default, recent FRR versions may refuse to exchange routes with an eBGP peer until you define a policy for it, as RFC 8212 describes. This depends on the version and profile, so check the FRR documentation. Practise only in a lab, never against real peers.

Try it

On paper, draw four autonomous systems in a square, with one announcing 198.51.100.0/24. Write the AS path each of the others receives from both directions. Decide which is shorter, then see how a higher local preference could change the choice. The subnetting guide helps with prefix lengths.

Check your understanding

Border Gateway Protocol (BGP)

All 5 sections ยท no timer

Unlimited retries

Questions from every section are combined into one assessment. Answer them all correctly to complete the article.

Your completion saves in this browser. Sign in to sync it to your account.