{"id":4920,"date":"2026-02-22T13:14:04","date_gmt":"2026-02-22T13:14:04","guid":{"rendered":"https:\/\/geekmungus.co.uk\/?p=4920"},"modified":"2026-02-22T13:14:04","modified_gmt":"2026-02-22T13:14:04","slug":"bgp-test-lab-part-7-path-selection-as-path-prepending","status":"publish","type":"post","link":"https:\/\/geekmungus.co.uk\/?p=4920","title":{"rendered":"BGP Test Lab &#8211; Part 7 &#8211; Path Selection: AS Path Prepending"},"content":{"rendered":"\n<p>In the previous article we talked about BGP Attributes and then how we can use MED (and Local Preference) to influence and control how traffic ingresses and egresses an Autonomous System (AS). But MED and Local Preference are just a couple of a few different techniques, in this article we&#8217;re going to explore how AS Path Prepending can be used to make a path (Route) between two AS look &#8220;worse&#8221; (longer in this case), by artificially adding AS to the AS Path BGP attribute.<\/p>\n\n\n\n<p>So what do we mean by AS Path, well let&#8217;s examine what the BGP Route table looks like, notice the final column on the right, AS-Path, this shows the list of AS that this route has come through to get to this particular route. Now in our topology, we currently only have two AS, so in this case the 10.2.0.0\/24, 10.2.1.0\/24 and 10.2.2.0\/24 networks are coming from AS Green (65002), so in the AS-Path, we only see 65002.<\/p>\n\n\n\n<p>But if these networks had instead come from another AS which is connected to AS Green, but not directly to AS Blue, then the AS-Path attribute would contain 65002 and say 65003 (if that were the ASN of another AS).<\/p>\n\n\n\n<p>As we learned in the previous article, the&nbsp;<strong>AS Path Length<\/strong>&nbsp;(4) BGP Attribute is used to decide on which path is &#8220;best&#8221;, we&#8217;re going to manipulate this attribute to make our Router A \u2194 Router C path look less desirable than the Router B \u2194 Router D path, ergo, so our Router A \u2194 Router C path will act as the &#8220;BACKUP PATH&#8221;.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>* tris-routerG.1 # show bgp route all\n\nRoutes:\n     Destination         Peer            Next-Hop        LPref Weight MED        AS-Path\n----------------------------------------------------------------------------------------\n*>i  10.1.0.0\/24         1.1.1.1         1.1.1.1         100   1      0\n*>i  10.1.1.0\/24         1.1.1.2         1.1.1.2         100   1      0\n*>i  10.2.0.0\/24         1.1.1.1         192.168.100.10  100   1      0          65002\n  i  10.2.0.0\/24         1.1.1.2         192.168.100.14  100   1      0          65002\n*>i  10.2.1.0\/24         1.1.1.1         192.168.100.10  100   1      0          65002\n  i  10.2.1.0\/24         1.1.1.2         192.168.100.14  100   1      0          65002\n*>i  10.2.2.0\/24         1.1.1.1         192.168.100.10  100   1      0          65002\n  i  10.2.2.0\/24         1.1.1.2         192.168.100.14  100   1      0          65002\n\n...<\/code><\/pre>\n\n\n\n<h1 class=\"wp-block-heading\" id=\"BGPTestLabPart7PathSelection:ASPathPrepending-CurrentNetworkTopology\">Current Network Topology<\/h1>\n\n\n\n<p>We have the topology from the previous article. Nothing has really changed, but what we have done is stated that we want the link between Router A and Router C to be the &#8220;backup&#8221; path. And we want the link between Router B and Router D to be the &#8220;primary&#8221; path.<\/p>\n\n\n\n<p>Currently, however if you were to ping from Router G to the Router H (or vice versa) you&#8217;d find that it would favour the &#8220;BACKUP PATH&#8221;, in this article we&#8217;re going to explore techniques to influence and control this routing path to how we want it to work.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"766\" height=\"818\" src=\"https:\/\/geekmungus.co.uk\/wp-content\/uploads\/2026\/02\/image-37.png\" alt=\"\" class=\"wp-image-4921\" srcset=\"https:\/\/geekmungus.co.uk\/wp-content\/uploads\/2026\/02\/image-37.png 766w, https:\/\/geekmungus.co.uk\/wp-content\/uploads\/2026\/02\/image-37-281x300.png 281w\" sizes=\"auto, (max-width: 766px) 100vw, 766px\" \/><\/figure>\n\n\n\n<h1 class=\"wp-block-heading\" id=\"BGPTestLabPart7PathSelection:ASPathPrepending-PathSelection\">Path Selection<\/h1>\n\n\n\n<p>There are a number of different options for path selection, the key thing to remember is it is influence rather than command. You don&#8217;t own the remote Autonomous System (AS) so we can only attempt to influence the best path selection within their network, they are the owners of it though!<\/p>\n\n\n\n<p>We&#8217;re going to investigate how we can influence the best path selection by use of AS Path Prepending to basically make the route via Router A \u2194 Router C look artificially longer than the one via Router B \u2194 Router D by adding another AS into the AS-Path attribute.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"BGPTestLabPart7PathSelection:ASPathPrepending-ASPathPrepending\">AS Path Prepending<\/h2>\n\n\n\n<p>So, the first thing you may be asking is we only have&nbsp;two AS&#8217;s, how are we going to add another one into the path when we only have 2 in the first place, well, there is nothing saying they all the AS&#8217;s in the path have to be unique! You can have the same AS twice (or more if you wanted to), so in our case we&#8217;ll create a policy that will add AS Blue (65001) twice to the AS-Path of the routes being sent from Router A to Router C.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"BGPTestLabPart7PathSelection:ASPathPrepending-RouterA\">Router A<\/h3>\n\n\n\n<p>Create a policy as follows:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>edit policy BACKUPROUTE-OUT<\/code><\/pre>\n\n\n\n<p>Then add the following content to the policy, you&#8217;ll also notice we&#8217;re using the\u00a0supernet\u00a0for the AS Blue, summarised to 10.1.0.0\/16, this is just so we can ensure that any new routes we might add are also included, without us needing to go back and add it manually to this policy. There is also a catch-all, so any other routes will be transmitted, without the extra AS added to the AS-Path attribute . If you don&#8217;t add the catch-all, any routes that don&#8217;t match the first statement won&#8217;t be transmitted at all; which may or may not be what you want, in our case that is not what we want!<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>entry BACKUPROUTE-OUT {\nif match any {\n  \u00a0 \u00a0 \u00a0 nlri 10.1.0.0\/16;\n}\nthen {\n        as-path 65001;\n\t\tpermit;\n}\n}\nentry BACKUPROUTEOUT-ALL {\nif match any {\n}\nthen {\n        permit;\n}\n}<\/code><\/pre>\n\n\n\n<p>Check the policy is okay with:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>check policy BACKUPROUTE-OUT<\/code><\/pre>\n\n\n\n<p>Then apply it to the BGP Neighbour (peer) configuration between Router A and Router C.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>configure bgp neighbor 192.168.100.10 route-policy out BACKUPROUTE-OUT<\/code><\/pre>\n\n\n\n<p>Refresh it with:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>refresh policy BACKUPROUTE-OUT<\/code><\/pre>\n\n\n\n<p>The policy is now applied, so that any routes sent to the BGP Neighbour peer 192.168.100.10, will now have an additional AS added to the AS-Path attribute, so it should show up saying &#8220;65001 65001&#8221; when examined on Router C, rather than just &#8220;65001&#8221; as it did previously. But, we&#8217;ll check this shortly, there&#8217;s something else we need to consider first!<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"BGPTestLabPart7PathSelection:ASPathPrepending-LocalPreference\">Local Preference<\/h2>\n\n\n\n<p>Wait, what why are we moving onto Local Preference? Well, same reason as in the previous article. We need to ensure the paths are symmetrical.<\/p>\n\n\n\n<p>We can illustrate this by looking at the route tables of Router G and Router H, we should be able to track the same path of intermediate routers between them in each direction, but if we have a look we can see this is not the case.<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Router G&#8217;s path between RouterG-LAN1 (10.1.2.0\/24) is: Router G \u2192 Router A \u2192 Router C \u2192 Router H.<\/li>\n\n\n\n<li>Router H&#8217;s path to RouterG-LAN1 (10.1.2.0\/24) is: Router H \u2192 Router D &#8211; Router B \u2192 Router G.<\/li>\n<\/ul>\n\n\n\n<p>That&#8217;s not what we want, although asymmetric routing can sometimes be useful, we want our path to be more deterministic through the network, in the current situation the traffic going between Router G and Router H (and vice-versa) would take one path outbound leg and another on the inbound leg.<\/p>\n\n\n\n<p>So the &#8220;AS Path Prepending&#8221; technique allows us to influence how the receiving AS will ingress traffic into our AS by making a particular route look less favourable (in our case making the Router A \u2194 Router C look less favourable), however, this only deals with ingress traffic (into AS Blue 65001), not how AS Blue 65001 sends the traffic out to AS Green (65002).&nbsp;<\/p>\n\n\n\n<p>So we&#8217;ll do the same thing as we did on the previous article and add a policy.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"BGPTestLabPart7PathSelection:ASPathPrepending-RouterA.1\">Router A<\/h3>\n\n\n\n<p>Create a new policy as follows and apply on the inbound to the BGP Neighbour (peer).<\/p>\n\n\n\n<p>You&#8217;ll also notice we&#8217;re using the&nbsp;supernet&nbsp;for the AS Green, summarised to 10.2.0.0\/16, this is just so if the administrator of AS Green were to add any new networks, we&#8217;d not need to add them manually to the policy. Of course, you may not always be able to do this, but this is where communication between the administrators of each AS becomes important to ensure each other&#8217;s configurations &#8220;dovetail&#8221; as much as possible.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>entry BACKUPROUTE-IN {\nif match all {\n    nlri 10.2.0.0\/16 ;\n}\nthen {\n    local-preference 50 ;   \n    permit  ;\n}\n}<\/code><\/pre>\n\n\n\n<p>Then apply it to the BGP Neighbour (peer) configuration between Router A and Router C.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>configure bgp neighbor 192.168.100.10 route-policy in BACKUPROUTE-IN<\/code><\/pre>\n\n\n\n<p>You may need to refresh with:&nbsp;<strong>&#8220;<em>refresh policy&nbsp;BACKUPROUTE-IN&#8221;<\/em><\/strong>, but now if we examine the route table on Router A, we can indeed see that the routes being learned from Router C now have a Local Preference (LPref) applied to them.<\/p>\n\n\n\n<p>In this case the higher the preference the more favourable the route\/path, the lower the preference the less favourable the route\/path.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>* tris-routerA.14 # show bgp routes all\n\nRoutes:\n     Destination         Peer            Next-Hop        LPref Weight MED        AS-Path\n----------------------------------------------------------------------------------------\n*>i  10.1.1.0\/24         1.1.1.2         1.1.1.2         100   1      0\n*>i  10.1.2.0\/24         1.1.1.7         1.1.1.7         100   1      0\n*>i  10.2.0.0\/24         1.1.1.2         192.168.100.14  100   1      0          65002\n  i  10.2.0.0\/24         192.168.100.10  192.168.100.10  50    1      0          65002\n*>i  10.2.1.0\/24         1.1.1.2         192.168.100.14  100   1      0          65002\n  i  10.2.1.0\/24         192.168.100.10  192.168.100.10  50    1      0          65002\n*>i  10.2.2.0\/24         1.1.1.2         192.168.100.14  100   1      0          65002\n  i  10.2.2.0\/24         192.168.100.10  192.168.100.10  50    1      0          65002\n\nFlags: (*) Preferred BGP route, (>) Active, (d) Suppressed, (h) History\n       (s) Stale, (m) Multipath, (u) Unfeasible\n\nOrigin: (?) Incomplete, (e) EGP, (i) IGP<\/code><\/pre>\n\n\n\n<h1 class=\"wp-block-heading\" id=\"BGPTestLabPart7PathSelection:ASPathPrepending-Verify\">Verify<\/h1>\n\n\n\n<p>Now let&#8217;s examine Router C&#8217;s route table, Router C is the peer of Router A, and will be getting the AS Path Prepending. And, yes as you can see there it is, notice that some of the route&#8217;s i.e. those with &#8220;next-hop&#8221; of 192.168.100.9 (i.e. Router A) have an extra AS specified in the path, which makes these routes\/paths look longer, and therefore worse.<\/p>\n\n\n\n<p>You can also see therefore that Router C has selected the other route via the next-hop 192.168.100.13 (i.e. Router B) as the &#8220;best&#8221; path to the AS Blue 65001.<\/p>\n\n\n\n<p>So, the AS Path Prepending at least is working as we want.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"762\" height=\"340\" src=\"https:\/\/geekmungus.co.uk\/wp-content\/uploads\/2026\/02\/image-38.png\" alt=\"\" class=\"wp-image-4922\" srcset=\"https:\/\/geekmungus.co.uk\/wp-content\/uploads\/2026\/02\/image-38.png 762w, https:\/\/geekmungus.co.uk\/wp-content\/uploads\/2026\/02\/image-38-300x134.png 300w\" sizes=\"auto, (max-width: 762px) 100vw, 762px\" \/><\/figure>\n\n\n\n<p>OK, so now let&#8217;s examine Router G and Router H&#8217;s view of the routes, because we want to run some tests between these two routes, it&#8217;s what these two see in their route tables is what matters to us in this particular example.<\/p>\n\n\n\n<p>Router G being within AS Blue 65001, should, because of the Local Preference we are setting on Router A, be seeing that the &#8220;best&#8221; route to the 10.2.0.0\/16 networks (in AS Green 65002) as being via Router B \u2194 Router D link, which as you can see it is indeed! Additionally, because of our manipulation of the AS Path attribute we are influencing AS Green 65002 to select the Router B \u2194 Router D link as the &#8220;best&#8221; route to the 10.1.0.0\/16 networks.&nbsp;<\/p>\n\n\n\n<p>Nice, that shows two things, firstly that the AS Path Prepending is working as we want, and secondly that the paths between Router G and Router H are symmetric, each leg of a connection between these networks (i.e. send and recieve) will go via our &#8220;PRIMARY ROUTE&#8221; (Router B \u2194 Router D) as we also want (thanks to the Local Preference we are also adding).&nbsp;<\/p>\n\n\n\n<p>Also note that we don&#8217;t see the extra AS-Path attributes on Router H, we only see these on Router C, this is because Router C is the router actually getting these routes directly from Router A, and so from Router H&#8217;s point of view, it&#8217;s got these routes from Router C, and Router C isn&#8217;t picking it as the best path, so neither is Router H.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"745\" height=\"288\" src=\"https:\/\/geekmungus.co.uk\/wp-content\/uploads\/2026\/02\/image-39.png\" alt=\"\" class=\"wp-image-4923\" srcset=\"https:\/\/geekmungus.co.uk\/wp-content\/uploads\/2026\/02\/image-39.png 745w, https:\/\/geekmungus.co.uk\/wp-content\/uploads\/2026\/02\/image-39-300x116.png 300w\" sizes=\"auto, (max-width: 745px) 100vw, 745px\" \/><\/figure>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"739\" height=\"287\" src=\"https:\/\/geekmungus.co.uk\/wp-content\/uploads\/2026\/02\/image-40.png\" alt=\"\" class=\"wp-image-4924\" srcset=\"https:\/\/geekmungus.co.uk\/wp-content\/uploads\/2026\/02\/image-40.png 739w, https:\/\/geekmungus.co.uk\/wp-content\/uploads\/2026\/02\/image-40-300x117.png 300w\" sizes=\"auto, (max-width: 739px) 100vw, 739px\" \/><\/figure>\n\n\n\n<p>Let&#8217;s now remove the policies from Router A (AS Path Prepending and Local Preference) and then re-examine the route tables, and see what has changed (i.e. back to before we did anything).<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"724\" height=\"347\" src=\"https:\/\/geekmungus.co.uk\/wp-content\/uploads\/2026\/02\/image-41.png\" alt=\"\" class=\"wp-image-4925\" srcset=\"https:\/\/geekmungus.co.uk\/wp-content\/uploads\/2026\/02\/image-41.png 724w, https:\/\/geekmungus.co.uk\/wp-content\/uploads\/2026\/02\/image-41-300x144.png 300w\" sizes=\"auto, (max-width: 724px) 100vw, 724px\" \/><\/figure>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"720\" height=\"337\" src=\"https:\/\/geekmungus.co.uk\/wp-content\/uploads\/2026\/02\/image-42.png\" alt=\"\" class=\"wp-image-4926\" srcset=\"https:\/\/geekmungus.co.uk\/wp-content\/uploads\/2026\/02\/image-42.png 720w, https:\/\/geekmungus.co.uk\/wp-content\/uploads\/2026\/02\/image-42-300x140.png 300w\" sizes=\"auto, (max-width: 720px) 100vw, 720px\" \/><\/figure>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"725\" height=\"338\" src=\"https:\/\/geekmungus.co.uk\/wp-content\/uploads\/2026\/02\/image-43.png\" alt=\"\" class=\"wp-image-4927\" srcset=\"https:\/\/geekmungus.co.uk\/wp-content\/uploads\/2026\/02\/image-43.png 725w, https:\/\/geekmungus.co.uk\/wp-content\/uploads\/2026\/02\/image-43-300x140.png 300w\" sizes=\"auto, (max-width: 725px) 100vw, 725px\" \/><\/figure>\n\n\n\n<p>And as you can see, the best path has returned to the Router A \u2194 Router C link, which is not what we want, but demonstrates we have successfully manipulated the routes as we wanted via AS Path Prepending.<\/p>\n\n\n\n<h1 class=\"wp-block-heading\" id=\"BGPTestLabPart7PathSelection:ASPathPrepending-Conclusion\">Conclusion<\/h1>\n\n\n\n<p>We&#8217;ve seen how AS Path Prepending can be used to attempt to influence the other AS to use the entry point to our network we want others to use. Additionally, we&#8217;ve looked at how Local Preference can be used within our own network to control the routing in association with MED to ensure a symmetric routing path.<\/p>\n\n\n\n<h1 class=\"wp-block-heading\" id=\"BGPTestLabPart7PathSelection:ASPathPrepending-AdditionalInformation\">Additional Information<\/h1>\n\n\n\n<ul class=\"wp-block-list\">\n<li><a href=\"https:\/\/networklessons.com\/bgp\/bgp-attributes-and-path-selection\">https:\/\/networklessons.com\/bgp\/bgp-attributes-and-path-selection<\/a><\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>In the previous article we talked about BGP Attributes and then how we can use MED (and Local Preference) to influence and control how traffic ingresses and egresses an Autonomous System (AS). But MED and Local Preference are just a couple of a few different techniques, in this article we&#8217;re going to explore how AS &#8230; <a title=\"BGP Test Lab &#8211; Part 7 &#8211; Path Selection: AS Path Prepending\" class=\"read-more\" href=\"https:\/\/geekmungus.co.uk\/?p=4920\" aria-label=\"Read more about BGP Test Lab &#8211; Part 7 &#8211; Path Selection: AS Path Prepending\">Read more<\/a><\/p>\n","protected":false},"author":4,"featured_media":4783,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[62,17],"tags":[],"class_list":["post-4920","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-bgp","category-networking"],"_links":{"self":[{"href":"https:\/\/geekmungus.co.uk\/index.php?rest_route=\/wp\/v2\/posts\/4920","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/geekmungus.co.uk\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/geekmungus.co.uk\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/geekmungus.co.uk\/index.php?rest_route=\/wp\/v2\/users\/4"}],"replies":[{"embeddable":true,"href":"https:\/\/geekmungus.co.uk\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=4920"}],"version-history":[{"count":1,"href":"https:\/\/geekmungus.co.uk\/index.php?rest_route=\/wp\/v2\/posts\/4920\/revisions"}],"predecessor-version":[{"id":4928,"href":"https:\/\/geekmungus.co.uk\/index.php?rest_route=\/wp\/v2\/posts\/4920\/revisions\/4928"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/geekmungus.co.uk\/index.php?rest_route=\/wp\/v2\/media\/4783"}],"wp:attachment":[{"href":"https:\/\/geekmungus.co.uk\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=4920"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/geekmungus.co.uk\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=4920"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/geekmungus.co.uk\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=4920"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}