BGP (Border Gateway Protocol)
The Path Vector protocol that powers the Internet. Unlike IGPs (OSPF/EIGRP) which seek speed, BGP seeks stability, policy control, and loop-free routing between Autonomous Systems (AS).
1. eBGP vs iBGP
BGP operates differently depending on the AS (Autonomous System) relationship.
| Feature | eBGP (External) | iBGP (Internal) |
|---|---|---|
| Peers | Different AS | Same AS |
| TTL | Default 1 (Directly Connected) | Default 255 (Can be multiple hops away) |
| Route Advertising | Advertises all best paths to peers. | Split Horizon Rule: Routes learned from an iBGP peer are NOT advertised to other iBGP peers. |
| Next Hop | Changes Next-Hop to self (usually). | Preserves Next-Hop. (Often causes "Next-Hop Unreachable" errors unless `next-hop-self` is used). |
Because iBGP routers don't re-advertise iBGP-learned routes, every iBGP router must peer with every other iBGP router (Full Mesh). Formula: N * (N-1) / 2.
Solution: Use Route Reflectors (RR) or Confederations to break the full mesh requirement.
2. BGP Attributes & Path Selection
BGP selects a single "Best Path" based on this strict tie-breaker list.
- Weight (Cisco): Highest wins. Local to the router only. (Not sent to peers). Range 0-65535.
- Local Preference: Highest wins. Local to the AS (Transitive within AS). Used to influence outbound traffic. Default 100.
- Locally Originated: Prefer paths I injected (network/redistribute/aggregate).
- AS Path: Shortest length wins. (Can be manipulated with AS-Path Prepending).
- Origin: IGP (i) < EGP (e) < Incomplete (?).
- MED (Metric): Lowest wins. Used to influence inbound traffic from an external AS. Non-transitive.
- eBGP over iBGP: Prefer external paths.
- IGP Cost: Lowest IGP metric to the BGP Next-Hop.
- Router ID: Lowest BGP Router ID.
Mnemonic: "We Love Oranges As Oranges Mean Pure Refreshment"
3. Connection States (FSM)
BGP uses TCP Port 179. Troubleshooting peerings requires understanding these states:
- Idle: Admin down or waiting for start event.
- Connect: Waiting for TCP handshake to complete.
- Active: BAD! This means TCP failed and it is actively trying to reconnect. Check ACLs, routing to peer IP, or misconfigured AS numbers.
- OpenSent: TCP Up. Sent Open message (Version, AS, Hold Time).
- OpenConfirm: Received Open message.
- Established: Up and exchanging routes.
4. Advanced Features & Scenarios
BGP Backdoor
Normally, eBGP routes (AD 20) are preferred over IGP routes (OSPF 110, EIGRP 90). Sometimes, you have a private backdoor link (IGP) that you prefer over the public internet (eBGP) for specific prefixes.
Use the network <ip> backdoor command. This sets the BGP route's distance to 200 (Local/iBGP), making the IGP route preferred.
Synchronization
Legacy rule: "Do not use or advertise a route learned via iBGP unless that route is also known via IGP." This prevents black-holing traffic in transit ASs that are not fully meshed. Modern networks disable this (no synchronization) because they rely on full iBGP meshes or MPLS.
Community Attribute
An optional, transitive tag (32-bit number) attached to routes. Used to group destinations for policy decisions.
- no-export: Do not advertise to eBGP peers.
- no-advertise: Do not advertise to any peer.
- internet: Advertise to everyone.
- Custom: e.g.,
65000:100to tag "Customers" vs "Peers".
References
- RFC 4271: A Border Gateway Protocol 4 (BGP-4) - The core BGP standard.
- Cisco BGP Best Path Selection Algorithm - Official documentation on the tie-breaker logic.
- Cisco BGP Case Studies - Comprehensive examples of load balancing, multihop, and policies.