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
| Word | What it means | Example |
|---|---|---|
| Autonomous system | one organisation's network, run under one routing policy | AS 65001 |
| AS number | the number that names an autonomous system | |
| BGP session | a connection between two BGP neighbours that carries routes | |
| Announce | to tell a neighbour a network you can reach | |
| AS path | the list of autonomous systems a route has crossed | |
| Local preference | a 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
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
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
sudo ip netns exec r1 ss -ltnShown 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
| Network | What it is | Announce? |
|---|---|---|
| 203.0.113.0/24 | The firm's public web servers | Yes |
| 198.51.100.0/24 | The firm's public mail servers | Yes |
| 10.50.0.0/16 | The office laptops, private | No |
| 172.20.0.0/16 | The building cameras, private | No |
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
| From | Local preference | AS path | Result |
|---|---|---|---|
| Neighbour A | 100 | 65002 65010 | Loses to B: same preference, longer path |
| Neighbour B | 100 | 65003 | Beats A: same preference, shorter path |
| Neighbour C | 200 | 65004 65005 65006 | Wins 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.