Select Page

AS-Path PrepenD

Prepend the AS Path | BGP

Shortest AS-Path wins by default. Used to influence inbound routing to your AS.

You can prepend one or more autonomous system (AS) numbers at the beginning of an AS path. The AS numbers are added at the beginning of the path after the actual AS number from which the route originates has been added to the path. Prepending an AS path makes a shorter AS path look longer and therefore less preferable to BGP.

Use Case:  If you are an enterprise that has multihoming to one or more service providers, you might prefer that incoming traffic take a particular path to reach your network. Perhaps you have two connections, but one costs less than the other. Or you might have one fast connection and another, much slower connection that you only want to use as a backup if your primary connection is down. AS path prepending is an easy method that you can use to influence inbound routing to your AS.

Juniper vMX 14 & EVE-NG Pro is used for this lab.

 Devices Configuration: 

[email protected]> show configuration |display set 
set version 14.1R4.8
set system host-name R1
set system root-authentication encrypted-password "$1$tO/JJjsr$6UERRBvamum8jyb8WbD5p1"
set system syslog user * any emergency
set system syslog file messages any notice
set system syslog file messages authorization info
set system syslog file interactive-commands interactive-commands any
set interfaces ge-0/0/0 unit 0 family inet address 12.12.12.1/24
set interfaces ge-0/0/1 unit 0 family inet address 13.13.13.1/24
set interfaces lo0 unit 1 family inet address 1.1.1.1/24
set interfaces lo0 unit 1 family inet address 11.11.11.11/24
set routing-options autonomous-system 100
set protocols bgp group iBGP type internal
set protocols bgp group iBGP traceoptions file R1-log
set protocols bgp group iBGP traceoptions flag all
set protocols bgp group iBGP export R1-loop
set protocols bgp group iBGP cluster 1.1.1.1
set protocols bgp group iBGP peer-as 100
set protocols bgp group iBGP neighbor 12.12.12.2
set protocols bgp group iBGP neighbor 13.13.13.3
set policy-options policy-statement R1-loop term t1 from protocol direct
set policy-options policy-statement R1-loop term t1 then accept
 
[email protected]> show configuration |display set 
set version 14.1R4.8
set system host-name R2
set system root-authentication encrypted-password "$1$gQQMnrjZ$0y8.izSPbRBPDQ37sp0t70"
set system syslog user * any emergency
set system syslog file messages any notice
set system syslog file messages authorization info
set system syslog file interactive-commands interactive-commands any
set interfaces ge-0/0/0 unit 0 family inet address 12.12.12.2/24
set interfaces ge-0/0/2 unit 0 family inet address 24.24.24.2/24
set routing-options autonomous-system 100
set protocols bgp group iBGP type internal
set protocols bgp group iBGP export next-hop
set protocols bgp group iBGP peer-as 100
set protocols bgp group iBGP neighbor 12.12.12.1
set protocols bgp group eBGP type external
set protocols bgp group eBGP export PREPEND
set protocols bgp group eBGP peer-as 200
set protocols bgp group eBGP neighbor 24.24.24.4
set policy-options policy-statement PREPEND term t1 then as-path-prepend "100 100 100 100 100"
set policy-options policy-statement next-hop term t1 then next-hop self

 
[email protected]> show configuration |display set 
set version 14.1R4.8
set system host-name R3
set system root-authentication encrypted-password "$1$qwaVLOJm$ZyIK8zBMf5lnBErcYT0mz0"
set system syslog user * any emergency
set system syslog file messages any notice
set system syslog file messages authorization info
set system syslog file interactive-commands interactive-commands any
set interfaces ge-0/0/1 unit 0 family inet address 13.13.13.3/24
set interfaces ge-0/0/3 unit 0 family inet address 35.35.35.3/24
set routing-options autonomous-system 100
set protocols bgp group iBGP type internal
set protocols bgp group iBGP export next-hop
set protocols bgp group iBGP peer-as 100
set protocols bgp group iBGP neighbor 13.13.13.1
set protocols bgp group eBGP type external
set protocols bgp group eBGP peer-as 200
set protocols bgp group eBGP neighbor 35.35.35.5
set policy-options policy-statement next-hop term t1 then next-hop self
 
