BGP Cheat Sheet

MAG212 CYBER / NETWORK ENGINEERING FIELD GUIDE

BGP Cheat Sheet: Configuration, Best-Path Selection, Troubleshooting & Security

A practical, beginner-friendly to engineer-level guide to Border Gateway Protocol (BGP), featuring an original three-router Cisco IOS XE lab, verified command examples, and fast troubleshooting workflows.

Editorial edition • Updated October 2026 • MAG212 CYBER

TCP/179Peer transport
20 / 200Typical Cisco eBGP / iBGP administrative distance
100Typical Cisco LOCAL_PREF default
6 statesBGP finite-state machine

1. What is BGP?

Border Gateway Protocol is the interdomain path-vector routing protocol used to exchange reachability information and routing policies between autonomous systems (AS). Unlike OSPF, it does not automatically choose paths by shortest internal cost. BGP applies routing policy and path attributes to select one best path among eligible candidates.

Understand it in 10 seconds: OSPF normally answers “How do I reach a destination inside my network?” BGP also answers “Which external network path should my organization prefer and advertise?”
CharacteristiceBGPiBGP
PeersDifferent AS numbersSame AS number
Common purposeExchange routing information across organizationsDistribute BGP reachability within one AS
Default TTL / peeringTTL 1 by default, so peers are usually directly connected; non-adjacent peers need ebgp-multihop (or disable-connected-check)TTL 255; commonly peers between loopbacks across a routed core
Cisco AD (default)20200
Next-hop behaviorTypically rewrites next hop to self when advertising externallyOften preserves external next hop; next-hop reachability matters
Route propagationAS_PATH loop preventioniBGP split horizon; full mesh or route reflectors

2. BGP Lab Topology — Three Routers

All IP addresses below are reserved documentation space or private addresses. The lab uses AS 65100 for the simulated ISP and AS 65200 for the enterprise. The edge and core run iBGP over the internal network.

Three-router BGP lab topology R1 in AS 65100 peers with R2 in AS 65200 over eBGP on 203.0.113.0/30. R2 peers with R3 inside AS 65200 over iBGP on 10.0.0.0/30. R1 originates the lab prefix 198.51.100.0/24. AS 65100 · ISP AS 65200 · ENTERPRISE eBGP 203.0.113.0/30 .1 Gi0/0Gi0/0 .2 iBGP 10.0.0.0/30 .1 Gi0/1Gi0/0 .2 R1ID 1.1.1.1 R2Edge · 2.2.2.2 R3Core · 3.3.3.3 Lab prefix (Null0)198.51.100.0/24 toward R3next-hop-self learns 198.51.100.0/24via 10.0.0.1
MAG212 CYBER original teaching diagram. R1–R2 uses 203.0.113.0/30; R2–R3 uses 10.0.0.0/30.

R1 — ISP (AS 65100)

interface GigabitEthernet0/0
 description TO-R2-ENTERPRISE
 ip address 203.0.113.1 255.255.255.252
 no shutdown
!
ip route 198.51.100.0 255.255.255.0 Null0
!
router bgp 65100
 bgp router-id 1.1.1.1
 neighbor 203.0.113.2 remote-as 65200
 address-family ipv4 unicast
  network 198.51.100.0 mask 255.255.255.0
  neighbor 203.0.113.2 activate
 exit-address-family
Lab-only note: The Null0 route above is solely to provide an exact match for the network statement in this isolated training scenario. Never originate documentation prefixes or an unowned address block into the public internet.

R2 — Enterprise edge (AS 65200)

interface GigabitEthernet0/0
 description TO-R1-ISP
 ip address 203.0.113.2 255.255.255.252
 no shutdown
!
interface GigabitEthernet0/1
 description TO-R3-CORE
 ip address 10.0.0.1 255.255.255.252
 no shutdown
!
router bgp 65200
 bgp router-id 2.2.2.2
 neighbor 203.0.113.1 remote-as 65100
 neighbor 10.0.0.2 remote-as 65200
 address-family ipv4 unicast
  neighbor 203.0.113.1 activate
  neighbor 10.0.0.2 activate
  neighbor 10.0.0.2 next-hop-self
 exit-address-family

R3 — Enterprise core (AS 65200)

interface GigabitEthernet0/0
 description TO-R2-EDGE
 ip address 10.0.0.2 255.255.255.252
 no shutdown
