Easier to read with cream paper, a tint, more contrast or larger text? Choose your colours and text, once, for every page.

Free lesson

How separate networks swap routes (BGP)

After this lesson: I can say how two networks share routes with BGP.

55 min lesson3 commandsBGP lab: connect two autonomous systems in your browser

Two companies, one handshake

Your shop buys internet from one provider. A hosting company buys it from another. They are different organisations.

Each must tell the other which addresses it can reach, without handing over its whole network.

The protocol for that conversation is BGP. It holds the internet together.

By the end of this lesson

Note

I can say how two networks share routes with BGP.

Key words

WordWhat it meansExample
Autonomous systemone organisation's network, run under one routing policyAS 65001
AS numberthe number that names an autonomous system
BGP sessiona connection between two BGP neighbours that carries routes
Announceto tell a neighbour a network you can reach
AS paththe list of autonomous systems a route has crossed
Local preferencea number you set to favour a route; higher wins

The cells students fill in are left blank in this preview.

The internet is many autonomous systems

An autonomous system is one organisation's network: a provider, a university or a large company. Each has an AS number.

Inside an AS, a protocol such as OSPF finds paths. Between systems, BGP carries routes.

The numbers 64512 to 65534 are private. They are for practice and for networks that never meet the internet.

Two routers form a session

Two BGP routers open a BGP session over a normal TCP connection to port 179. Each side says its AS number.

If the two numbers differ, it is an external session, between organisations. If they match, it is internal, inside one.

Once the session is established, the routers swap the networks they announce.

Ask r1 for its BGP sessions

Command
sudo vtysh -N r1 -c "show bgp summary"

Shown here, not run. Create a free account to press Run and type it into your own lab’s terminal.

Read r1's table without BGP

Command
sudo vtysh -N r1 -c "show ip route"

Shown here, not run. Create a free account to press Run and type it into your own lab’s terminal.

List the ports r1 listens on

Command
sudo ip netns exec r1 ss -ltn

Shown here, not run. Create a free account to press Run and type it into your own lab’s terminal.

What the three answers say

The first Run prints % BGP instance not found. The program is running, but nobody has created a BGP router with an AS number.

The second Run lists connected lines and the router's own addresses. No line starts with B, the code for a route learned from BGP.

The third Run lists four listening ports, all on 127.0.0.1: the router's own consoles. None is port 179.

A router announces only what it is told

BGP does not share everything it knows. A router announces a network only when its owner says so.

This is the point of BGP. An organisation decides which networks the world may reach through it.

A private network is simply never announced.

Worked example: what a firm announces

NetworkWhat it isAnnounce?
203.0.113.0/24The firm's public web serversYes
198.51.100.0/24The firm's public mail serversYes
10.50.0.0/16The office laptops, privateNo
172.20.0.0/16The building cameras, privateNo

The cells students fill in are left blank in this preview.

A router chooses between routes by rules

A router can hear one network from several neighbours. It picks one by rules, in order.

First it drops any route whose AS path already holds its own AS number. That route has looped back.

Then the highest local preference wins. If that ties, the shortest AS path wins.

Real routers check a few more rules after these. In this lesson the last rule is simple: the lowest neighbour address wins.

Worked example: three routes to one network

FromLocal preferenceAS pathResult
Neighbour A10065002 65010Loses to B: same preference, longer path
Neighbour B10065003Beats A: same preference, shorter path
Neighbour C20065004 65005 65006Wins overall: highest preference

The cells students fill in are left blank in this preview.

A common mistake

Warning

Many people think BGP picks the fastest path. BGP knows nothing about speed. It follows the owner's preferences, then counts autonomous systems. A short AS path can be a slow link.

Going further: one more rule

A neighbour can attach a MED, a number that says which of its links it would rather you used. Lower is better.

Add the rule to a copy of best_route: after the AS path rule, a route with a lower med wins. Treat a route with no med key as 0.

Write one test with two routes that tie on preference and path length but differ on med.

About this lab and its source: BGP lab: connect two autonomous systems in your browser

Teaching a class? Set this module for your students with a teacher guide, marked assignments and a lab for every student.