Using Regex to Prepend AS Numbers to the BGP AS_PATH Attribute

Using Regex to Prepend AS Numbers to the BGP AS_PATH Attribute

29651
Created On 09/25/18 17:51 PM - Last Modified 06/13/23 13:54 PM


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.

Export pix.PNG.png

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

  1. Go to Network > Virtual Routers > Select your router
  2. Next, locate BGP > Export
  3. Enter a rule name, enable the rule, and select the appropriate eBGP peer
    Export ISP_A genereal.PNG
  4. 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.
    Export ISP_A match.PNG
  5. 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.
    Export ISP_A Action.PNG
  6. Press OK and the Export rule should look like the following:
    Export ISP_A.PNG
    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:
    Export ISP_A Everything.PNG
  7. 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:

Export pre.PNG                                                                                           

After the configuration, the AS Path advertised for 10.10.20.10/32 now consists three instances of 2345 as shown below:

Export after.PNG

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



Actions
  • Print
  • Copy Link

    https://knowledgebase.paloaltonetworks.com/kcSArticleDetail?id=kA10g000000ClKy&refURL=http%3A%2F%2Fknowledgebase.paloaltonetworks.com%2FkcSArticleDetail

Choose Language