!
router bgp 65200
 bgp router-id 3.3.3.3
 neighbor 10.0.0.1 remote-as 65200
 address-family ipv4 unicast
  neighbor 10.0.0.1 activate
 exit-address-family
Expected result: R2 peers with R1 using eBGP and with R3 using iBGP. R3 can learn the 198.51.100.0/24 lab prefix with next hop 10.0.0.1. The ISP does not learn private enterprise routes unless explicitly advertised. Example syntax is Cisco IOS/IOS XE-oriented; features and defaults vary by release.

3. The Six BGP Neighbor States

StateWhat it meansWhat to check
IdleBGP waits or resets the peer connectionConfig, administrative shutdown, reachability
ConnectTrying to establish TCP connectionRoutes, ACLs, TCP 179
ActiveTCP connection attempt failed; retryingPeer IP, remote-AS, firewall, TTL and authentication
OpenSentOPEN sent; checking peer capabilitiesAS mismatch, version/capabilities
OpenConfirmOPEN accepted; waiting for KEEPALIVETimers and session resets
EstablishedBGP session is up; UPDATE messages can flowAddress-family activation and policies if no prefixes

4. BGP Path Attributes — Fast Reference

AttributePreference / useWhere it matters
Weight (Cisco-specific)Highest wins; local router onlyLocal path preference, never sent to peers
LOCAL_PREFHighest wins; default commonly 100Normally propagated via iBGP, not ordinary eBGP
AS_PATHShorter usually winsShows AS sequence, helps prevent AS loops
ORIGINIGP (i) preferred to EGP (e), then incomplete (?)How route entered BGP
MEDLower preferred under normal comparison rulesHints preferred entry into a neighboring AS
NEXT_HOPMust be reachableCommon cause of unusable BGP routes
COMMUNITYPolicy tags; no universal numeric priorityApply routing policies at scale
ORIGINATOR_ID / CLUSTER_LISTLoop prevention with route reflectorsiBGP route reflection

5. Cisco BGP Best-Path Selection — Simplified Order

Before comparing attributes, BGP discards ineligible candidates (for example, routes with unreachable next hops). Cisco’s precise algorithm contains advanced cases, knobs, and later tie-breakers; use the table as a study sequence, not as a universal vendor-neutral algorithm.

OrderRuleWinner
1WeightHighest
2Local preferenceHighest
3Locally originatedLocal
4AS_PATH lengthShortest
5Origin codeIGP, then EGP, then incomplete
6MED (subject to comparison conditions)Lowest
7eBGP vs iBGPeBGP
8IGP cost to next hopLowest
9Older eBGP path (when applicable)Oldest
10Router ID, cluster list, neighbor addressTie breakers
Critical exam tip: A higher LOCAL_PREF beats a shorter AS_PATH because LOCAL_PREF is checked earlier. MED is not generally compared across unrelated neighboring ASes unless settings enable that behavior.

6. Control Outbound Routing: LOCAL_PREF

Scenario: Your AS receives the same prefix from ISP-A and ISP-B. Prefer ISP-A for traffic leaving your network. Apply an inbound route map to routes received from ISP-A and set LOCAL_PREF to 200.

ip prefix-list DEMO-PREFIX seq 5 permit 198.51.100.0/24
!
route-map PREFER-ISP-A permit 10
 match ip address prefix-list DEMO-PREFIX
 set local-preference 200
!
route-map PREFER-ISP-A permit 100
!
router bgp 65200
 address-family ipv4 unicast
  neighbor 203.0.113.1 route-map PREFER-ISP-A in
 exit-address-family

Why the permit 100? An unmatched route map route is denied implicitly. The second entry allows all other routes to pass unchanged, assuming other inbound filters permit them. For real Internet edge deployments, always use explicit import/export prefix policies and an agreed maximum-prefix limit.

7. Influence Inbound Routing: AS-PATH Prepending

Scenario: You want other networks to view a backup link as less attractive for your own legitimate prefix. Add your ASN multiple times on outbound advertisements over the backup peer. This is only a hint; upstream policies can override it.

ip prefix-list OWN-PREFIX seq 5 permit 192.0.2.0/24
!
route-map BACKUP-PREPEND permit 10
 match ip address prefix-list OWN-PREFIX
 set as-path prepend 65200 65200 65200
!
router bgp 65200
 address-family ipv4 unicast
  neighbor 203.0.113.5 route-map BACKUP-PREPEND out
 exit-address-family

