9 mins read

BGP – remove-private

1. Intro

When advertising AS paths to remote systems, have the local system strip private AS numbers from the AS path. The numbers are stripped from the AS path starting at the left end of the AS path (the end where AS paths have been most recently added). The routing device stops searching for private ASs when it finds the first nonprivate AS or a peer’s private AS. If the AS path contains the AS number of the external BGP (EBGP) neighbor, BGP does not remove the private AS number.

We will put this to the test using the following setup:

In our setup, R2 is receiving the 192.168.50.0/26 prefix from R3, but this prefix was originated many hops away. Before R2 will advertise the 192.168.50.0/26 to R1, it will strip away the private AS numbers.

The configuration template is basic. The BGP group TO-R1 will be configured with different remove-private options. We will configure different AS numbers to explore different scenarios, but the template is the following:

2. remove-private

Initially, the remove-private knob is not configured.

If we read again the definition, we see the following:

  • the numbers are stripped from the AS path starting at the left end (AS path: 65310 65320 65300 400 65500 65500 65500 I)
  • the routing device stops searching for private ASs when it finds the first nonprivate AS (in our case, this is AS 400)

3. remove-private all

But what if we want to remove all private AS numbers? then we just add the ‘remove-private all‘ knob.

4. remove-private all replace

When the all knob is configured, instead of removing, we can also replace the AS numbers:

But this is not ideal, we have an as-path loop for AS 200. We will fix this next.

5. remove-private all replace nearest

To remove the as-path loop we created in the previous section for AS 200 we can use the nearest knob:

We can see that 65500 65500 65500 AS numbers were replaced with the nearest AS number: 400 400 400. This looks better now.

6. First AS is nonprivate

The routing device stops searching for private ASs when it finds the first nonprivate AS, but what if the 1st AS in the path is a non private one?

As the definition is saying, stop at the 1st non private AS number. So, if the 1st AS is a non private one, then no action is taken.

To remove the ‘stop at the 1st non private AS number’ rule, we can add the all knob.

7. no-peer-loop-check

This will apply in a very specific use case, let’s see the official documentation:

By default, the remove-private statement has a peer loop check restriction. If a private AS in the AS path has the same value as the configured peer-as for the neighbor, remove-private does not remove or replace this private AS number. This restriction provides peer-as loop protection. However, you can remove this restriction using the no-peer-loop-check option.

To test this ourselves, let’s reset the setup so that R1 and R3 have the same 65100 AS:

While this can be a safety mechanism for as-path loop prevention, we can override this by applying the ‘no-peer-loop-check‘ knob, to force R2 to remove the private AS.


External Resources: