← Back to portfolio
network-labs / bgp / BGP-RouteMap-PathSelection
πŸ“„ README.md CML Lab

πŸ”€ BGP Route Map & Path Selection Lab

⚑ Intermediate ⏱ ~90 minutes πŸŽ“ CCNP-level

This lab gives you hands-on practice manipulating BGP path selection using route-maps, prefix-lists, AS-path prepending, local preference, MED, and communities. You will control how traffic enters and leaves your autonomous system by modifying BGP attributes at each peer boundary.

πŸ—ΊοΈ Topology

  Loopbacks: 10.1.1.0/24         Loopbacks: 10.3.1.0/24
             10.1.2.0/24                    10.3.2.0/24
                  β”‚                               β”‚
        β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”       β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”
        β”‚       R1           β”‚       β”‚       R3              β”‚
        β”‚   AS 100           β”‚       β”‚   AS 300              β”‚
        β”‚   1.1.1.1/32       β”‚       β”‚   3.3.3.3/32         β”‚
        β””β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜       β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”˜
                 β”‚ 192.168.12.0/24                  β”‚ 192.168.23.0/24
                 β”‚                                  β”‚
        β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
        β”‚                  R2                        β”‚
        β”‚              AS 200                        β”‚
        β”‚           2.2.2.2/32                       β”‚
        β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                                  β”‚ 192.168.24.0/24
                                  β”‚
                      β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”
                      β”‚       R4            β”‚
                      β”‚   AS 400            β”‚
                      β”‚   4.4.4.4/32       β”‚
                      β”‚ Loopbacks:          β”‚
                      β”‚  10.3.1.0/24        β”‚
                      β”‚  10.3.2.0/24        β”‚
                      β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
RouterASRouter-IDInterfacesRole
R11001.1.1.1Gi0/0 β†’ 192.168.12.1BGP Client / Traffic Source
R22002.2.2.2Gi0/0 Gi0/1 Gi0/2Hub / Route Reflector candidate
R33003.3.3.3Gi0/0 β†’ 192.168.23.3Primary upstream / prefix source
R44004.4.4.4Gi0/0 β†’ 192.168.24.4Alternate upstream / prefix source
ℹ️

R3 and R4 both advertise 10.3.1.0/24 and 10.3.2.0/24 into R2. This deliberate overlap is what makes the path-selection exercises meaningful β€” R2 must choose between two valid paths.

πŸ“‹ Prerequisites

πŸš€ Getting Started

Step 1 β€” Import and Start the Lab

  1. Log in to your CML instance.
  2. Click Labs β†’ Import and upload bgp-routemap-lab.yaml.
  3. Click Start Lab and wait for all nodes to reach the Running state (β‰ˆ 2–3 minutes for IOSv).
  4. Open a console to each router.

Step 2 β€” Verify BGP Neighbour State

On R2, confirm all three peers are established:

R2# show bgp ipv4 unicast summary

Expected output β€” all neighbours should show a numeric value in the State/PfxRcd column (not Idle or Active):

Neighbor        V           AS MsgRcvd MsgSent   TblVer  InQ OutQ Up/Down  State/PfxRcd
192.168.12.1    4          100      12      12        7    0    0 00:05:12        3
192.168.23.3    4          300      10      10        7    0    0 00:05:08        3
192.168.24.4    4          400      10      10        7    0    0 00:05:04        3
R2# show bgp ipv4 unicast

You should see 10.3.1.0/24 and 10.3.2.0/24 with two candidate paths each (from AS300 and AS400).


πŸ§ͺ Lab Exercises