Conceptual second ISP at 203.0.113.5; configure the matching peer and real owned prefix separately. Outbound route-map entries with no subsequent permit entry deny nonmatching prefixes, which may be desirable for strict export control.

8. Essential Verification and Troubleshooting Commands

Command (Cisco IOS XE)What it tells you
show ip bgp summaryNeighbor state; prefix count when established
show bgp ipv4 unicast summaryAddress-family focused peer health
show ip bgp neighborsTimers, resets, policies and peer details
show ip bgp 198.51.100.0Candidate paths, attributes and chosen route
show ip route 198.51.100.0Whether the route entered the routing table
show ip route 203.0.113.1Reachability toward a peer or next hop
show tcp briefTCP session status (platform-dependent formatting)
show running-config | section router bgpBGP neighbor configuration and policies
show ip bgp neighbors 203.0.113.1 advertised-routesWhat your router is offering to a peer (policy matters)
show ip bgp neighbors 203.0.113.1 routesAccepted routes from a peer, if enabled/supported

Troubleshooting workflow

  1. Neighbor never establishes: ping peer, verify route, ACL/TCP 179, remote-as, BGP authentication, and TTL/eBGP multihop where applicable.
  2. Established but zero routes: check IPv4/IPv6 address family, inbound prefix policies, origin network statements and exact RIB matches.
  3. Route in BGP, absent from RIB: next-hop reachability, competing administrative distance, RIB failure or policy.
  4. Wrong exit path: inspect weight, LOCAL_PREF, AS_PATH, ORIGIN and MED in order; confirm where policies are attached.
  5. Unexpected withdrawals: check interface flaps, session reset reason, max-prefix, peer updates and logs.

9. Secure BGP at the Edge

Filter routesExplicit import/export prefix lists and route maps
Protect peersGTSM/TTL protection where supported; MD5/TCP-AO where available
Validate originRPKI ROA/ROV for internet announcements
Limit damageMaximum-prefix limits, alerting and logging

Adopt strict export filtering to prevent accidental leaks; reject bogon or unauthorized origins as appropriate to your policy; monitor unexpected AS_PATH and volume changes; and use route dampening carefully rather than treating it as a universal fix. RPKI validates route-origin authorization, but it does not cryptographically validate the complete AS_PATH.

10. Quick Interview Questions & Answers

Q: What transport does BGP use?

A: TCP port 179; its reliable transport carries BGP protocol messages.

Q: Difference between eBGP and iBGP?

A: eBGP peers have different ASNs; iBGP peers share an ASN.

Q: Why is a BGP neighbor stuck in Active?

A: The TCP session has not successfully formed. Check connectivity, peer IP, ASNs, filters, authentication and TTL.

Q: Does the shortest AS_PATH always win?

A: No. Weight, LOCAL_PREF and local origination can override it before AS_PATH is compared.

Q: Why does next-hop-self help?

A: It gives internal peers a reachable next hop when learning routes originating from external neighbors.

Q: Does BGP network command create a route?

A: No. It originates the matching prefix into BGP only when an exact route exists in the appropriate routing table.

Q: How does iBGP scale beyond a full mesh?

A: Route reflectors or confederations can reduce full-mesh requirements.

Q: Which attribute controls traffic leaving your AS?

A: LOCAL_PREF is a common AS-wide tool for influencing outbound choices.

Q: Can AS_PATH prepending force inbound traffic?

A: No. It influences some remote selection decisions but cannot override other networks’ policies.

Q: What is the first sign BGP is working?

A: A peer in Established state; check received/advertised prefixes separately.

11. Mini Practice Scenario

Question: R2 learns 198.51.100.0/24 from two peers. Path A has LOCAL_PREF 200 and AS_PATH 65100 64496 64497. Path B has LOCAL_PREF 100 and AS_PATH 65101. Assuming both are valid and have equal weight, which wins?

Answer: Path A. LOCAL_PREF is compared before AS_PATH length, so 200 beats 100 regardless of Path B having fewer AS hops.

12. Sources & Verification

This is an original MAG212 CYBER teaching guide. The lab, diagram and explanations were written independently and checked against the BGP-4 standard and Cisco documentation.

RFC 4271 — A Border Gateway Protocol 4 (BGP-4) · Cisco — BGP Best Path Selection Algorithm · RFC 6811 — BGP Prefix Origin Validation (RPKI)

Commands are educational Cisco IOS/IOS XE examples. Test in a lab before applying to a production edge. Defaults and CLI syntax vary by vendor and version.