[email protected]> show configuration |display set    
set version 14.1R4.8
set system host-name R4
set system root-authentication encrypted-password "$1$.PVBvHjK$w5rPIhxtZRpFph6gWcI8M0"
set system syslog user * any emergency
set system syslog file messages any notice
set system syslog file messages authorization info
set system syslog file interactive-commands interactive-commands any
set interfaces ge-0/0/0 unit 0 family inet address 46.46.46.4/24
set interfaces ge-0/0/2 unit 0 family inet address 24.24.24.4/24
set routing-options autonomous-system 200
set protocols bgp group eBGP type external
set protocols bgp group eBGP export PREPEND
set protocols bgp group eBGP peer-as 100
set protocols bgp group eBGP neighbor 24.24.24.2
set protocols bgp group iBGP type internal
set protocols bgp group iBGP export next-hop
set protocols bgp group iBGP peer-as 200
set protocols bgp group iBGP neighbor 46.46.46.6
set policy-options policy-statement PREPEND term t1 from route-filter 66.66.66.0/24 exact
set policy-options policy-statement PREPEND term t1 then as-path-prepend "200 200 200"
set policy-options policy-statement next-hop term t1 then next-hop self
 
[email protected]> show configuration |display set 
set version 14.1R4.8
set system host-name R5
set system root-authentication encrypted-password "$1$k7n8w/wo$8euhVYmjwdLXi0ony6IbP/"
set system syslog user * any emergency
set system syslog file messages any notice
set system syslog file messages authorization info
set system syslog file interactive-commands interactive-commands any
set interfaces ge-0/0/1 unit 0 family inet address 56.56.56.5/24
set interfaces ge-0/0/3 unit 0 family inet address 35.35.35.5/24
set routing-options autonomous-system 200
set protocols bgp group eBGP type external
set protocols bgp group eBGP peer-as 100
set protocols bgp group eBGP neighbor 35.35.35.3
set protocols bgp group iBGP type internal
set protocols bgp group iBGP export next-hop
set protocols bgp group iBGP peer-as 200
set protocols bgp group iBGP neighbor 56.56.56.6
set policy-options policy-statement next-hop term t1 then next-hop self
 
[email protected]> show configuration |display set 
set version 14.1R4.8
set system host-name R6
set system root-authentication encrypted-password "$1$kHQdSe5p$nauLFLu5lENsFFOz2rgTd."
set system syslog user * any emergency
set system syslog file messages any notice
set system syslog file messages authorization info
set system syslog file interactive-commands interactive-commands any
set interfaces ge-0/0/0 unit 0 family inet address 46.46.46.6/24
set interfaces ge-0/0/1 unit 0 family inet address 56.56.56.6/24
set interfaces lo0 unit 6 family inet address 6.6.6.6/24
set interfaces lo0 unit 6 family inet address 66.66.66.66/24
set routing-options autonomous-system 200
set protocols bgp group iBGP type internal
set protocols bgp group iBGP traceoptions file R6-logs
set protocols bgp group iBGP traceoptions flag all
set protocols bgp group iBGP export R6-loop
set protocols bgp group iBGP cluster 6.6.6.6
set protocols bgp group iBGP peer-as 200
set protocols bgp group iBGP neighbor 46.46.46.4
set protocols bgp group iBGP neighbor 56.56.56.5
set policy-options policy-statement R6-loop term t1 from interface lo0.6
set policy-options policy-statement R6-loop term t1 then accept
 
— Configuration | Verification —

AS-PATH: Current path b/w R1 & r6