Exercise 1 β€” Local Preference (Outbound from R2's Perspective)

Outbound Local Pref

Scenario: R2 receives 10.3.1.0/24 from both R3 (AS300) and R4 (AS400). By default, the tie-break may be arbitrary. Force R2 to always prefer the path via R3 for this prefix by setting a higher local preference.

Task 1.1 β€” Create a prefix-list and route-map on R2

R2(config)# ip prefix-list PREFER-R3 seq 10 permit 10.3.1.0/24

R2(config)# route-map SET-LOCALPREF-R3 permit 10
R2(config-route-map)#  match ip address prefix-list PREFER-R3
R2(config-route-map)#  set local-preference 200
R2(config-route-map)# exit
R2(config)# route-map SET-LOCALPREF-R3 permit 20
R2(config-route-map)# exit

Task 1.2 β€” Apply inbound to the R3 neighbour

R2(config)# router bgp 200
R2(config-router)#  neighbor 192.168.23.3 route-map SET-LOCALPREF-R3 in
R2(config-router)#  end
R2# clear ip bgp 192.168.23.3 soft in

Task 1.3 β€” Verify

R2# show bgp ipv4 unicast 10.3.1.0/24

The best path (>) should now show Local preference 200 via 192.168.23.3.

πŸ’‘

BGP Decision rule: Higher local preference wins. Default is 100. Local preference is only meaningful within the same AS β€” it is not propagated to eBGP peers.


Exercise 2 β€” AS-Path Prepending (Influence Inbound Traffic)

Inbound AS-Path

Scenario: You want external ASes to prefer sending traffic for 10.3.2.0/24 via R3. Prepend extra AS hops on the advertisement sent to R4 to make that path look longer (less preferred).

Task 2.1 β€” Create a prefix-list for the target prefix on R2

R2(config)# ip prefix-list PREPEND-OUT seq 10 permit 10.3.2.0/24

Task 2.2 β€” Route-map to prepend AS 200 three times outbound to R4

R2(config)# route-map PREPEND-TO-R4 permit 10
R2(config-route-map)#  match ip address prefix-list PREPEND-OUT
R2(config-route-map)#  set as-path prepend 200 200 200
R2(config-route-map)# exit
R2(config)# route-map PREPEND-TO-R4 permit 20
R2(config-route-map)# exit

Task 2.3 β€” Apply outbound to R4

R2(config)# router bgp 200
R2(config-router)#  neighbor 192.168.24.4 route-map PREPEND-TO-R4 out
R2(config-router)#  end
R2# clear ip bgp 192.168.24.4 soft out

Task 2.4 β€” Verify from R4's perspective

R4# show bgp ipv4 unicast 10.3.2.0/24

The path via R2 should now show a longer AS-path: 200 200 200 300. If R4 has another path available it will prefer it; otherwise this path remains best but is now less attractive to any downstream peers.


Exercise 3 β€” MED (Multi-Exit Discriminator)

Inbound MED

Scenario: R2 wants to tell R1 which of its two upstream links (via R3 or via R4) to prefer for return traffic to 2.2.2.2/32. Use MED to signal link preference to R1.

Task 3.1 β€” Set MED on advertisements to R1

R2(config)# route-map SET-MED-LOW permit 10
R2(config-route-map)#  set metric 50
R2(config-route-map)# exit

R2(config)# router bgp 200
R2(config-router)#  neighbor 192.168.12.1 route-map SET-MED-LOW out
R2(config-router)#  end
R2# clear ip bgp 192.168.12.1 soft out

Task 3.2 β€” Verify on R1

R1# show bgp ipv4 unicast 2.2.2.2/32

The route should show metric 50 in the BGP table. A lower MED is preferred (when comparing paths from the same neighbouring AS).

⚠️

MED is only compared between paths received from the same neighbouring AS by default. Enable bgp always-compare-med under the BGP process if you want MED compared across different ASes β€” but understand the implications before using it in production.


Exercise 4 β€” BGP Communities

Communities Policy

Scenario: R1 tags its prefixes with a community value, and R2 applies different local preferences based on that community β€” a common ISP policy pattern.

Task 4.1 β€” R1 tags 10.1.1.0/24 with community 100:500

R1(config)# ip prefix-list TAG-PREFIX seq 10 permit 10.1.1.0/24

R1(config)# route-map TAG-COMMUNITY permit 10
R1(config-route-map)#  match ip address prefix-list TAG-PREFIX
R1(config-route-map)#  set community 100:500
R1(config-route-map)# exit
R1(config)# route-map TAG-COMMUNITY permit 20
R1(config-route-map)# exit

R1(config)# router bgp 100
R1(config-router)#  neighbor 192.168.12.2 route-map TAG-COMMUNITY out
R1(config-router)#  end
R1# clear ip bgp 192.168.12.2 soft out

Task 4.2 β€” R2 matches community 100:500 and sets local preference

R2(config)# ip community-list standard HIGHPREF-COMM permit 100:500

R2(config)# route-map COMM-LOCALPREF permit 10
R2(config-route-map)#  match community HIGHPREF-COMM
R2(config-route-map)#  set local-preference 300
R2(config-route-map)# exit
R2(config)# route-map COMM-LOCALPREF permit 20
R2(config-route-map)# exit

R2(config)# router bgp 200
R2(config-router)#  neighbor 192.168.12.1 route-map COMM-LOCALPREF in
R2(config-router)#  end
R2# clear ip bgp 192.168.12.1 soft in

Task 4.3 β€” Verify community and local pref on R2

R2# show bgp ipv4 unicast 10.1.1.0/24

Look for Local preference: 300 and the community 100:500 in the detailed output.


Exercise 5 β€” Filter with Prefix-List (Inbound)

Filtering

Scenario: R2 should not accept 10.3.2.0/24 from R4 at all β€” only from R3.

Task 5.1 β€” Create a deny prefix-list and apply inbound from R4

R2(config)# ip prefix-list BLOCK-FROM-R4 seq 5  deny   10.3.2.0/24
R2(config)# ip prefix-list BLOCK-FROM-R4 seq 10 permit 0.0.0.0/0 le 32

R2(config)# router bgp 200
R2(config-router)#  neighbor 192.168.24.4 prefix-list BLOCK-FROM-R4 in
R2(config-router)#  end
R2# clear ip bgp 192.168.24.4 soft in

Task 5.2 β€” Verify the prefix is now only learned from R3

R2# show bgp ipv4 unicast 10.3.2.0/24

Only one path should remain β€” via 192.168.23.3 (R3 / AS300). The R4 path should be gone.


βœ… Verification Checklist

Use this checklist to confirm you have completed all exercises:


πŸ“Š BGP Path Selection Order β€” Quick Reference

#AttributePreferScope
1WeightHigherCisco local only
2Local PreferenceHigherWithin AS
3Locally originatedLocal winsβ€”
4AS Path LengthShortereBGP
5OriginIGP > EGP > ?β€”
6MEDLowerSame neighbour AS
7eBGP over iBGPeBGPβ€”
8IGP metric to next-hopLowerβ€”
9Router IDLowerTiebreak

πŸ”§ Useful Commands

! Show full BGP table
show bgp ipv4 unicast

! Show detail for a specific prefix
show bgp ipv4 unicast 10.3.1.0/24

! Show neighbour summary
show bgp ipv4 unicast summary

! Show all routes received from a peer (before policy)
show bgp ipv4 unicast neighbors 192.168.23.3 received-routes

! Show routes advertised to a peer (after policy)
show bgp ipv4 unicast neighbors 192.168.23.3 advertised-routes

! Soft reset inbound (re-apply inbound policy without dropping session)
clear ip bgp 192.168.23.3 soft in

! Soft reset outbound
clear ip bgp 192.168.23.3 soft out

! Debug BGP updates (use sparingly)
debug ip bgp 192.168.23.3 updates

πŸŽ“ Challenge Extensions

Completed the core exercises? Try these additional challenges:

πŸ†

Pro tip: Use show bgp ipv4 unicast neighbors X.X.X.X policy on newer IOS-XE versions to see exactly which route-maps and prefix-lists are applied to a peer in each direction.


Lab version 1.0  Β·  Platform: Cisco Modeling Labs 2.x  Β·  Node type: IOSv  Β·  Topology: 4 routers / 3 eBGP sessions


Exercise Screenshots

Exercise_1_results.png
Exercise_1_results
Exercise_2_Results.png
Exercise_2_Results
Exercise_3_results.png
Exercise_3_results
Exercise_5_results.png
Exercise_5_results