Using Regex to Prepend AS Numbers to the BGP AS_PATH Attribute
Resolution
Overview
There are different attributes that determine how BGP chooses the path to reach a destination prefix/network. Network administrators/engineers can influence these attributes to match their network requirements. This document describes how to manipulate the AS_path (Autonomous System path) attribute, using regular expressions.
Network Scenario
The following topology will be used for this document.
Prerequisites
Export the loopback prefix 10.10.20.10/32 to the eBGP peer "ISP_A", but prepend the local AS 3 times to the original AS-Path.
Steps
- Go to Network > Virtual Routers > Select your router
- Next, locate BGP > Export
- Enter a rule name, enable the rule, and select the appropriate eBGP peer
- In the Match tab, enter ^$ for the regex expression and add the address prefix that you are trying to modify AS_path for. The expression, ^$, was chosen as the preferred regex because the prefix originated from this AS. If you want to modify the AS_Path for all prefixes, then leave the address prefix field blank.
- In the Action tab, set Action to 'Allow' and configure the desired AS Path prepend number. For this requirement, we have chosen to enter 3.
- Press OK and the Export rule should look like the following:
Note: If the configuration is committed at this point, the prepend will work but only the prefix 10.10.20.10/32 will be exported to the eBGP peer.
There is an implicit deny rule that is triggered once any rules are created in the export or import tabs. (The same is true for OSPF export).
Add an allow rule to make sure you're exporting other prefixes. The Export tab should now appear like the following: - Commit and verify
Verification
Before the example configuration, the AS Path advertised for 10.10.20.10/32 consisted of only one instance of 2345 as shown on the screenshot below:
After the configuration, the AS Path advertised for 10.10.20.10/32 now consists three instances of 2345 as shown below:
Other Regular Expressions:
^$ - Routes that originated from this AS
_2345_ - Routes that passed through 2345
^2345_ - Routes learned by 2345
_2345$ - Routes originated from AS 2345. (Could sometimes be same as ^$)
(400|500|600) - Match either 400, 500 or 600
See Also
For more Regex Combinations, see Regular expression syntax for patterns in custom app signatures
owner: tasonibare