The other half of the problem
The last lesson steered outbound traffic with local preference. Replies and new connections arrive the other way, and the path they take is decided by other networks reading the routes you advertise. If both ISPs carry 198.51.100.0/24 with the same attributes, remote networks pick whichever looks best to them, and half the world may arrive through the backup link.
On small screens, swipe sideways or focus the diagram and use the arrow keys.
You cannot overwrite their choice. You can make the backup path look worse.
AS path prepending
The best-path algorithm prefers a shorter AS_PATH. Prepending adds extra copies of your own AS number to the routes you send to one ISP, so that path looks longer. The route is still valid and still a backup.
On small screens, swipe sideways or focus the diagram and use the arrow keys.
route-map ISPB-OUT permit 10
match ip address prefix-list COMPANY-ONLY
set as-path prepend 64500 64500 64500
router bgp 64500
address-family ipv4 unicast
neighbor 192.0.2.5 route-map ISPB-OUT out
exit-address-family
end
clear ip bgp 192.0.2.5 soft outR2, global configuration mode, then privileged EXEC for the last line. Three extra copies of 64500 are added when advertising to ISP B. Always prepend your own AS number, not someone else's.
Check what a neighbour would receive without logging in to it:
R2#show ip bgp neighbors 192.0.2.5 advertised-routes Network Next Hop Metric LocPrf Weight Path *> 198.51.100.0 0.0.0.0 0 32768 64500 64500 64500 64500 i Total number of prefixes 1
MED: a hint to a neighbouring AS
The multi-exit discriminator tells one neighbouring AS which of several links into your AS you prefer. Lower wins. It is useful if you connect to the same provider in two places.
On small screens, swipe sideways or focus the diagram and use the arrow keys.
MED has three limits. By default it is compared only between paths from the same neighbouring AS, so it cannot choose between ISP A and ISP B. The receiving AS does not pass it on to other ASes. And it ranks low in the order, below weight, local preference and AS_PATH length, so any of those can override it.
route-map TO-ISPA permit 10
match ip address prefix-list COMPANY-ONLY
set metric 50
router bgp 64500
address-family ipv4 unicast
neighbor 192.0.2.1 route-map TO-ISPA outR1: advertises the company prefix to ISP A with MED 50. A second link to ISP A would advertise a higher MED so ISP A prefers this one.
How many prepends
One extra copy of your AS number rarely changes anything, and ten is excessive: paths on the internet are mostly four to six ASes long, so a few additional copies are enough to push a path behind a rival that has the default local preference. Start with two or three, check the result from the outside, and add one at a time.
On small screens, swipe sideways or focus the diagram and use the arrow keys.
Splitting by prefix: some prefixes each way
On small screens, swipe sideways or focus the diagram and use the arrow keys.
Prepending the same on every prefix sends everyone to one provider. If you own two prefixes you can balance the links: prepend prefix A towards ISP B and prefix B towards ISP A. Each prefix has a primary path and the other is the backup.
ip prefix-list NET-A seq 5 permit 198.51.100.0/25
ip prefix-list NET-B seq 5 permit 198.51.100.128/25
!
route-map TO-ISPB permit 10
match ip address prefix-list NET-A
set as-path prepend 64500 64500 64500
route-map TO-ISPB permit 20
!
route-map TO-ISPA permit 10
match ip address prefix-list NET-B
set as-path prepend 64500 64500 64500
route-map TO-ISPA permit 20
!
router bgp 64500
address-family ipv4 unicast
neighbor 192.0.2.5 route-map TO-ISPB out
neighbor 192.0.2.1 route-map TO-ISPA outR2 and R1. Traffic for NET-A comes in via ISP A and for NET-B via ISP B. The empty permit sequence at the end lets everything else through unchanged: without it the implicit deny would drop other routes.
Checking from the outside
You cannot see the other network's choice from your own router, so look from outside. Many providers and research projects run looking glass servers: web or command line tools that run show ip bgp from their router. Ask one in a distant AS for your prefix and read the AS path it chose.
On small screens, swipe sideways or focus the diagram and use the arrow keys.
Why this is a request, not a command
Inbound policy changes what neighbours see. It cannot change what they decide. A provider can set local preference on every route from a customer, ignore MED, strip prepends or filter them. Treat every inbound change as an experiment: apply it, then check from outside, for example with a looking glass that your provider publishes, and use a longer prepend only if the result does not move.
On small screens, swipe sideways or focus the diagram and use the arrow keys.
Technical reference: RFC 4271 defines AS_PATH and MED. Output above is illustrative.
Check your inbound policy
You prepend three times on R2 toward ISP B. Remote networks still use ISP B. What is the likely reason?
You advertise MED 10 to ISP A and MED 20 to ISP B. Does that make remote networks prefer ISP A?
What does set as-path prepend 64500 64500 do on a route sent to an ISP?