🌐 BGP (Border Gateway Protocol) - Internet protocol
🌐 BGP (Border Gateway Protocol)
🧠 Top 5 Key Points
-
Path Vector Routing Protocol:
BGP makes routing decisions based on path attributes, policies, and rules, not just metrics like OSPF or EIGRP. -
Used for Internet Routing:
It’s the protocol that runs the Internet, connecting different Autonomous Systems (AS) — typically ISPs, enterprises, and data centers. -
Exterior Gateway Protocol (EGP):
Unlike OSPF or EIGRP (Interior Gateway Protocols), BGP operates between autonomous systems, not within one. -
TCP Port 179:
BGP forms neighbor relationships (peering) over TCP port 179 for reliable communication. BGP table will have 30 lakh routes information.
-
Two Types of BGP:
-
eBGP: Between different AS (ISPs or enterprises).
-
iBGP: Within the same AS (used inside large networks).
-
⚙️ Technical Summary
-
Protocol Type: Path Vector
-
Metric: Path attributes (WEIGHT, AS-PATH, NEXT-HOP, LOCAL_PREF, etc.)
-
Transport: TCP Port 179
-
Convergence: Slower but highly stable and scalable
🧰 BGP Lab in Cisco Packet Tracer
(Simplified eBGP Lab for beginners)
🎯 Goal:
Configure eBGP between two autonomous systems (AS 65001 and AS 65002) so that both LANs can communicate.
🖥️ Network Topology
IP Address Plan
| Device | Interface | IP Address | Network | AS Number |
|---|---|---|---|---|
| R1 | G0/0 | 192.168.1.1 | 192.168.1.0/24 | 65001 (ISP 1) |
| S0/0/0 | 10.0.0.1 | 10.0.0.0/30 | 65001 (ISP 1) | |
| R2 | S0/0/0 | 10.0.0.2 | 10.0.0.0/30 | 65002 (ISP 2) |
| G0/0 | 192.168.2.1 | 192.168.2.0/24 | 65002 (ISP 2) | |
| PC1 | NIC | 192.168.1.10 | 192.168.1.0/24 | — |
| PC2 | NIC | 192.168.2.10 | 192.168.2.0/24 | — |
🪜 Step-by-Step Configuration
🔹 R1 (AS 65001)
🔹 R2 (AS 65002)
🔍 Verification Commands
➡ Shows BGP neighbor relationships and AS numbers.
➡ Displays the BGP routing table.
➡ Shows BGP-learned routes (marked with “B”).
💡 Testing
From PC1, ping PC2:
✅ If successful → BGP routes are properly exchanged between AS 65001 and AS 65002.
🧠 What Students Learn
| Concept | Description |
|---|---|
| BGP Type | Path Vector |
| Use Case | Routing between ISPs or organizations |
| eBGP Peering | Between different AS numbers |
| Transport Protocol | TCP port 179 |
| Metric Basis | Path attributes (AS Path, Next Hop, etc.) |
🗺️ Extra Teaching Tip
"Think of BGP as the Internet’s post office — it doesn’t care how you reach the neighbor’s street (internal routing handles that), it just needs to know which neighborhood (AS) to forward to next."
----------------------------------------------------------------------------------------------------------------------------
BGP Path Selection Process (Interview Explanation)
When BGP (Border Gateway Protocol) learns multiple routes to the same destination, it chooses the best path based on a sequence of attributes.
BGP Path Selection Order
1. Highest Weight (Cisco-specific)
- Weight is local to the router.
- Higher weight is preferred.
- Not advertised to other routers.
Example:
Path A: Weight = 500
Path B: Weight = 200
Best Path → Path A
2. Highest Local Preference
- Used within the same Autonomous System (AS).
- Advertised to all iBGP routers.
- Higher value is preferred.
Example:
Path A: Local Preference = 200
Path B: Local Preference = 100
Best Path → Path A
Default: 100
3. Prefer Locally Originated Routes
Routes that originate from:
-
networkcommand -
aggregate-address - Route redistribution
are preferred over learned routes.
4. Shortest AS Path
BGP prefers the route with the fewest AS numbers.
Example:
Path A:
65001 65002
Path B:
65001 65002 65003 65004
Best Path → Path A
5. Lowest Origin Type
Preference order:
IGP < EGP < Incomplete
IGP is preferred.
6. Lowest MED (Multi-Exit Discriminator)
Lower MED is preferred.
Example:
Path A: MED = 20
Path B: MED = 100
Best Path → Path A
7. Prefer eBGP over iBGP
External BGP routes are preferred over Internal BGP routes.
eBGP > iBGP
8. Lowest IGP Cost to Next Hop
Chooses the route with the shortest internal routing cost to reach the next hop.
9. Oldest Route
If all else is equal, BGP may prefer the oldest route to reduce route flapping.
10. Lowest BGP Router ID
Example:
Router A: 1.1.1.1
Router B: 2.2.2.2
Best Path → Router A
11. Lowest Neighbor IP Address
Final tie-breaker if everything else is identical.
Easy Mnemonic for Interviews
Remember this order:
- Weight
- Local Preference
- Local Origin
- AS Path
- Origin
- MED
- eBGP over iBGP
- IGP Metric
- Oldest Path
- Router ID
- Neighbor IP
Mnemonic:
"We Love Local AS Origin, Many External Interns Offer Reliable Networking."
One-Line Interview Answer
BGP selects the best path by evaluating attributes in order: Highest Weight → Highest Local Preference → Locally Originated Route → Shortest AS Path → Lowest Origin Type → Lowest MED → eBGP over iBGP → Lowest IGP Metric → Oldest Path → Lowest Router ID → Lowest Neighbor IP Address.
BGP Attributes Explained with Real-Time Examples
Imagine your company (AS 65001) is connected to two ISPs:
ISP-A (AS 100)
|
|
AS 65001
|
|
ISP-B (AS 200)
Both ISPs advertise a route to Google's network. BGP must decide which path to use.
1. Weight (Cisco Specific)
What is it?
A local attribute used only on one router.
Higher Weight Wins
Example:
Route via ISP-A → Weight 500
Route via ISP-B → Weight 200
Result:
Best Path = ISP-A
Real World
Your company wants all traffic to leave through ISP-A regardless of other factors.
2. Local Preference
What is it?
Used within the entire Autonomous System.
Higher Local Preference Wins
Example:
ISP-A = Local Preference 300
ISP-B = Local Preference 100
Result:
All routers in AS 65001 use ISP-A
Real World
ISP-A is cheaper than ISP-B.
You configure:
ISP-A = 300
ISP-B = 100
All outbound traffic prefers the cheaper ISP.
3. Locally Originated Route
Routes created by:
network command
redistribute
aggregate-address
are preferred.
Example:
Route A = Learned from ISP
Route B = Created locally
Result:
Route B wins
Real World
Your company advertises:
10.10.10.0/24
through BGP.
Your own route is always preferred.
4. AS Path
What is it?
List of Autonomous Systems a route has crossed.
Shortest AS Path Wins
Example:
Route A:
100 200
Route B:
100 200 300 400
Result:
Route A wins
Real World
Path to Google:
AS100 → AS15169
vs
AS100 → AS300 → AS400 → AS15169
BGP chooses the shorter path.
5. Origin Attribute
Indicates how the route entered BGP.
Preference:
IGP > EGP > Incomplete
Real World
Route A:
network statement
Route B:
redistributed from OSPF
Route A wins.
6. MED (Multi Exit Discriminator)
Used between neighboring ASes.
Lower MED Wins
Example:
Link 1 MED = 50
Link 2 MED = 200
Result:
Link 1 wins
Real World
A provider has two circuits to your company:
Bangalore Circuit
Mumbai Circuit
Provider wants traffic via Bangalore.
Provider advertises:
Bangalore MED = 50
Mumbai MED = 200
7. eBGP vs iBGP
Preference:
eBGP > iBGP
Real World
Router receives:
Route from ISP (eBGP)
Route from internal router (iBGP)
BGP prefers the ISP route.
8. Lowest IGP Metric to Next Hop
BGP checks how close the next hop is.
Example:
Route A → OSPF Cost 10
Route B → OSPF Cost 50
Result:
Route A wins
Real World
Data Center A:
10ms away
Data Center B:
50ms away
BGP prefers Data Center A.
9. Oldest Route
When everything else matches:
Older route wins
Real World
Prevents route flapping.
If two paths are identical:
Use the stable route.
10. Lowest Router ID
Example:
Router A = 1.1.1.1
Router B = 2.2.2.2
Result:
Router A wins
Real World
Tie-breaker only.
11. Lowest Neighbor IP
Final tie-breaker.
Example:
Neighbor A = 10.1.1.1
Neighbor B = 10.1.1.2
Result:
10.1.1.1 wins
Real Interview Scenario
Question:
Your company has two Internet providers.
ISP-A = Cheap
ISP-B = Expensive
Management wants:
All outgoing traffic via ISP-A
Solution:
Set:
Local Preference
ISP-A = 300
ISP-B = 100
Result:
Entire company uses ISP-A.
Most Important Attributes for Interviews
| Attribute | Preference |
|---|---|
| Weight | Higher |
| Local Preference | Higher |
| AS Path | Shorter |
| Origin | IGP |
| MED | Lower |
| eBGP/iBGP | eBGP |
| IGP Cost | Lower |
| Router ID | Lower |
Easy Interview Answer
"The most commonly used BGP attributes in production are Weight, Local Preference, AS Path, and MED. Network engineers typically use Local Preference to control outbound traffic and AS Path prepending or MED to influence inbound traffic. BGP selects the best route by evaluating these attributes in a specific order until one path is preferred."
------------------------------------------------------------------------------------------------------
1. Configure Weight
Purpose: Control outbound traffic on a single Cisco router.
- Higher Weight = Preferred
- Default Weight = 0
- Local to the router only (not advertised)
Example
Prefer ISP-A for network 10.10.10.0/24.
R1(config)# access-list 1 permit 10.10.10.0 0.0.0.255
R1(config)# route-map SET-WEIGHT permit 10
R1(config-route-map)# match ip address 1
R1(config-route-map)# set weight 500
R1(config)# router bgp 65001
R1(config-router)# neighbor 192.168.1.1 route-map SET-WEIGHT in
Verify:
show ip bgp
2. Configure Local Preference
Purpose: Control outbound traffic for the entire AS.
- Higher Local Preference = Preferred
- Default = 100
- Advertised inside your AS (iBGP)
Example
Prefer ISP-A.
R1(config)# route-map SET-LOCALPREF permit 10
R1(config-route-map)# set local-preference 300
R1(config)# router bgp 65001
R1(config-router)# neighbor 192.168.1.1 route-map SET-LOCALPREF in
Result:
ISP-A Local Preference = 300
ISP-B Local Preference = 100
Best Path = ISP-A
Verify:
show ip bgp
3. Configure MED (Multi Exit Discriminator)
Purpose: Suggest which link another AS should use to reach you.
- Lower MED = Preferred
Example
Advertise MED 50 to ISP.
R1(config)# route-map SET-MED permit 10
R1(config-route-map)# set metric 50
R1(config)# router bgp 65001
R1(config-router)# neighbor 192.168.1.1 route-map SET-MED out
Result:
ISP receives:
MED = 50
and prefers this path over another with MED = 200.
Verify:
show ip bgp
4. Configure AS Path Prepending
Purpose: Influence inbound traffic by making one path look longer.
- Longer AS Path = Less Preferred
Example
Current:
65001
After prepending:
65001 65001 65001
Configuration:
R1(config)# route-map PREPEND permit 10
R1(config-route-map)# set as-path prepend 65001 65001 65001
R1(config)# router bgp 65001
R1(config-router)# neighbor 192.168.2.1 route-map PREPEND out
Result:
ISP sees:
65001 65001 65001
instead of
65001
and may choose another path.
Verify:
show ip bgp
Comments
Post a Comment