← all cheatsheets
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

StateDescription
IdleNo BGP connection
ConnectTCP connection being established
OpenSentWaiting for BGP Open message
OpenConfirmWaiting for Open acknowledgment
EstablishedSession up, routes exchanged

3. Timers (Default)

TimerDefault
Keepalive60 sec
Hold Time180 sec
Update Timer30 sec
Min Route Adv. Interval30 sec

4. Path Attributes

AttributeDescription
WeightCisco local (highest first)
Local PreferencePreferred path within AS
AS PathShorter path preferred
OriginIGP < EGP < Incomplete
MEDMulti Exit Discriminator (lower better)
Next HopReachability of next hop
CommunityTag for policy control
Router IDTiebreaker

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

MessagePurpose
OPENEstablishes BGP connection
UPDATEAdvertises or withdraws routes
KEEPALIVEMaintains BGP session
NOTIFICATIONReports errors, closes session

7. BGP vs EIGRP vs OSPF

FeatureBGPEIGRPOSPF
TypePath VectorHybridLink State
DomainInter-DomainIntra-DomainIntra-Domain
StandardOpenCisco Prop.Open
AlgorithmPolicy BasedDUALSPF (Dijkstra)
ConvergenceSlowerFastFast

8. Network Types

TypeDescription
eBGPBetween different AS
iBGPWithin the same AS
iBGP Full MeshEvery router peers with every other
Route ReflectorReduces 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

CommandPurpose
router bgp <AS>Enter BGP config
neighbor <IP> remote-as <AS>Set BGP neighbor
network <NET> mask <MASK>Advertise network
neighbor <IP> next-hop-selfSet next hop to self
show ip bgp summaryCheck neighbor status
show ip bgpCheck learned routes
show ip bgp neighborsCheck neighbor details
clear ip bgp * soft inSoft reset inbound

11. Advanced Concepts

ConceptDescription
CommunitiesTag routes for policy control between AS
Route DistinguisherMakes VPN routes unique
ConfederationsDivide large AS into sub-AS
Graceful RestartMaintain forwarding during restart
BGP MultipathMultiple 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 PrependingCommunities
MechanismPad own AS number to lengthen AS_PATHTag routes; upstream acts on tag
Best-path step4 (AS Path length)Varies — often sets Local Pref (step 2)
GranularityBlunt — affects all upstreamsSurgical — per-provider, per-route
Needs ISP supportNo — works everywhereYes — ISP must define/honor community
Beaten byAny upstream Local Pref overrideWhatever the ISP policy dictates
Typical useMake a path less preferred globallySet 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