The border gateway protocol (BGP) enables the exchange of routing information between autonomous systems — essentially separate pools of routers — across the internet. When a user (or another server) wants to send packets across the internet (or internally when BGP is used inside a network), BGP is responsible for choosing the best path for that data as it travels from Point A to Point B.
The Internet Engineering Task Force (IETF) oversaw the creation of BGP in 1989, while Yakov Rekhter (IBM) and Kirk Lougheed (Cisco) designed the protocol itself. BGP 1.0 was specified within RFC 1105 that year, while the current version (BGP 4.0) debuted in 1995 under RFC 1771.
How does the border gateway protocol (BGP) work?
Per the TCP/IP model, BGP is considered a Layer 7 protocol since it functions above the transport layer in that context. The application layer then uses that information to build and update its routing table to decide where IP packets should go next. The Open Systems Interconnection (OSI) Model, meanwhile, considers BGP a transport layer (Layer 4) protocol — despite handling routing processes that might normally fall under the network layer (Layer 3) umbrella.
Understanding border gateway protocol (BGP) topology
BGP relies on networks of autonomous systems (usually organizations with one or more routers) to establish routing procedures. This relies on a number of components:
BGP speakers – Routing devices that send BGP messages, create or receive new routing information, and broadcast that information to other BGP speakers after comparing new routes against their own local routes.
BGP peers – Speakers that communicate with one another over a TCP connection — exchanging routing information, performing path selection, and storing route data at the autonomous system's edge
BGP tables – Databases containing the network layer reachability information (NLRI) and overall topology of the system. More specifically, a BGP routing table contains the best available routing paths between and across networks.
BGP path attributes – Parameters that determine how routing paths are selected, such as weight (local to the router), local preference (determining internal BGP routing), originate (sets preference for the original local path), AS path length (sets preference to the shortest path lengths), and others
Autonomous system (AS) numbers – Numbers included in BGP sessions which identify groups of IP prefixes. These numbers are assigned by local internet registries (LIRs) from pools that ultimately come from the IANA. Some links (such as between a customer and their ISP) will use private AS numbers instead of their own, and the ISP will route traffic there via internal BGP.
All of these components work together to ensure that messages travel from origin to destination. How these components interact — and which ones are most important — can depend on whether routes are used for internal (iBGP) or external BGP (eBGP).
Types of BGP
There are two distinct types of BGP: internal and external. While the greater internet uses external BGP to route data across autonomous systems, these same systems often leverage their own internal BGP setup to manage traffic within their networks. It's similar to how a highway network works — with interstate highways (external BGP) handling traffic across the entire internet, and intrastate highways (internal BGP) routing traffic within the system's established borders.
External BGP is the only requirement to receive IP traffic from the internet, since those systems can use any number of internet protocols to enable communication internally. Because the paths and AS values are thus lower on average, "best path" selection algorithms will typically prefer external BGP routes to internal routes unless a higher local preference is set. This requires the router to be connected to routes that can reach the IP in question.
What else makes BGP useful?
BGP has existed for quite some time, and has evolved into an essential internet protocol. It enjoys widespread use, and a large number of network engineers or other professionals that regularly work with BGP are comfortable with the technology. Mailing lists and forums give users 24/7 access to knowledge and community support.
BGP offers the following benefits:
Network bandwidth conservation by choosing the most efficient routing paths, slashing latency and congestion
Support for some of the web's most critical security measures. However, as BGP comes with no built-in security features, engineers must actively implement security around BGP to protect transactions made using the protocol (mainly external BGP messages). They must also ensure that received BGP announcements are actually routing traffic and not attempting a man-in-the-middle (MITM) attack.
Support for classless inter-domain routing (CIDR), allowing for routers to merge multiple smaller routes and downsize their routing tables
Programmatic policy support, enabling administrators to choose mixtures of routes both inside and outside of the autonomous system
Error prevention by monitoring whether BGP peers in the system remain reachable — and by continually assessing connection health
Higher availability routing by following the next-hop principle, which has routers send traffic using a connection with the fewest hops to its intended destination. BGP doesn't need to know the path to every IP address on the internet.
While BGP remains essential to powering internet communication, researchers and organizations (in government and the private sector) are continually improving the protocol between major releases.
Does HAProxy support BGP?
Yes! HAProxy products support BGP routing to ensure high availability with our route health injection (RHI) module — working effectively alongside other protocols such as open shortest path first (OSPF). HAProxy harnesses the open-source BIRD internet-routing daemon to share routes with BGP.
To learn more about BGP support in HAProxy, check out our route health injection documentation.