You can use the bgp maxas-limit command to prevent the forwarding of routes having AS paths longer than a specified limit.
bgp maxas-limit
- host1(config-router)#bgp maxas-limit 42
To apply the new behavior to routes that are already present in the BGP routing table, you must use the clear ip bgp command to perform a soft clear or hard clear of the current BGP session.
If you use the fields as-path option with the show ip bgp command, the display indicates routes whose AS path exceeds the limit. The following display illustrates the result of setting the AS path length limit to 5:
host1:3# show ip bgp fields intro best peer loc-pref as-path Local router ID 13.13.13.3, local AS 200 10 paths, 5 distinct prefixes (520 bytes used) 6 paths selected for route table installation 14 path attribute entries (1943 bytes used) Status codes: > best Prefix Peer LocPrf AS-path 10.23.40.1/32 192.168.13.1 200 100 211 32 15 67 44 (too long) > 10.23.40.1/32 172.123.23.2 100 100 211 > 10.23.40.2/32 192.168.13.1 200 100 211 32 15 67 10.23.40.2/32 172.123.23.2 100 100 211 32 > 10.23.40.3/32 192.168.13.1 100 211 32 15 10.23.40.3/32 172.123.23.2 100 211 32 15 10.23.40.4/32 192.168.13.1 100 100 211 32 > 10.23.40.4/32 172.123.23.2 200 100 211 32 15 67 > 10.23.40.5/32 192.168.13.1 100 100 211 10.23.40.5/32 172.123.23.2 200 100 211 32 15 67 44 (too long)