BGP (Border Gateway Protocol) is the routing protocol network operators use to exchange which IP prefixes can be reached through which autonomous system. From the paths it has learned, each router picks the neighbour it forwards traffic to, following its operator's routing policy. Without BGP the individual networks of the internet would not know how to reach each other.
Key facts
- Meaning
- Border Gateway Protocol, currently version 4
- Transport
- TCP port 179
- Variants
- eBGP between ASes, iBGP within an AS
- Smallest usual prefixes
- /24 for IPv4, /48 for IPv6
- Safeguards
- IRR filters and RPKI
- Needed for your own sessions
- Own ASN and own address space
How BGP distributes routes
What an autonomous system is and when having your own makes sense is covered in our article on autonomous systems. BGP is the protocol these networks use to talk to each other. Two routers set up a session over TCP and send each other updates. Each route consists of a prefix, that is an IP network such as 192.0.2.0/24, and attributes. The most important one is the AS path: every network that passes a route on puts its own ASN in front. If a router finds its own ASN already in the path, it discards the route, which prevents loops. A network with a full routing table today knows around one million IPv4 prefixes.
How BGP chooses a path
If a router can reach the same prefix via several neighbours, it picks exactly one best path. Before that, a rule outside BGP applies: a more specific prefix always wins, so a /24 beats the covering /22. Among identical prefixes the router compares the attributes in a fixed order, simplified as follows:
- Local preference: the operator's internal setting, for example peering before transit.
- AS path length: a path through fewer networks is preferred.
- MED: a hint from the neighbour as to which of several interconnection points it prefers to receive traffic on.
- eBGP before iBGP: a route learned directly from outside beats one passed on internally.
- Router ID as the final tie-breaker when everything else is equal.
A network can therefore only steer incoming traffic indirectly, for example by artificially lengthening the AS path towards one upstream (prepending) or by announcing more specific prefixes at one location.
eBGP and iBGP
eBGP runs between two different autonomous systems, usually between directly connected routers at an interconnection point or internet exchange. iBGP distributes the routes learned from outside to all border routers within an AS. A router does not pass a route learned via iBGP on to further iBGP neighbours. Larger networks therefore need either sessions between all routers or so-called route reflectors. How the routers find each other internally is handled by a separate protocol such as OSPF or IS-IS. For a single server with its own BGP session iBGP does not matter; one eBGP session to the provider's router is enough.
What BGP support means for a dedicated server
Normally a server receives IP addresses from the provider's network, and the provider takes care of routing. With BGP support your server sets up its own eBGP session to the provider's router, for example with BIRD or FRRouting, and announces your own prefixes over it. This is called BYOIP (Bring Your Own IP). Several things have to fit together:
- Your own AS number and address space registered to you in the RIPE database.
- A prefix of at least /24 for IPv4 or /48 for IPv6; most operators discard smaller networks.
- Matching route or route6 objects in the IRR and a valid ROA in RPKI.
- Routing software on the server with filters for incoming and outgoing routes.
- An agreement with the provider on which prefixes it accepts from your session.
Typical reasons are addresses that survive a change of provider, and anycast or failover, where the same prefix is announced at several locations. Where your own addresses come from is explained in the article on RIPE PA and PI addresses.
Risks: misconfiguration, route leaks and hijacks
BGP basically trusts whatever the neighbours announce. A typo in a prefix or a missing export filter can divert traffic meant for other networks. In a route leak, a network passes routes it learned from one upstream on to another upstream or peer, and suddenly traffic flows through a network that was never designed for it. In a hijack, someone announces a prefix that does not belong to them, deliberately or by mistake. There are safeguards against both that each side of a session should use:
- IRR filters: the provider builds a list of the prefixes it accepts from you out of your route objects and your AS-SET.
- RPKI: a ROA cryptographically states which AS may announce a prefix, and routers with route origin validation discard invalid announcements.
- Max prefix limit: the session is torn down if suddenly more prefixes arrive than agreed.
- Export filters on your side: explicitly allow only your own prefixes and discard everything else.
RPKI only checks which AS originally announces a prefix, not the rest of the path. Against route leaks, clean filters on both sides are therefore what helps most.
BGP communities
Communities are tags attached to a route. The classic format is ASN:value; for 32-bit ASNs there are large communities with three fields. What a community does is defined and documented by the receiving operator. Common instructions are not to pass a route on to certain peers, to add prepending or to lower its local preference. A widespread special case is blackholing: the neighbour then drops all traffic to a destination IP. This protects the rest of the network during an attack but makes the affected address unreachable.
At Realtoxmedia, BGP is available for dedicated servers and colocation; for colocation you set up BGP sessions in the colocation panel. With IP transit you get a BGP session to the backbone AS207252 and use a BGP community to decide for each prefix whether it is routed through DDoS filtering during an attack. Basic DDoS protection is free of charge; staying reachable during an attack requires the paid extended DDoS protection. If you do not have your own AS yet, Realtoxmedia helps you apply for one through its RIPE services.
BGP distributes the information on which network reaches which prefixes across the internet, and each network chooses its paths according to its own policy. Your own BGP session is worthwhile if you want to use your own addresses independently of a provider or announce them at several locations. For that, maintain your IRR objects and ROAs and filter your own announcements strictly.