BGP path selection: how routers choose a route
Learn how BGP compares routes to the same network, how policy changes the result, and how to check the selected path.
Routing / Field note
Use Local Preference, AS_PATH, and MED to guide BGP traffic while understanding what each network controls.
Traffic engineering means guiding traffic toward a route that fits the network's needs. A team may prefer one provider for lower cost, keep another as backup, or ask a neighbor to use a certain link.
BGP offers useful policy tools, but each AS runs its own policy. A change in your network can influence a neighbor; it cannot force the neighbor to follow your choice.
From your AS's point of view:
The place where you apply a policy matters. An inbound policy changes routes as your router receives them, which can change your outbound path. An outbound policy changes how your router advertises routes, which may influence a neighbor's inbound choice.
Local Preference tells routers in one AS which exit they should prefer. A higher value wins when routes reach the Local Preference comparison. In the shared simulator topology, Corp-X (AS 64531) receives Path A from ISP-B (AS 64520) and Path B from ISP-C (AS 64540). Both start at 100. Setting Path B to 200 makes Corp-X prefer the ISP-C exit, before it compares later attributes.
ip prefix-list LAB-DESTINATION seq 5 permit 192.0.2.0/24
route-map PREFER-ISP-C permit 10
match ip address prefix-list LAB-DESTINATION
set local-preference 200
!
router bgp 64531
neighbor 10.0.4.1 route-map PREFER-ISP-C inThis Cisco IOS-XE example applies the policy to the route received from ISP-C router C1 at 10.0.4.1. A route map can deny routes that do not match a permit entry. If the neighbor sends other routes, add the correct approved policy before using this pattern. Review the effect in a lab first.
Your neighbor makes its own best-path choice, but you can send policy hints with your advertisements.
An AS can add its own AS number more than once when it advertises a route. This makes the path appear longer to some neighbors. They may then choose a different route. In the simulator, Path A runs through ISP-B AS 64520 and Path B through ISP-C AS 64540. Prepending AS 64512 on the ISP-A-to-ISP-B advertisement makes Path A appear longer to Corp-X. A neighbor's Local Preference or other policy can still take priority, so prepending is not a promise about the final path.
ip prefix-list LAB-DESTINATION seq 5 permit 192.0.2.0/24
route-map PREPEND-TO-ISP-B permit 10
match ip address prefix-list LAB-DESTINATION
set as-path prepend 64512 64512
!
router bgp 64512
neighbor 10.0.2.1 route-map PREPEND-TO-ISP-B outApply the outbound policy on ISP-A router A1 toward ISP-B router B1 (10.0.2.1). The simulator's AS_PATH preset models this change on Path A.
MED is a hint that can suggest which entry point a neighboring AS should use to reach your network. A lower MED is commonly preferred when comparing routes learned from the same neighboring AS. The other network chooses whether and how to compare it. In the simulator, Path A arrives from ISP-B AS 64520 and Path B from ISP-C AS 64540, so the MED preset enables an explicit cross-AS comparison. Real routers often do not compare those values by default.
ip prefix-list LAB-DESTINATION seq 5 permit 192.0.2.0/24
route-map MED-TO-ISP-B permit 10
match ip address prefix-list LAB-DESTINATION
set metric 50
!
route-map MED-TO-ISP-C permit 10
match ip address prefix-list LAB-DESTINATION
set metric 10
!
! Add each neighbor policy on the matching ISP-A router.
! On ISP-A A1, which peers with ISP-B B1:
router bgp 64512
neighbor 10.0.2.1 route-map MED-TO-ISP-B out
!
! On ISP-A A2, which peers with ISP-C C1:
router bgp 64512
neighbor 10.0.4.1 route-map MED-TO-ISP-C outThis shows the Cisco IOS-XE route-map form. Configure each neighbor on its matching ISP-A router. Confirm the exact command and MED comparison behavior on your router. Do not assume Corp-X or another neighbor compares MED from different ASes unless its policy says it does.
show ip bgp 192.0.2.0/24
show ip bgp neighbors 10.0.2.1 routes
show ip bgp neighbors 10.0.4.1 routes
show ip route 192.0.2.0Command names vary by platform. Check the relevant command reference before making a live network change.
Quick answers about exit paths, inbound traffic, and policy limits.
3 answersDoes Local Preference change inbound traffic?
Local Preference guides route choice inside your own AS, so it mainly changes outbound traffic. AS_PATH prepending, MED, and provider communities may influence inbound traffic, but the other AS controls its own routes.
Is AS_PATH prepending guaranteed to move traffic?
No. A neighbor may prefer its own Local Preference or use another policy before it considers AS_PATH length.
Should I change MED on all routes?
No. Start with the prefixes and neighbor where the value has a clear purpose. Confirm the neighbor's policy and MED comparison behavior first.
Continue with the BGP route-selection guide or practice these decisions in the BGP learning experience.
Continue reading
Learn how BGP compares routes to the same network, how policy changes the result, and how to check the selected path.
Configure a small two-router eBGP lab, advertise one route from each side, and check the session safely.
Reader signal
Your feedback helps shape the next field note and lab.
Views count when this page opens. You can change or remove your vote during this tab session.