Border Gateway Protocol (BGP) is the protocol that runs the global internet. While IGPs like OSPF are used to route traffic inside a single organization, BGP is an Exterior Gateway Protocol (EGP) used to route traffic between massive, completely different organizations, such as ISPs, cloud providers, and large enterprises.
The Autonomous System (AS)
To understand BGP, you must understand the concept of an Autonomous System. An AS is a massive network (or group of networks) managed by a single organization with a unified routing policy—for example, Comcast, AT&T, or Google.
Every AS is assigned a unique, globally registered number called an ASN (Autonomous System Number). When ISP A talks to ISP B over the internet, they are establishing an External BGP (eBGP) session between their respective ASNs.
Internal BGP (iBGP) is sometimes used within a massive enterprise core to carry hundreds of thousands of internet routes, but eBGP is the primary focus for internet connectivity.
BGP is a Path-Vector Protocol
Unlike OSPF, which calculates the mathematical fastest bandwidth link, BGP does not care about bandwidth. It is a Path-Vector protocol, meaning it makes routing decisions based on network policies, business rules, and the number of AS hops it must traverse.
When a BGP router advertises a prefix (a subnet) to a neighbor, it attaches a list of Attributes to it. The router uses these attributes to choose the best path.
| BGP Attribute | Description |
|---|---|
| AS_PATH | A list of every ASN the route has passed through. BGP prefers the path with the fewest AS hops (the shortest AS_PATH). It also uses this for loop prevention: if a router sees its own ASN in the path, it drops the route. |
| LOCAL_PREF | Used to tell your own internal routers which path to prefer when leaving the network. Higher is better. |
| MED (Multi-Exit Discriminator) | Used to gently suggest to an external neighboring ISP which path they should take to enter your network. Lower is better. |
Practical Multi-Homing Example
Why would an enterprise use BGP instead of a simple Default Route? Redundancy.
Imagine a large hospital connected to two different ISPs (ISP A and ISP B) for redundancy. This is called Multi-Homing. The hospital owns its own block of public IPs (e.g., 198.51.100.0/24) and its own ASN.
Using BGP, the hospital's edge routers advertise 198.51.100.0/24 to both ISP A and ISP B simultaneously. The global internet learns that to reach the hospital, traffic can take either ISP. If a backhoe cuts the fiber optic cable connecting to ISP A, the BGP session drops, the internet recalculates, and all traffic automatically shifts to enter via ISP B, keeping the hospital online.
Common BGP Troubleshooting
When BGP fails, the stakes are usually very high.
1. Neighbor Not Established (Idle/Active State)
BGP neighbors must be manually configured; they do not auto-discover each other like OSPF. If the neighbor state is not "Established," check:
- TCP Port 179: BGP uses TCP. Ensure no firewalls are blocking TCP 179 between the peers.
- Wrong IP or ASN: Double-check that you typed the neighbor's IP address and ASN correctly.
- Authentication: If MD5 passwords are used, ensure they match exactly.
2. Next-Hop Unreachable
A BGP router will receive a route, but it will absolutely refuse to install it into the Routing Table if it does not know how to reach the Next-Hop IP address attached to that route. Check your underlying IGP (OSPF) to ensure the Next-Hop is reachable.
3. Prefixes Filtered or Missing
Security best practice demands that BGP administrators configure strict Route Maps / Prefix Filters. A router should only advertise the specific subnets it owns, and should only accept specific subnets from a peer. If a route is missing, check the outbound filters on the sending router and the inbound filters on the receiving router.
Security Best Practices
- Never Accept a Default Route blindly: If a misconfigured peer sends you a Default Route, all your outbound traffic might be blackholed into their network.
- Maximum Prefix Limits: Configure your router to tear down the BGP session if an ISP accidentally sends you the full internet routing table (nearly 1,000,000 routes), which would immediately crash a small router's RAM.