BGP¶
Before the real action begins and your router gets connected to the Internet, you need to learn a little bit about BGP. It essentially makes the difference between your home network and a network which is directly connected to the Internet.
Why do we need BGP?¶
Every router makes a decision for each network packet it receives: 'Where do I send this next?' It answers that question by consulting its routing table, a list of known prefixes and the next hop (e.g. router) to reach them. For destinations, it doesn't recognize, a router can fall back on a default route (::/0 or 0.0.0.0/0), essentially saying 'Send it this way (commonly upstream) and let the next router figure it out.'
That works fine for your home router or a small office router that only needs to reach the Internet through a single ISP. But what happens at the ISP itself? Or at an ORG, which directly participates at the internet? There is no upstream to fall back on — those routers must have explicit and accurate knowledge of every reachable network on the planet. A default route is not an option.
This is exactly the problem Border Gateway Protocol (BGP) solves. It is the mechanism by which routers at the edges of large networks (ISP, ORG, IXP) tell each other: 'I can reach these prefixes — here's the path.' Without it, the tens of thousands of independently operated networks that make up the Internet would have no way to exchange reachability information with each other, and global connectivity would collapse.
Autonomous Systems¶
Before understanding BGP, you need to understand Autonomous Systems (AS).
An Autonomous System is essentially a collection of networks and routers under the control of a single organization. There are many reasons to register for an AS, for example if you are
- an ISP,
- an IXP,
- an organisation with multiple upstream carriers or
- a cloud provider.
Each AS is assigned a unique AS Number (ASN), a 16-bit or 32-bit identifier issued by Regional Internet Registries (RIRs) like RIPE NCC for Europe. A few examples:
BGP's job is to let these autonomous systems advertise the IP address ranges (prefixes) they own and discover the best paths to reach prefixes owned by others.
Types of BGP¶
There are essentially two types of BGP: eBGP and iBGP. Don't worry, the difference is pretty easy to understand.
External BGP (eBGP)¶
This is BGP operating between different autonomous systems. When your ISP exchanges routes with another ISP, they're using eBGP. Peers in an eBGP session are typically directly connected (one hop apart).
In this workshop, you'll mainly establish eBGP peerings.
Internal BGP (iBGP)¶
This is BGP operating within a single autonomous system. Large networks use iBGP to distribute externally-learned routes to all their internal routers. A key rule of iBGP is that routes learned from an iBGP peer must not be re-advertised to another iBGP peer — otherwise you'll get a routing loop. As a consequence, iBGP requires either a full mesh of sessions between all routers, or the use of Route Reflectors (special routers that relay iBGP routes on behalf of others) to scale the design.
Route path selection¶
If you have just one BGP peering, then it's pretty easy for your BGP daemon to decide, which is the best route providing the next hop for reaching a target. However, what happens if you have multiple routes for one target? This is defined in chapter 9.1 of RFC 4271.
BGP uses a few attributes in order to determine the best route:
| Attribute | Description |
|---|---|
AS_PATH |
A list of all ASNs a route has traversed. When AS64500 advertises a prefix to AS64501, which then advertises it to AS64502, the AS_PATH becomes [64501, 64500]. This serves two purposes: loop prevention (if a router sees its own ASN in the path, it discards the route) and path-length comparison (shorter AS_PATH is generally preferred). |
NEXT_HOP |
The IP address of the next router to send packets to in order to reach the destination. |
LOCAL_PREF |
Used only within an AS (not advertised externally). It tells all routers inside the AS which exit point is preferred for leaving the network. A higher value equals a more preferred route. You can use this if you have multiple upstreams and want to prefer one of them 'manually'. |
MED |
Advertised value to a neighboring AS to suggest which entry point they should use when sending traffic into your network. A lower MED equals more preferred. This can be used to steer inbound traffic when there are multiple connections between two ASes. |
ROUTER_ID |
A 32-bit identifier used to identify a BGP router. It's usually an IPv4 address of the router. |
ORIGIN |
Describes how the route was originally introduced into BGP. IGP means the route was injected into the BGP routing table using a network statement. EGP means the route was learned via EGP, BGP's predecessor protocol. Incomplete means the route was redistributed from an unknown or uncharacterized source, such as a static route. |
After checking whether the NEXT_HOP is reachable (if it's not, the route should not be considered), BGP essentially ranks the routes using the following order:
- Highest
LOCAL_PREF - Shortest
AS_PATH ORIGIN: preferIGPoverEGPoverincomplete- Lowest
MED - Prefer eBGP over iBGP
- Lowest metric to
NEXT_HOP - Lowest
ROUTER_ID - Lowest neighbor IP address