🌐 BGP (Border Gateway Protocol) - Internet protocol

 

🌐 BGP (Border Gateway Protocol)


🧠 Top 5 Key Points

  1. Path Vector Routing Protocol:
    BGP makes routing decisions based on path attributes, policies, and rules, not just metrics like OSPF or EIGRP.

  2. Used for Internet Routing:
    It’s the protocol that runs the Internet, connecting different Autonomous Systems (AS) — typically ISPs, enterprises, and data centers.

  3. Exterior Gateway Protocol (EGP):
    Unlike OSPF or EIGRP (Interior Gateway Protocols), BGP operates between autonomous systems, not within one.

  4. TCP Port 179:
    BGP forms neighbor relationships (peering) over TCP port 179 for reliable communication.

  5. BGP table will have 30 lakh routes information.

  6. 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

PC1 -- R1 -- R2 -- PC2

IP Address Plan

DeviceInterfaceIP AddressNetworkAS Number
R1G0/0192.168.1.1192.168.1.0/24    65001   (ISP 1)
S0/0/010.0.0.110.0.0.0/30    65001   (ISP 1)
R2S0/0/010.0.0.210.0.0.0/30     65002   (ISP 2)
G0/0192.168.2.1192.168.2.0/24    65002   (ISP 2)
PC1NIC192.168.1.10192.168.1.0/24    —
PC2NIC192.168.2.10192.168.2.0/24     —

🪜 Step-by-Step Configuration

🔹 R1 (AS 65001)

enable conf t interface g0/0 ip address 192.168.1.1 255.255.255.0 no shutdown exit interface s0/0/0 ip address 10.0.0.1 255.255.255.252 clock rate 64000 no shutdown exit router bgp 65001 neighbor 10.0.0.2 remote-as 65002 network 192.168.1.0 mask 255.255.255.0

🔹 R2 (AS 65002)

enable conf t interface s0/0/0 ip address 10.0.0.2 255.255.255.252 no shutdown exit interface g0/0 ip address 192.168.2.1 255.255.255.0 no shutdown exit router bgp 65002 neighbor 10.0.0.1 remote-as 65001 network 192.168.2.0 mask 255.255.255.0

🔍 Verification Commands

show ip bgp summary

➡ Shows BGP neighbor relationships and AS numbers.

show ip bgp

➡ Displays the BGP routing table.

show ip route bgp

➡ Shows BGP-learned routes (marked with “B”).


💡 Testing

From PC1, ping PC2:

ping 192.168.2.10

✅ If successful → BGP routes are properly exchanged between AS 65001 and AS 65002.


🧠 What Students Learn

ConceptDescription
BGP TypePath Vector
Use CaseRouting between ISPs or organizations
eBGP PeeringBetween different AS numbers
Transport ProtocolTCP port 179
Metric BasisPath 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:

  • network command
  • 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:

  1. Weight
  2. Local Preference
  3. Local Origin
  4. AS Path
  5. Origin
  6. MED
  7. eBGP over iBGP
  8. IGP Metric
  9. Oldest Path
  10. Router ID
  11. 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

AttributePreference
WeightHigher
Local PreferenceHigher
AS PathShorter
OriginIGP
MEDLower
eBGP/iBGPeBGP
IGP CostLower
Router IDLower

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




BGP issues

BGP issues generally fall into a few common categories. If you know these, you'll be able to troubleshoot most BGP problems in labs and production.

1. BGP Neighbor Not Established

Symptoms:

  • show ip bgp summary shows:
    • Idle
    • Connect
    • Active

Common causes:

  • IP connectivity issue
  • Wrong neighbor IP
  • Incorrect remote AS
  • ACL or firewall blocking TCP port 179
  • Missing update-source for loopback peering
  • Missing ebgp-multihop when peers are not directly connected

Commands:

show ip bgp summary
ping <neighbor-IP>
show ip route

2. BGP Established but No Routes Received

Symptoms:

  • Neighbor is Established
  • Prefixes received = 0

Common causes:

  • Neighbor isn't advertising any routes
  • Route filtering with prefix lists or route maps
  • Route doesn't exist in neighbor's routing table
  • Incorrect network statement

Commands:

show ip bgp
show ip bgp neighbors

3. Network Statement Not Advertising

Example:

router bgp 65001
network 10.1.1.0 mask 255.255.255.0

The route is advertised only if an exact matching route exists in the local routing table.

For example:

Routing table:

10.1.1.0/24

Advertisement succeeds.

Routing table:

10.1.0.0/16

Advertisement fails because it isn't an exact /24 match.


4. Next-Hop Unreachable

Example:

BGP Table
Network: 20.1.1.0
Next Hop: 192.168.100.1

If the router cannot reach 192.168.100.1, the route won't be installed.

Check:

show ip bgp
show ip route

5. iBGP Next-Hop Issue

In iBGP, the next hop is not changed by default.

Example:

R1 ---- R2 ---- R3
eBGP iBGP

R2 advertises a route to R3 but keeps R1 as the next hop.

If R3 can't reach R1, the route is unusable.

Solution:

neighbor x.x.x.x next-hop-self

6. Route Filtering

Routes may be blocked by:

  • Prefix lists
  • Access lists
  • Route maps
  • AS path filters
  • Community filters

Check:

show run | section bgp

7. Incorrect AS Number

Example:

R1:

neighbor 10.1.1.2 remote-as 65002

R2:

router bgp 65003

The session won't establish because the AS numbers don't match the configuration.


8. Synchronization (Legacy)

Older BGP implementations required synchronization with the IGP before advertising routes.

Modern Cisco routers have synchronization disabled by default, so this is rarely encountered today.


9. Route Flapping

A route repeatedly appears and disappears.

Causes include:

  • Interface instability
  • Physical link problems
  • Unstable upstream connectivity

You may see the BGP session reset frequently.


10. BGP Attributes Causing Unexpected Path Selection

A router may choose an unexpected path because of attributes such as:

  • Weight
  • Local Preference
  • AS Path
  • MED
  • Origin
  • eBGP over iBGP
  • IGP metric to next hop

Review:

show ip bgp

11. Maximum Prefix Limit Reached

If configured:

neighbor 10.1.1.2 maximum-prefix 100

Receiving more than 100 prefixes can cause the neighbor session to be shut down to protect the router.


12. TTL Problems in eBGP

eBGP neighbors expect a TTL of 1 by default.

If they're not directly connected, the session won't establish unless you configure:

neighbor x.x.x.x ebgp-multihop 2

(or a higher value as needed).


Common troubleshooting commands

show ip bgp summary
show ip bgp
show ip bgp neighbors
show ip route
show run | section bgp
show ip bgp neighbors advertised-routes
show ip bgp neighbors received-routes

Interview tip

If you're asked, "A BGP neighbor is stuck in Active state. What do you check?", a good answer is:

  1. Verify IP connectivity (ping, routing table).
  2. Confirm the neighbor IP and remote-as are correct.
  3. Check that TCP port 179 isn't being blocked.
  4. Verify update-source and ebgp-multihop if required.
  5. Review BGP logs and neighbor status with show ip bgp summary and show ip bgp neighbors.

Comments

Popular posts from this blog

🖧 VLAN (Virtual Local Area Network)

🌐 NAT (Network Address Translation)

🛰️ OSPF (Open Shortest Path First)