BGP AS_PATH Explained: Loop Prevention, Path Selection and Traffic Engineering

Short answer: AS_PATH is the ordered record of autonomous systems a BGP route has traversed. It helps detect routing loops and contributes to path selection. Prepending can influence how some remote networks choose an inbound path, but it is not a guarantee.

What AS_PATH contains

When an eBGP speaker advertises a route, it normally adds its own ASN to the AS_PATH. The receiving AS checks the path; if its own ASN is already present, it rejects the route to prevent a loop. AS_PATH also gives operators policy context about the route's origin and transit sequence.[1]

Path segments and practical reading

A simple path such as 64520 64510 is commonly read left to right: the neighboring AS 64520 advertised a route whose path already included 64510. Real paths can include AS_SET and confederation segments, so do not treat every displayed path as a simple sequence. Aggregation can also alter path detail.

How it affects path choice

Many implementations consider AS_PATH length when comparing otherwise eligible routes, but this is only one part of a larger policy-driven decision process; local preference and other criteria can take precedence. The exact selection sequence and options vary by implementation.[2]

Traffic engineering: control, influence and limits

  • Outbound: Your AS can use import policy to prefer or reject routes based on AS_PATH patterns, but LOCAL_PREF is usually the clearer internal exit-selection tool.
  • Inbound influence: Prepending your ASN multiple times on selected advertisements may make a path appear longer to some remote networks, encouraging an alternate route. Apply it narrowly and coordinate with upstream policy.
  • Cannot control: Other networks choose their routes using their own policies. Their LOCAL_PREF, communities, peering relationships, filtering, and path-selection settings can outweigh your prepending. AS_PATH does not control packet forwarding once a route has been chosen.

Example: Cisco-style inbound influence

Illustrative policy: prepend your own ASN on advertisements sent to the secondary provider. Confirm the exact syntax for your platform and release.

ip prefix-list OUR-PREFIX seq 10 permit 203.0.113.0/24
route-map TO-ISP-B permit 10
 match ip address prefix-list OUR-PREFIX
 set as-path prepend 64500 64500 64500
route-map TO-ISP-B permit 100
!
router bgp 64500
 neighbor 192.0.2.2 route-map TO-ISP-B out

The final permit clause matters: without deliberate handling, unmatched routes may be denied by a route-map. In FRRouting, outbound route maps and AS-path policy are supported; validate syntax against the installed release.[2][3]

Verification workflow

  1. Inspect the received route and full path: Cisco show ip bgp 203.0.113.0/24; FRR show bgp ipv4 unicast 203.0.113.0/24.
  2. Inspect the advertised route to the intended peer: Cisco show ip bgp neighbors 192.0.2.2 advertised-routes; FRR show bgp neighbors 192.0.2.2 advertised-routes.
  3. Confirm the expected prepend appears in the outbound AS_PATH and that the route remains permitted.
  4. Check the remote provider's looking glass or ask the provider to confirm its received path; your local advertised-routes output does not prove how every remote AS selects traffic.

Troubleshooting checklist

  • Is the prefix actually being advertised to the correct neighbor and address family?
  • Does an outbound filter or route-map deny the route?
  • Is the intended ASN prepended the expected number of times?
  • Is a private ASN being leaked, or is a provider stripping prepends?
  • Does the remote network's policy override path length?
  • Are you comparing the same prefix length and route origin at both exits?
  • Has a more-specific route made the AS_PATH comparison irrelevant?

Modern use: Internet edge and data centers

At a dual-ISP edge, AS_PATH prepending is a coarse inbound traffic influence tool, often combined with provider communities and prefix policy. It cannot ensure symmetric flows, which may still be affected by firewall state, NAT, and the remote network's decisions.

In BGP EVPN/VXLAN fabrics, AS_PATH loop prevention applies to BGP routes as they cross AS boundaries, but many internal fabric designs rely primarily on iBGP and route-reflector policy. Do not confuse overlay reachability or EVPN route types with the inter-AS AS_PATH string; inspect the relevant address family and control-plane policy.

Interview answer

“AS_PATH records the AS sequence associated with a BGP route. eBGP adds the local ASN, and a router rejects a route containing its own ASN to prevent loops. Shorter AS_PATH can be preferred at a decision stage, but policy such as LOCAL_PREF can take precedence. Prepending may influence inbound traffic, but the receiving AS controls its own selection.”

Related reading

Sources

  1. RFC 4271, BGP-4, AS_PATH attribute and loop detection
  2. FRRouting BGP documentation: path selection and AS-path concepts
  3. FRRouting route-map documentation

Try it: BGP Best Path Simulator - free, runs in your browser.

Comments

Popular posts from this blog

BGP Neighbor States

Reason legend in show ip ospf statistics