-- R1 can reach to R6 via R2 & R3:
[email protected]R1> show route 6.6.6.6
inet.0: 10 destinations, 12 routes (10 active, 0 holddown, 0 hidden)
+ = Active Route, - = Last Active, * = Both
6.6.6.0/24 *[BGP/170] 02:33:32, localpref 100
AS path: 200 I, validation-state: unverified
> to 12.12.12.2 via ge-0/0/0.0
[BGP/170] 02:33:32, localpref 100
AS path: 200 I, validation-state: unverified
> to 13.13.13.3 via ge-0/0/1.0

-- R6 can reach to R1 via R4 & R5:
[email protected]R6> show route 1.1.1.1
inet.0: 12 destinations, 14 routes (12 active, 0 holddown, 0 hidden)
+ = Active Route, - = Last Active, * = Both
1.1.1.0/24 *[BGP/170] 02:09:54, localpref 100
AS path: 100 I, validation-state: unverified
> to 46.46.46.4 via ge-0/0/0.0
[BGP/170] 02:09:54, localpref 100
AS path: 100 I, validation-state: unverified
> to 56.56.56.5 via ge-0/0/1.0

Current path: /** R6 --> R1 via R4/R2:
[email protected]> trace 1.1.1.1 source 6.6.6.6
traceroute to 1.1.1.1 (1.1.1.1) from 6.6.6.6, 30 hops max, 40 byte packets
1 46.46.46.4 (46.46.46.4) 1.179 ms 0.784 ms 0.940 ms
2 24.24.24.2 (24.24.24.2) 2.924 ms 1.330 ms 1.184 ms
3 1.1.1.1 (1.1.1.1) 3.829 ms 1.806 ms 1.914 ms

Why this path is taken (from R6 via R4)?
[Because, Inactive reason: Not Best in its group - Router ID]

 

[email protected]R6> show route 1.1.1.0/24 detail 

 

inet.0: 12 destinations, 14 routes (12 active, 0 holddown, 0 hidden)

1.1.1.0/24 (2 entries, 1 announced)

        *BGP    Preference: 170/-101

                Next hop type: Indirect

                Address: 0x969064c

                Next-hop reference count: 9

                Source: 46.46.46.4

                Next hop type: Router, Next hop index: 564

                Next hop: 46.46.46.4 via ge-0/0/0.0, selected

                Session Id: 0x142

                Protocol next hop: 46.46.46.4

                Indirect next hop: 0x9648220 1048575 INH Session ID: 0x143

                State: <Active Int Ext>

                Local AS:   200 Peer AS:   200

                Age: 2:14:31    Metric2: 0 

                Validation State: unverified 

                Task: BGP_200.46.46.46.4+49726

                Announcement bits (3): 0-KRT 1-BGP_RT_Background 2-Resolve tree 1 

                AS path: 100 I

                Accepted

                Localpref: 100

                Router ID: 24.24.24.4   

         BGP    Preference: 170/-101

                Next hop type: Indirect

                Address: 0x96904d0

                Next-hop reference count: 5

                Source: 56.56.56.5

                Next hop type: Router, Next hop index: 565

                Next hop: 56.56.56.5 via ge-0/0/1.0, selected

                Session Id: 0x140

                Protocol next hop: 56.56.56.5

                Indirect next hop: 0x9648110 1048574 INH Session ID: 0x141

                State: <NotBest Int Ext>

                Inactive reason: Not Best in its group – Router ID    <<====

                Local AS:   200 Peer AS:   200

                Age: 2:14:31    Metric2: 0 

                Validation State: unverified 

                Task: BGP_200.56.56.56.5+49316

                AS path: 100 I

                Accepted

                Localpref: 100

                Router ID: 35.35.35.5

 

 

[email protected]> show log R6-logs |match 1.1.1.0 

Apr 16 01:58:37.254667 CHANGE   1.1.1.0/24          nhid 0 gw 46.46.46.4      BGP      pref 170/-101 metric  <Active Int Ext>  as 200

Apr 16 01:58:37.254659 CHANGE   1.1.1.0/24          nhid 0 gw 56.56.56.5      BGP      pref 170/-101 metric  <NotBest Int Ext>  as 200

 
 --- Now, we want to choose path as  /** R6 --> R5 --> R3 --> R1.
We will use AS-Path prepend b/w eBGP peers (R2/R4).
R2>
set policy-options policy-statement PREPEND term t1 then as-path-prepend "100 100 100 100 100"
set protocols bgp group eBGP export PREPEND

 

[email protected]> show log R6-logs |match 1.1.1.0    

Apr 16 02:01:28.801162 CHANGE   1.1.1.0/24          nhid 0 gw 56.56.56.5      BGP      pref 170/-101 metric  <Active Int Ext>  as 200

Apr 16 02:01:28.801185 CHANGE   1.1.1.0/24          nhid 0 gw 46.46.46.4      BGP      pref 170/-101 metric  <Int Ext>  as 200

  /** gw R5 become Active now and R4 become InActive

 

[email protected]> traceroute 1.1.1.1 source 6.6.6.6 

traceroute to 1.1.1.1 (1.1.1.1) from 6.6.6.6, 30 hops max, 40 byte packets

 1  56.56.56.5 (56.56.56.5)  3.521 ms  0.770 ms  0.955 ms

 2  35.35.35.3 (35.35.35.3)  5.784 ms  1.216 ms  1.286 ms

 3  1.1.1.1 (1.1.1.1)  2.956 ms  1.941 ms  1.771 ms

 

[email protected]> show route 1.1.1.0/24 detail 

 

inet.0: 12 destinations, 14 routes (12 active, 0 holddown, 0 hidden)

1.1.1.0/24 (2 entries, 1 announced)

        *BGP    Preference: 170/-101

                Next hop type: Indirect

                Address: 0x96904d0

                Next-hop reference count: 9

                Source: 56.56.56.5

                Next hop type: Router, Next hop index: 565

                Next hop: 56.56.56.5 via ge-0/0/1.0, selected

                Session Id: 0x140

                Protocol next hop: 56.56.56.5

                Indirect next hop: 0x9648110 1048574 INH Session ID: 0x144

                State: <Active Int Ext>

                Local AS:   200 Peer AS:   200

                Age: 5:56       Metric2: 0 

                Validation State: unverified 

                Task: BGP_200.56.56.56.5+179

                Announcement bits (3): 0-KRT 1-BGP_RT_Background 2-Resolve tree 1 

                AS path: 100 I

                Accepted

                Localpref: 100

                Router ID: 35.35.35.5   

         BGP    Preference: 170/-101

                Next hop type: Indirect

                Address: 0x969064c

                Next-hop reference count: 5

                Source: 46.46.46.4

                Next hop type: Router, Next hop index: 564

                Next hop: 46.46.46.4 via ge-0/0/0.0, selected

                Session Id: 0x142

                Protocol next hop: 46.46.46.4

                Indirect next hop: 0x9648220 1048575 INH Session ID: 0x145

                State: <Int Ext>

                Inactive reason: AS path   <<======

                Local AS:   200 Peer AS:   200

                Age: 3:03       Metric2: 0 

                Validation State: unverified 

                Task: BGP_200.46.46.46.4+52665

                AS path: 100 100 100 100 100 100 I   <<== Longest AS-path now.

                Accepted

                Localpref: 100

                Router ID: 24.24.24.4

                 

 

 [email protected]> show route protocol bgp terse active-path 

 

inet.0: 12 destinations, 14 routes (12 active, 0 holddown, 0 hidden)

+ = Active Route, – = Last Active, * = Both

 

A V Destination        P Prf   Metric 1   Metric 2  Next hop        AS path

* 1.1.1.0/24         B 170        100                             100 I

  unverified                                       >56.56.56.5

* 11.11.11.0/24      B 170        100                             100 I

  unverified                                       >56.56.56.5

  

 — Note that path is changed now. R6 –> R5 –> R3 –> R1

 

 -- Lets check R1:
[email protected]> show route protocol bgp terse
inet.0: 10 destinations, 11 routes (10 active, 0 holddown, 0 hidden)
+ = Active Route, - = Last Active, * = Both
A Destination P Prf Metric 1 Metric 2 Next hop AS path
* 6.6.6.0/24 B 170 100 >12.12.12.2 200 I
B 170 100 >13.13.13.3 200 I
* 66.66.66.0/24 B 170 100 >12.12.12.2 200 I
B 170 100 >13.13.13.3 200 I

-- R1 learning R6 subnet 6.6.6.0 and 66.66.66.0 from both R2 and R3.
-- R2 is prefer'd because of the router ID.

[email protected]> show route 66.66.66.0 detail
inet.0: 10 destinations, 12 routes (10 active, 0 holddown, 0 hidden)
66.66.66.0/24 (2 entries, 1 announced)
*BGP Preference: 170/-101
Next hop type: Indirect
Address: 0x96944d0
Next-hop reference count: 6
Source: 12.12.12.2
Next hop type: Router, Next hop index: 564
Next hop: 12.12.12.2 via ge-0/0/0.0, selected
Session Id: 0x142
Protocol next hop: 12.12.12.2
Indirect next hop: 0x964c110 1048574 INH Session ID: 0x14d
State: <Active Int Ext>
Local AS: 100 Peer AS: 100
Age: 45 Metric2: 0
Validation State: unverified
Task: BGP_100.12.12.12.2+179
Announcement bits (3): 0-KRT 1-BGP_RT_Background 2-Resolve tree 1
AS path: 200 I
Accepted
Localpref: 100
Router ID: 12.12.12.2
BGP Preference: 170/-101
Next hop type: Indirect
Address: 0x969464c
Next-hop reference count: 2
Source: 13.13.13.3
Next hop type: Router, Next hop index: 565
Next hop: 13.13.13.3 via ge-0/0/1.0, selected
Session Id: 0x140
Protocol next hop: 13.13.13.3
Indirect next hop: 0x964c220 1048575 INH Session ID: 0x14c
State: <NotBest Int Ext>
Inactive reason: Not Best in its group - Router ID <<==
Local AS: 100 Peer AS: 100
Age: 4:29 Metric2: 0
Validation State: unverified
Task: BGP_100.13.13.13.3+179
AS path: 200 I
Accepted
Localpref: 100
Router ID: 13.13.13.3

Now, From R1 66.66.66.0/24 should use path as R1--> R3 --> R5 --> R6 and all other traffic (6.6.6.0/24) still use R1--> R2 --> R4 --> R6 path.
Apply policy to R4 eBGP peering.

R4>
set policy-options policy-statement PREPEND term t1 from route-filter 66.66.66.0/24 exact
set policy-options policy-statement PREPEND term t1 then as-path-prepend "200 200 200"
set policy-options policy-statement next-hop term t1 then next-hop self
set protocols bgp group eBGP export PREPEND

 

[email protected]R1> show route protocol bgp 

 

inet.0: 10 destinations, 11 routes (10 active, 0 holddown, 0 hidden)

+ = Active Route, – = Last Active, * = Both

 

6.6.6.0/24         *[BGP/170] 00:03:47, localpref 100

                      AS path: 200 I, validation-state: unverified

                    > to 12.12.12.2 via ge-0/0/0.0    <===

                    [BGP/170] 00:07:14, localpref 100

                      AS path: 200 I, validation-state: unverified

                    > to 13.13.13.3 via ge-0/0/1.0

66.66.66.0/24      *[BGP/170] 00:07:14, localpref 100

                      AS path: 200 I, validation-state: unverified

                    > to 13.13.13.3 via ge-0/0/1.0  < ===

 

 

— Additional Theory —

BGP Peering:

Share on print
Print
Share on google
Google+
Share on facebook
Facebook
Share on twitter
Twitter
Share on linkedin
LinkedIn

The Juniper All-Access | Reading List

Leave a reply

Your email address will not be published. Required fields are marked *

ADENTECH guides

We love to help.

Get our newsletter, join the community: