Skip to content
Apr 28 / Greg

Cisco BGP Prepend All Routes – The Lazy Way

One man’s lazy is another man’s efficient. I’m the most efficient guy you know 😛

Prepending is adding your AS number to BGP NLRI multiple times to make a set of routes look further away and thus less preferred.

Without Prepending:

1
2
3
Router# show ip bgp 1.1.1.0/24
BGP routing table entry for 1.1.1.0/24, version 555663701
  65001 4323 15169, (received & used)

With Prepending:

1
2
3
Router# show ip bgp 1.1.1.0/24
BGP routing table entry for 1.1.1.0/24, version 555663701
  65001 65001 65001 4323 15169, (received & used)

As you can see, in the second entry with prepending the AS distance to the route was 2 AS hops further away, and thus less preferred.

Say for example a customer wants you to prepend every route to them. The customer could just adjust local preference on their side, but if they aren’t comfortable with that, you can do the adjustment to prepending for them.

First, we create a route map that will do the prepending:

1
2
3
route-map bgp->prepend permit 10 !create the map
 description :: Prepend 2 times to routes !always add a description ALWAYS
 set as-path prepend 65001 65001 !add the prepending command

Normally on a route-map statement you are required to use a “match” command. In the match command you will use something like an access-list or a prefix-list to specify which NLRI to act upon. In our case we wanted to act on everything. If you simply omit the match statement it uses an implicit “any”, and will capture everything.

We then add the route-map to the neighbor:

1
2
3
4
5
6
router bgp 65001 !enter your BGP process
 address-family ipv4 !enter the v4 address family
 neighbor 10.0.0.1 route-map bgp->prepend out !assign our new route-map to the peer outgoing
exit !get back to config mode
exit !get back to enable mode
clear ip bgp 10.0.0.1 soft out !do a soft clear on the peer to send the new prepending towards the

That’s just about as few lines as you can use to prepend everything. I like using route-maps like this because if later on down the road I want to adjust them again, I just add an incremented statement 🙂

Leave a Comment

 

*