Introduction to BGP
Border Gateway Protocol (BGP) is the backbone of the modern internet, responsible for routing data between different autonomous systems (AS). Unlike interior gateway protocols (IGPs) like OSPF or EIGRP, which operate within a single network, BGP is an Exterior Gateway Protocol (EGP) designed to exchange routing information between different organizations and internet service providers (ISPs).
BGP is a path-vector routing protocol, meaning it makes routing decisions based on paths, network policies, and rule sets rather than just metrics like hop count or bandwidth. It is highly scalable, making it the de facto standard for inter-domain routing.
How BGP Works
BGP operates on TCP port 179 and establishes peer sessions (neighbors) between routers in different ASes. These sessions can be:
- eBGP (External BGP): Between routers in different ASes.
- iBGP (Internal BGP): Between routers within the same AS.
Key Concepts in BGP
- Autonomous System (AS): A collection of networks under a single administrative control, identified by a unique AS number (ASN).
- BGP Peering: The process of establishing a BGP session between routers.
- BGP Attributes: Metrics used to determine the best path for routing.
- Route Advertisement: The process of sharing routing information between BGP peers.
- Path Selection: The algorithm BGP uses to choose the best route among multiple options.
BGP Message Types
BGP uses four main message types to maintain and exchange routing information:
- OPEN Message: Establishes a BGP session between peers.
- UPDATE Message: Advertises or withdraws routes.
- KEEPALIVE Message: Ensures the BGP session remains active.
- NOTIFICATION Message: Reports errors and terminates the session if needed.
BGP Path Attributes
BGP uses several attributes to determine the best path for routing. These attributes can be:
- Well-known Mandatory: Must be recognized by all BGP routers (e.g., AS_PATH, NEXT_HOP, ORIGIN).
- Well-known Discretionary: Recognized by all but not required in every update (e.g., LOCAL_PREF, ATOMIC_AGGREGATE).
- Optional Transitive: May not be recognized by all routers but passed along (e.g., COMMUNITY, AGGREGATOR).
- Optional Non-Transitive: Ignored if not recognized (e.g., MED, ORIGINATOR_ID).
Key BGP Attributes
- AS_PATH: Lists the AS numbers a route has traversed (used for loop prevention).
- NEXT_HOP: Specifies the next-hop IP for the route.
- LOCAL_PREF: Indicates the preferred path within an AS (higher value is better).
- MED (Multi-Exit Discriminator): Suggests the best entry point into an AS (lower value is better).
- WEIGHT (Cisco-specific): Locally significant value to prefer a route (higher is better).
- ORIGIN: Indicates how the route was injected into BGP (IGP, EGP, or incomplete).
BGP Route Selection Process
When multiple paths to a destination exist, BGP uses the following decision process to select the best route:
- Highest Weight (Cisco proprietary)
- Highest LOCAL_PREF
- Locally Originated Routes (via
network
oraggregate
commands) - Shortest AS_PATH
- Lowest ORIGIN type (IGP < EGP < Incomplete)
- Lowest MED
- eBGP over iBGP paths
- Lowest IGP metric to NEXT_HOP
- Oldest Route (for stability)
- Lowest Router ID
- Minimum Cluster List Length (for route reflectors)
- Lowest Neighbor IP Address
BGP Configuration Basics
Here’s a simple BGP configuration example on a Cisco router:
router bgp 65001
neighbor 192.168.1.2 remote-as 65002
network 10.0.0.0 mask 255.255.255.0
Key BGP Commands
router bgp <ASN>
: Enables BGP routing.neighbor <IP> remote-as <ASN>
: Defines a BGP peer.network <prefix> mask <subnet>
: Advertises a network in BGP.show ip bgp summary
: Displays BGP neighbor status.show ip bgp
: Shows the BGP routing table.
BGP Route Filtering and Policy Control
BGP allows administrators to manipulate routing using:
- Prefix Lists: Filter routes based on IP prefixes.
- Route Maps: Apply conditions to modify or filter routes.
- AS_PATH Access Lists: Filter routes based on AS_PATH.
- COMMUNITY Attributes: Tag routes for policy enforcement.
Example: Using Route Maps
route-map SET_LOCAL_PREF permit 10
set local-preference 200
!
router bgp 65001
neighbor 192.168.1.2 route-map SET_LOCAL_PREF in
BGP Security Considerations
BGP is vulnerable to several attacks, including:
- Route Hijacking: Malicious AS advertises incorrect routes.
- Route Leaks: Accidental misconfiguration causing traffic to take suboptimal paths.
- BGP Session Hijacking: Attackers impersonate a BGP peer.
Mitigation Techniques
- Route Filtering: Only accept legitimate routes.
- BGPsec: A security extension for BGP (still in adoption).
- RPKI (Resource Public Key Infrastructure): Validates route origins.
Advanced BGP Features
- Route Reflectors: Reduces full-mesh iBGP requirements.
- BGP Confederations: Divides an AS into sub-ASes for scalability.
- Multiprotocol BGP (MP-BGP): Extends BGP for MPLS/VPNs and IPv6.
- BGP Load Balancing: Distributes traffic over multiple paths.
Conclusion
BGP is a complex but essential protocol that powers global internet routing. Understanding its operation, attributes, and best practices is crucial for network engineers working with large-scale networks. By mastering BGP, you gain control over how traffic flows across the internet, ensuring optimal performance, redundancy, and security.