Introduction
BGP (Border Gateway Protocol) is the routing protocol that powers the Internet. It connects autonomous systems and determines how traffic flows between networks.
This comprehensive guide covers BGP mechanics, neighbor relationships, route attributes, and implementation.
What is BGP?
BGP is the protocol that routers on the Internet use to exchange routing information. It makes routing decisions based on paths and policies.
Key Concepts
AS (Autonomous System): A network under single administration.
Neighbor: BGP peer that exchanges routes.
Prefix: IP address range being advertised.
AS Path: List of AS numbers the route has traversed.
BGP Message Types
| Type | Description |
|---|---|
| OPEN | Establishes neighbor relationship |
| UPDATE | Advertises/withdraws routes |
| NOTIFICATION | Error handling |
| KEEPALIVE | Maintains relationship |
Implementation
Quagga/FRRouting
# /etc/frr/bgpd.conf
router bgp 65001
bgp router-id 192.168.1.1
neighbor 10.0.0.2 remote-as 65002
!
address-family ipv4 unicast
network 192.168.1.0/24
neighbor 10.0.0.2 activate
exit-address-family
Cisco Configuration
router bgp 65001
bgp router-id 192.168.1.1
neighbor 10.0.0.2 remote-as 65002
!
address-family ipv4 unicast
network 192.168.1.0 mask 255.255.255.0
neighbor 10.0.0.2 activate
Route Attributes
Well-Known Attributes
| Attribute | Description |
|---|---|
| AS-Path | Sequence of AS numbers |
| Next-Hop | Next hop IP |
| Origin | IGP, EGP, Incomplete |
| Local-Preference | Preferred exit (IBGP) |
| MED | Multi-exit discriminator |
AS Path Prepending
# Make path appear longer to influence routing
neighbor 10.0.0.2 route-map OUTBOUND out
!
route-map OUTBOUND permit 10
set as-path prepend 65001 65001
Filtering
Prefix Lists
ip prefix-list DENY_PRIVATE permit 10.0.0.0/8 ge 8 le 24
router bgp 65001
neighbor 10.0.0.2 prefix-list DENY_PRIVATE in
Route Maps
route-map FILTER permit 10
match ip address prefix-list ALLOWED
set local-preference 200
router bgp 65001
neighbor 10.0.0.2 route-map FILTER in
BGP Community
# Tag routes with community
route-map TAG_COMMUNITY permit 10
set community 65001:100
# Filter by community
ip community-list 1 permit 65001:100
route-map FILTER_COMMUNITY deny 10
match community 1
!
route-map FILTER_COMMUNITY permit 20
Peering Types
iBGP (Internal BGP)
- Between routers in same AS
- Does not change AS path
- Requires full mesh or RR
eBGP (External BGP)
- Between routers in different AS
- Changes next hop
- AS path modified
Route Selection
BGP selects best route based on:
- Highest WEIGHT (Cisco)
- Highest LOCAL_PREF
- Local originated routes
- Shortest AS_PATH
- Lowest ORIGIN (IGP < EGP < Incomplete)
- Lowest MED
- eBGP over iBGP
- Lowest IGP metric
- Router ID
Best Practices
- Use route filters and prefix lists
- Implement route damping
- Configure graceful restart
- Monitor peer state
- Use Route Reflectors for iBGP
Conclusion
BGP is the backbone of Internet routing. Understanding BGP is essential for network engineers working at ISPs or large enterprises.
Comments