BGP
BGP
Border Gateway Protocol
1. What is BGP?2. BGP States3. Timers (Default)4. Path Attributes5. Best Path Selection Order6. Message Types7. BGP vs EIGRP vs OSPF8. Network Types9. Configuration10. Common Commands11. Advanced Concepts12. Traffic Engineering: AS Path Prepending vs Communities
1. What is BGP?
BGP is a Path Vector protocol used to exchange routing between Autonomous Systems (AS). TCP port 179. Backbone of Internet routing. Makes decisions based on policies.
2. BGP States
| State | Description |
|---|---|
| Idle | No BGP connection |
| Connect | TCP connection being established |
| OpenSent | Waiting for BGP Open message |
| OpenConfirm | Waiting for Open acknowledgment |
| Established | Session up, routes exchanged |
3. Timers (Default)
| Timer | Default |
|---|---|
| Keepalive | 60 sec |
| Hold Time | 180 sec |
| Update Timer | 30 sec |
| Min Route Adv. Interval | 30 sec |
4. Path Attributes
| Attribute | Description |
|---|---|
| Weight | Cisco local (highest first) |
| Local Preference | Preferred path within AS |
| AS Path | Shorter path preferred |
| Origin | IGP < EGP < Incomplete |
| MED | Multi Exit Discriminator (lower better) |
| Next Hop | Reachability of next hop |
| Community | Tag for policy control |
| Router ID | Tiebreaker |
5. Best Path Selection Order
- •1. Weight (Cisco) — highest
- •2. Local Preference — highest
- •3. Locally originated
- •4. AS Path — shortest
- •5. Origin — IGP < EGP < Incomplete
- •6. MED — lowest
- •7. eBGP over iBGP
- •8. Lowest IGP cost to Next Hop
- •9. Oldest path
- •10. Lowest Router ID
- •11. Lowest Neighbor IP
6. Message Types
| Message | Purpose |
|---|---|
| OPEN | Establishes BGP connection |
| UPDATE | Advertises or withdraws routes |
| KEEPALIVE | Maintains BGP session |
| NOTIFICATION | Reports errors, closes session |
7. BGP vs EIGRP vs OSPF
| Feature | BGP | EIGRP | OSPF |
|---|---|---|---|
| Type | Path Vector | Hybrid | Link State |
| Domain | Inter-Domain | Intra-Domain | Intra-Domain |
| Standard | Open | Cisco Prop. | Open |
| Algorithm | Policy Based | DUAL | SPF (Dijkstra) |
| Convergence | Slower | Fast | Fast |
8. Network Types
| Type | Description |
|---|---|
| eBGP | Between different AS |
| iBGP | Within the same AS |
| iBGP Full Mesh | Every router peers with every other |
| Route Reflector | Reduces full mesh complexity |
9. Configuration
Router R1 (AS 65010)
router bgp 65010 neighbor 192.168.12.2 remote-as 65020 network 192.168.10.0 mask 255.255.255.0 neighbor 192.168.12.2 next-hop-self
Router R2 (AS 65020)
router bgp 65020 neighbor 192.168.12.1 remote-as 65010 network 192.168.20.0 mask 255.255.255.0
10. Common Commands
| Command | Purpose |
|---|---|
| router bgp <AS> | Enter BGP config |
| neighbor <IP> remote-as <AS> | Set BGP neighbor |
| network <NET> mask <MASK> | Advertise network |
| neighbor <IP> next-hop-self | Set next hop to self |
| show ip bgp summary | Check neighbor status |
| show ip bgp | Check learned routes |
| show ip bgp neighbors | Check neighbor details |
| clear ip bgp * soft in | Soft reset inbound |
11. Advanced Concepts
| Concept | Description |
|---|---|
| Communities | Tag routes for policy control between AS |
| Route Distinguisher | Makes VPN routes unique |
| Confederations | Divide large AS into sub-AS |
| Graceful Restart | Maintain forwarding during restart |
| BGP Multipath | Multiple paths if equal cost |
12. Traffic Engineering: AS Path Prepending vs Communities
Both influence inbound traffic — the hard direction in BGP. You cannot set what neighbors prefer directly, only signal. Two main tools:
| AS Path Prepending | Communities | |
|---|---|---|
| Mechanism | Pad own AS number to lengthen AS_PATH | Tag routes; upstream acts on tag |
| Best-path step | 4 (AS Path length) | Varies — often sets Local Pref (step 2) |
| Granularity | Blunt — affects all upstreams | Surgical — per-provider, per-route |
| Needs ISP support | No — works everywhere | Yes — ISP must define/honor community |
| Beaten by | Any upstream Local Pref override | Whatever the ISP policy dictates |
| Typical use | Make a path less preferred globally | Set Local Pref, prepend, or blackhole remotely |
Rule of thumb: Prepending is a hammer, communities are a scalpel. Prepending is weak — it sits low in best-path selection, so any provider setting a higher Local Preference ignores it entirely. Communities let the provider apply policy on your behalf (often setting Local Pref), making them far more effective when supported.
AS Path Prepending (make path less preferred)
route-map PREPEND-OUT permit 10 set as-path prepend 65010 65010 65010 ! router bgp 65010 neighbor 192.168.12.2 route-map PREPEND-OUT out
Community tagging (RFC 1997 well-known + custom)
ip community-list 1 permit 65020:120 ! route-map TAG-OUT permit 10 set community 65020:120 ! router bgp 65010 neighbor 192.168.12.2 send-community neighbor 192.168.12.2 route-map TAG-OUT out
- •Well-known communities: NO_EXPORT (do not advertise outside AS), NO_ADVERTISE (do not advertise to any peer), LOCAL_AS, INTERNET
- •Format: `ASN:value` (e.g. `65020:120` — ISP doc defines meaning)
- •Always `send-community` to neighbor — not sent by default
- •Prepending own AS 1–3 times is typical; >3 often filtered as suspicious