>_nexthopreachable

CCNP ENCOR: BGP Neighbors, Next Hops, and the Best Path Algorithm

Ali Bahadır Coşkun29 min read

Border Gateway Protocol (BGP) is the routing protocol that connects autonomous systems. An autonomous system (AS) is a network under a single administration, such as an enterprise or a service provider, identified by an AS number. Interior gateway protocols like OSPF and EIGRP look for the shortest path inside one network. BGP exchanges prefixes between networks that don't trust each other's metrics, so every route carries a set of path attributes, and each AS applies its own policy to decide which path to use. BGP is a path-vector protocol. The most important attribute is the AS path, the list of autonomous systems a route has passed through, which is also how BGP prevents loops.

A session between routers in different autonomous systems is external BGP (eBGP), and a session between routers in the same AS is internal BGP (iBGP). The two behave differently in a few important ways, and most of this lab is about those differences and about how a router chooses between several paths to the same prefix.

In this lab, we'll bring up eBGP and iBGP sessions, advertise prefixes, fix the iBGP next hop, and then walk through the best path algorithm with weight, local preference, AS-path prepending, and MED. Every output in this article comes from the lab itself.

Topology

The topology has seven routers and four autonomous systems. AS 10 is the network we operate: R11 and R12 are its edge routers and R13 is an internal router. AS 20 is a provider with two routers, and AS 10 connects to it twice. AS 30 is a second provider, and AS 40 is a partner network that both providers can reach.

The router names carry the AS number, so R21 is router 1 of AS 20. Links inside an AS use 10.a.b.0/24, where a and b are the two router numbers, and links between autonomous systems use 23.AS.AS.0/24. The last octet of every interface address is the router number, so R21 is 23.10.20.21 on its link to R11.

LinkTypeSubnet
R11–R21AS 10 to AS 2023.10.20.0/24
R12–R22AS 10 to AS 2023.20.10.0/24
R12–R31AS 10 to AS 3023.10.30.0/24
R21–R41AS 20 to AS 4023.20.40.0/24
R31–R41AS 30 to AS 4023.30.40.0/24
R11–R12Inside AS 10, OSPF cost 1010.11.12.0/24
R11–R13Inside AS 10, OSPF cost 1010.11.13.0/24
R12–R13Inside AS 10, OSPF cost 110.12.13.0/24
R21–R22Inside AS 20, no IGP10.21.22.0/24

Each router has two loopbacks. Loopback0 is N.N.N.N/32, for example 13.13.13.13 on R13, and it is used as the BGP router ID. Loopback1 is 172.16.N.1/24 and stands for the LAN behind the router. These LANs are the prefixes we'll advertise in BGP. Most checks use two of them: 172.16.13.0/24 behind R13 in AS 10, and 172.16.41.0/24 behind R41 in AS 40.

Inside AS 10, OSPF runs on the internal links and the Loopback0 addresses. I set the OSPF cost to 10 on both of R11's internal links, so R13 reaches R12's loopback with a metric of 2 and R11's loopback with a metric of 11. We will come back to that on task 4.

Task 1: Bring Up eBGP

Objective: Configure the five eBGP sessions on the links between autonomous systems: R11–R21, R12–R22, R12–R31, R21–R41, and R31–R41.

Configuration

R12 has two providers:

ios
configure terminalrouter bgp 10 bgp router-id 12.12.12.12 neighbor 23.20.10.22 remote-as 20 neighbor 23.10.30.31 remote-as 30end

The other routers follow the same pattern with their own AS number, router ID, and neighbors:

RouterLocal ASeBGP neighbors
R111023.10.20.21 (AS 20)
R212023.10.20.11 (AS 10), 23.20.40.41 (AS 40)
R222023.20.10.12 (AS 10)
R313023.10.30.12 (AS 10), 23.30.40.41 (AS 40)
R414023.20.40.21 (AS 20), 23.30.40.31 (AS 30)

The 10 in router bgp 10 is the local AS number. Unlike the OSPF process ID, it is not locally significant: the neighbor has to be configured with exactly this number in its own remote-as statement, otherwise the session is rejected. A router can only run one BGP process.

BGP does not discover neighbors. There are no hellos sent to a multicast address like in OSPF or EIGRP. Both sides must name each other, and each side must have the other's AS number right. A neighbor whose remote-as is different from the local AS is an eBGP neighbor. eBGP packets are sent with a TTL of 1 by default, which is why eBGP neighbors are normally directly connected and peer with the address on the shared link.

Session states

A BGP session moves through these states:

  • Idle: BGP is not trying to connect yet, or it is waiting before the next attempt.
  • Connect and Active: the router is trying to open the TCP session. A neighbor that stays in Active usually means that the address is unreachable or the other side is not configured.
  • OpenSent and OpenConfirm: the routers exchange OPEN messages, check the AS number and other parameters, and then send keepalives.
  • Established: the session is up. Only Established neighbors exchange routes.

With only R12 configured, both of its neighbors are stuck, because the other side is not answering yet:

text
R12# show ip bgp summaryBGP router identifier 12.12.12.12, local AS number 10BGP table version is 1, main routing table version 1Neighbor        V           AS MsgRcvd MsgSent   TblVer  InQ OutQ Up/Down  State/PfxRcd23.10.30.31     4           30       0       0        1    0    0 never    Idle23.20.10.22     4           20       0       0        1    0    0 never    Idle

Verification

After the other routers are configured:

text
R12# show ip bgp summaryBGP router identifier 12.12.12.12, local AS number 10BGP table version is 1, main routing table version 1Neighbor        V           AS MsgRcvd MsgSent   TblVer  InQ OutQ Up/Down  State/PfxRcd23.10.30.31     4           30       2       2        1    0    0 00:00:49        023.20.10.22     4           20       2       2        1    0    0 00:00:45        0

Idle or Active means the session is not up. A number means the session is Established, and the number is how many prefixes were received from that neighbor. It is 0 here because nothing is advertised yet.

text
R12# show ip bgp neighbors 23.10.30.31 | include BGP state|remote AS|hold timeBGP neighbor is 23.10.30.31,  remote AS 30, external link  BGP state = Established, up for 00:00:49  Last read 00:00:49, last write 00:00:49, hold time is 180, keepalive interval is 60 seconds

external link confirms that this is an eBGP session. Keepalives are sent every 60 seconds, and the session is torn down if nothing is received for 180 seconds. Those are slow timers compared to an IGP, and BGP is slow in general: after a session comes up or a policy changes, it can take up to a minute before the tables settle.

The sessions are ordinary TCP connections to port 179:

text
R12# show tcp briefTCB       Local Address               Foreign Address             (state)0CB01DF0  23.10.30.12.49272          23.10.30.31.179             ESTAB0CAFF3C8  23.20.10.12.29318          23.20.10.22.179             ESTAB

R12 opened both connections from a random source port to port 179 on the neighbor. Either side can open the connection, and one TCP session per neighbor is enough.

Task 2: Advertise the LANs

Objective: Advertise the Loopback1 LAN on the six routers that run BGP, and find the AS path, the next hop, and the origin code in the BGP table.

Configuration

On R41:

ios
configure terminalrouter bgp 40 network 172.16.41.0 mask 255.255.255.0end

The network statement in BGP works differently from the one in OSPF and EIGRP. It does not enable BGP on anything. It tells BGP to advertise a prefix, and only if a route with exactly that prefix and mask is already in the routing table. Here, that is the connected route of Loopback1. If the mask doesn't match, for example network 172.16.41.0 mask 255.255.0.0, nothing is advertised.

Verification

text
R41# show ip bgpBGP table version is 7, local router ID is 41.41.41.41Status codes: s suppressed, d damped, h history, * valid, > best, i - internal,              r RIB-failure, S Stale, m multipath, b backup-path, f RT-Filter,              x best-external, a additional-path, c RIB-compressed,Origin codes: i - IGP, e - EGP, ? - incompleteRPKI validation codes: V valid, I invalid, N Not found     Network          Next Hop            Metric LocPrf Weight Path *>  172.16.11.0/24   23.20.40.21                            0 20 10 i *>  172.16.12.0/24   23.30.40.31                            0 30 10 i *>  172.16.21.0/24   23.20.40.21              0             0 20 i *>  172.16.22.0/24   23.30.40.31                            0 30 10 20 i *>  172.16.31.0/24   23.30.40.31              0             0 30 i *>  172.16.41.0/24   0.0.0.0                  0         32768 i
  • * means the path is valid, and > marks the best path. Only the best path is installed in the routing table and advertised to other neighbors.
  • Next Hop: 0.0.0.0 means R41 originated the route itself. For the others, it is the neighbor's address on the shared link. A router that advertises a route to an eBGP neighbor sets the next hop to its own address.
  • Path: the AS path, read from right to left. 20 10 means the route was originated in AS 10 and passed through AS 20. Every AS adds its own number to the front when it advertises the route to an eBGP neighbor.
  • Origin: the i at the end of every path is the origin code for a route injected with a network statement. A redistributed route would show ?.
  • Weight: 32768 for the route R41 originated, and 0 for learned routes. We'll use it in Task 5.

The routes are installed with an administrative distance of 20, the value for eBGP:

text
R41# show ip route bgp | begin GatewayGateway of last resort is not set      172.16.0.0/16 is variably subnetted, 7 subnets, 2 masksB        172.16.11.0/24 [20/0] via 23.20.40.21, 00:01:10B        172.16.12.0/24 [20/0] via 23.30.40.31, 00:01:09B        172.16.21.0/24 [20/0] via 23.20.40.21, 00:01:10B        172.16.22.0/24 [20/0] via 23.30.40.31, 00:00:38B        172.16.31.0/24 [20/0] via 23.30.40.31, 00:01:09

AS-path loop prevention

One entry in R41's table looks wrong. 172.16.22.0/24 belongs to R22 in AS 20, and R41 is directly connected to AS 20, but the path is 30 10 20. R22's LAN reaches R41 the long way around, through AS 10 and AS 30.

The reason is that R21 and R22 don't have a BGP session with each other yet, so R22 can't hand its LAN to R21. R21 does receive the route from R41, but its AS path already contains 20, and a router discards an eBGP update that contains its own AS number. This is how BGP prevents loops.

AS 10 is split in the same way. R12's LAN can only reach R11 through AS 30, AS 40, and AS 20, so it arrives with AS 10 in the path and R11 drops it:

text
R11# show ip bgp 172.16.12.0% Network not in table

Both problems are solved by iBGP.

Task 3: Add iBGP

Objective: Configure a full mesh of iBGP sessions between the Loopback0 addresses of R11, R12, and R13, start BGP on R13, and configure one iBGP session between R21 and R22. Then check whether R13 can use the external routes.

Configuration

On R13:

ios
configure terminalrouter bgp 10 bgp router-id 13.13.13.13 neighbor 11.11.11.11 remote-as 10 neighbor 11.11.11.11 update-source Loopback0 neighbor 12.12.12.12 remote-as 10 neighbor 12.12.12.12 update-source Loopback0 network 172.16.13.0 mask 255.255.255.0end

R11 and R12 get the same two lines for each of their two iBGP neighbors. In AS 20, R21 and R22 peer on the addresses of their shared link (10.21.22.21 and 10.21.22.22) with a single remote-as 20 line each, because AS 20 has no IGP to carry loopbacks.

A neighbor with the same AS number as the local router is an iBGP neighbor. iBGP neighbors do not need to be directly connected, so they usually peer between loopbacks. A session between loopbacks stays up as long as the IGP has any path between the two routers, while a session between interface addresses goes down with that one link.

By default, a router sends BGP packets from the address of the outgoing interface. R11 is configured to expect R13 at 13.13.13.13, so a connection coming from 10.11.13.13 would be refused. update-source Loopback0 makes the router open the session from its loopback address.

iBGP has two rules that eBGP does not have:

  1. A route learned from an iBGP neighbor is not advertised to another iBGP neighbor. The AS path does not change inside an AS, so the AS-path check can't prevent loops there. This rule does it instead, and it is why the three routers in AS 10 need a full mesh.
  2. The next hop is not changed when a route is advertised to an iBGP neighbor.

Verification

text
R13# show ip bgp summary | begin NeighborNeighbor        V           AS MsgRcvd MsgSent   TblVer  InQ OutQ Up/Down  State/PfxRcd11.11.11.11     4           10      12       6        4    0    0 00:01:11        512.12.12.12     4           10      12       6        4    0    0 00:01:12        5

Both sessions are up, and R13 received five prefixes from each edge router. R11 also has R12's LAN now, with an empty AS path (Local), because the route never left AS 10:

text
R11# show ip bgp 172.16.12.0BGP routing table entry for 172.16.12.0/24, version 7Paths: (1 available, best #1, table default)  Advertised to update-groups:     1  Refresh Epoch 1  Local    12.12.12.12 (metric 11) from 12.12.12.12 (12.12.12.12)      Origin IGP, metric 0, localpref 100, valid, internal, best      rx pathid: 0, tx pathid: 0x0

R13's table is less healthy:

text
R13# show ip bgp | begin Network     Network          Next Hop            Metric LocPrf Weight Path *>i 172.16.11.0/24   11.11.11.11              0    100      0 i *>i 172.16.12.0/24   12.12.12.12              0    100      0 i *>  172.16.13.0/24   0.0.0.0                  0         32768 i * i 172.16.21.0/24   23.10.20.21              0    100      0 20 i * i                  23.20.10.22              0    100      0 20 i * i 172.16.22.0/24   23.10.20.21              0    100      0 20 i * i                  23.20.10.22              0    100      0 20 i * i 172.16.31.0/24   23.10.20.21              0    100      0 20 40 30 i * i                  23.10.30.31              0    100      0 30 i * i 172.16.41.0/24   23.10.20.21              0    100      0 20 40 i * i                  23.10.30.31              0    100      0 30 40 i

The i after the status codes means the path was learned through iBGP. The two LANs inside AS 10 are marked *>i: valid, best, internal. Every route from another AS has two paths, but none of them has a >. The local preference column shows 100 for all of them, which is the default.

text
R13# show ip bgp 172.16.41.0BGP routing table entry for 172.16.41.0/24, version 0Paths: (2 available, no best path)Flag: 0x820  Not advertised to any peer  Refresh Epoch 2  20 40    23.10.20.21 (inaccessible) from 11.11.11.11 (11.11.11.11)      Origin IGP, metric 0, localpref 100, valid, internal      rx pathid: 0, tx pathid: 0  Refresh Epoch 2  30 40    23.10.30.31 (inaccessible) from 12.12.12.12 (12.12.12.12)      Origin IGP, metric 0, localpref 100, valid, internal      rx pathid: 0, tx pathid: 0

R11 learned this prefix from R21 with the next hop 23.10.20.21 and passed it to R13 with the same next hop. The links to the other autonomous systems are not in OSPF, so R13 has no route to that address:

text
R13# show ip route 23.10.20.21% Network not in table

A path with an unreachable next hop can't be the best path, and without a best path nothing is installed:

text
R13# show ip route 172.16.41.0% Subnet not in table

Task 4: Fix the Next Hop with next-hop-self

Objective: Configure next-hop-self on the edge routers toward their iBGP neighbors, verify reachability between the LANs of R13 and R41, and explain the best path each router in AS 10 chooses for 172.16.41.0/24.

Configuration

On R11:

ios
configure terminalrouter bgp 10 neighbor 12.12.12.12 next-hop-self neighbor 13.13.13.13 next-hop-selfend

With next-hop-self, a router replaces the next hop with its own address when it advertises a route to that neighbor. R13 now receives the external routes with the next hop 11.11.11.11 or 12.12.12.12, which it knows from OSPF. The alternative is to advertise the external links in the IGP. next-hop-self keeps them out of it.

The best path algorithm

When a router has several paths to the same prefix, it compares them step by step and stops at the first step where they differ:

StepAttributePreferred
1WeightHighest
2Local preferenceHighest
3Locally originatedRoutes the router originated itself
4AS pathShortest
5Origin codeIGP, then EGP, then incomplete
6MEDLowest
7eBGP over iBGPeBGP
8IGP metric to the next hopLowest
9TiebreakersOldest eBGP path, then lowest neighbor router ID

A path is only considered if its next hop is reachable, which is what was missing in Task 3. No policy is configured yet, so the algorithm runs on its defaults, and the three routers in AS 10 each end up deciding on a different step.

Verification

R13 has two iBGP paths:

text
R13# show ip bgp 172.16.41.0BGP routing table entry for 172.16.41.0/24, version 9Paths: (2 available, best #2, table default)  Not advertised to any peer  Refresh Epoch 3  20 40    11.11.11.11 (metric 11) from 11.11.11.11 (11.11.11.11)      Origin IGP, metric 0, localpref 100, valid, internal      rx pathid: 0, tx pathid: 0  Refresh Epoch 3  30 40    12.12.12.12 (metric 2) from 12.12.12.12 (12.12.12.12)      Origin IGP, metric 0, localpref 100, valid, internal, best      rx pathid: 0, tx pathid: 0x0

Weight, local preference, AS-path length, origin, and MED are equal, and both paths are iBGP. The decision falls to step 8. The number in parentheses after the next hop is the IGP metric to reach it: 2 for R12 and 11 for R11. R13 chooses R12.

The route is installed with an administrative distance of 200, the value for iBGP:

text
R13# show ip route 172.16.41.0Routing entry for 172.16.41.0/24  Known via "bgp 10", distance 200, metric 0  Tag 30, type internal  Last update from 12.12.12.12 00:00:47 ago  Routing Descriptor Blocks:  * 12.12.12.12, from 12.12.12.12, 00:00:47 ago      Route metric is 0, traffic share count is 1      AS Hops 2      Route tag 30      MPLS label: none
text
R13# ping 172.16.41.1 source Loopback1Sending 5, 100-byte ICMP Echos to 172.16.41.1, timeout is 2 seconds:Packet sent with a source address of 172.16.13.1!!!!!Success rate is 100 percent (5/5), round-trip min/avg/max = 8/10/13 msR13# traceroute 172.16.41.1 source Loopback1 numericTracing the route to 172.16.41.1VRF info: (vrf in name/id, vrf out name/id)  1 10.12.13.12 6 msec 7 msec 5 msec  2 23.10.30.31 7 msec 6 msec 7 msec  3 23.30.40.41 10 msec *  8 msec

The traffic leaves AS 10 through R12 and AS 30.

R11 has one iBGP path from R12 and one eBGP path from R21:

text
R11# show ip bgp 172.16.41.0BGP routing table entry for 172.16.41.0/24, version 4Paths: (2 available, best #2, table default)  Advertised to update-groups:     3  Refresh Epoch 1  30 40    12.12.12.12 (metric 11) from 12.12.12.12 (12.12.12.12)      Origin IGP, metric 0, localpref 100, valid, internal      rx pathid: 0, tx pathid: 0  Refresh Epoch 1  20 40    23.10.20.21 from 23.10.20.21 (21.21.21.21)      Origin IGP, localpref 100, valid, external, best      rx pathid: 0, tx pathid: 0x0

Both AS paths have two entries. R11 decides on step 7: an eBGP path is preferred over an iBGP path. The idea is to hand traffic to the other AS as soon as possible instead of carrying it across our own network first.

R12 has three paths:

text
R12# show ip bgp 172.16.41.0BGP routing table entry for 172.16.41.0/24, version 5Paths: (3 available, best #3, table default)  Advertised to update-groups:     1          3  Refresh Epoch 1  20 40    23.20.10.22 from 23.20.10.22 (22.22.22.22)      Origin IGP, localpref 100, valid, external      rx pathid: 0, tx pathid: 0  Refresh Epoch 1  20 40    11.11.11.11 (metric 11) from 11.11.11.11 (11.11.11.11)      Origin IGP, metric 0, localpref 100, valid, internal      rx pathid: 0, tx pathid: 0  Refresh Epoch 1  30 40    23.10.30.31 from 23.10.30.31 (31.31.31.31)      Origin IGP, localpref 100, valid, external, best      rx pathid: 0, tx pathid: 0x0

The iBGP path from R11 loses to the two eBGP paths on step 7. Between the eBGP paths through AS 20 and AS 30, everything is equal, so R12 keeps the one it learned first. In this run, the session to R31 came up four seconds before the session to R22. That is not something to rely on, so the next task makes the choice deliberate.

Task 5: Prefer a Path Locally with Weight

Objective: Make R12 send traffic for 172.16.41.0/24 through AS 30, using weight, without affecting other routes or other routers.

Configuration

On R12:

ios
configure terminalip prefix-list AS40-LAN seq 5 permit 172.16.41.0/24route-map FROM-AS30 permit 10 match ip address prefix-list AS40-LAN set weight 200route-map FROM-AS30 permit 20router bgp 10 neighbor 23.10.30.31 route-map FROM-AS30 inendclear ip bgp 23.10.30.31 soft in

Weight is the first step of the algorithm, and the highest weight wins. It is 32768 for routes the router originates and 0 for routes it learns. Weight is a Cisco value, not a BGP attribute. It is never sent in an update, so it only influences the router on which it is set.

An inbound route map is applied to the routes received from one neighbor. Sequence 10 matches the partner LAN and sets its weight to 200. The empty permit 20 is important. A route map ends with an implicit deny, so a route that matches no sequence is dropped. Without sequence 20, R12 would discard every other route from R31.

A new policy does not apply to routes that were already received. clear ip bgp 23.10.30.31 soft in asks the neighbor to send its routes again without resetting the session.

Verification

text
R12# show ip bgp 172.16.41.0BGP routing table entry for 172.16.41.0/24, version 12Paths: (3 available, best #3, table default)  Advertised to update-groups:     1          3  Refresh Epoch 1  20 40    23.20.10.22 from 23.20.10.22 (22.22.22.22)      Origin IGP, localpref 100, valid, external      rx pathid: 0, tx pathid: 0  Refresh Epoch 1  20 40    11.11.11.11 (metric 11) from 11.11.11.11 (11.11.11.11)      Origin IGP, metric 0, localpref 100, valid, internal      rx pathid: 0, tx pathid: 0  Refresh Epoch 2  30 40    23.10.30.31 from 23.10.30.31 (31.31.31.31)      Origin IGP, localpref 100, weight 200, valid, external, best      rx pathid: 0, tx pathid: 0x0

The path through R31 is best again, but this time because of weight 200. The other route from R31 is still accepted, with the default weight of 0:

text
R12# show ip bgp | begin Network     Network          Next Hop            Metric LocPrf Weight Path... *>  172.16.31.0/24   23.10.30.31              0             0 30 i *   172.16.41.0/24   23.20.10.22                            0 20 40 i * i                  11.11.11.11              0    100      0 20 40 i *>                   23.10.30.31                          200 30 40 i

On R13, the path learned from R12 has no weight. The value stayed on R12:

text
R13# show ip bgp 172.16.41.0 | begin Refresh  Refresh Epoch 3  20 40    11.11.11.11 (metric 11) from 11.11.11.11 (11.11.11.11)      Origin IGP, metric 0, localpref 100, valid, internal      rx pathid: 0, tx pathid: 0  Refresh Epoch 3  30 40    12.12.12.12 (metric 2) from 12.12.12.12 (12.12.12.12)      Origin IGP, metric 0, localpref 100, valid, internal, best      rx pathid: 0, tx pathid: 0x0

Task 6: Prefer an Exit for the Whole AS with Local Preference

Objective: Make the R11–R21 link the preferred exit from AS 10 toward 172.16.41.0/24, using a local preference of 200 on R11. Keep the weight from Task 5 and compare R13 with R12.

Configuration

On R11:

ios
configure terminalip prefix-list AS40-LAN seq 5 permit 172.16.41.0/24route-map FROM-AS20 permit 10 match ip address prefix-list AS40-LAN set local-preference 200route-map FROM-AS20 permit 20router bgp 10 neighbor 23.10.20.21 route-map FROM-AS20 inendclear ip bgp 23.10.20.21 soft in

Local preference is the second step of the algorithm. The highest value wins, and the default is 100. Unlike weight, it is a real BGP attribute that is carried in updates to iBGP neighbors. One router sets it, and every router in the AS takes it into account. It is not sent to eBGP neighbors, so it never leaves the AS. Local preference is the usual tool for choosing the exit from an AS.

Verification

text
R13# show ip bgp 172.16.41.0BGP routing table entry for 172.16.41.0/24, version 13Paths: (2 available, best #1, table default)  Not advertised to any peer  Refresh Epoch 3  20 40    11.11.11.11 (metric 11) from 11.11.11.11 (11.11.11.11)      Origin IGP, metric 0, localpref 200, valid, internal, best      rx pathid: 0, tx pathid: 0x0  Refresh Epoch 3  30 40    12.12.12.12 (metric 2) from 12.12.12.12 (12.12.12.12)      Origin IGP, metric 0, localpref 100, valid, internal      rx pathid: 0, tx pathid: 0

The path from R11 arrives with localpref 200 and is now best. In Task 4, this path lost on the IGP metric, 11 against 2. The metrics haven't changed, but local preference is compared at step 2, so the algorithm never gets to step 8.

text
R13# traceroute 172.16.41.1 source Loopback1 numericTracing the route to 172.16.41.1VRF info: (vrf in name/id, vrf out name/id)  1 10.11.13.11 6 msec 5 msec 5 msec  2 23.10.20.21 7 msec 9 msec 7 msec  3 23.20.40.41 10 msec *  9 msec

R13's traffic now leaves through R11 and AS 20.

R12 received the same path with the same local preference, but it makes a different decision:

text
R12# show ip bgp 172.16.41.0BGP routing table entry for 172.16.41.0/24, version 12Paths: (3 available, best #3, table default)  Advertised to update-groups:     1          3  Refresh Epoch 1  20 40    23.20.10.22 from 23.20.10.22 (22.22.22.22)      Origin IGP, localpref 100, valid, external      rx pathid: 0, tx pathid: 0  Refresh Epoch 1  20 40    11.11.11.11 (metric 11) from 11.11.11.11 (11.11.11.11)      Origin IGP, metric 0, localpref 200, valid, internal      rx pathid: 0, tx pathid: 0  Refresh Epoch 2  30 40    23.10.30.31 from 23.10.30.31 (31.31.31.31)      Origin IGP, localpref 100, weight 200, valid, external, best      rx pathid: 0, tx pathid: 0x0

The path from R11 has localpref 200, but the path through R31 has weight 200, and weight is compared first. R12 is the only router that knows about the weight, and it is the only router in AS 10 that does not follow the AS-wide decision.

Task 7: Influence Inbound Traffic with AS-Path Prepending

Objective: Make other autonomous systems prefer AS 20 over AS 30 to reach AS 10, by prepending the local AS number once to the routes R12 advertises to R31.

Weight and local preference decide how an AS sends traffic out. They can't reach into another AS, because neither one is sent to eBGP neighbors. What another AS does compare is the length of the AS path, step 4 of the algorithm.

Right now, R41 has two paths to R13's LAN with the same AS-path length:

text
R41# show ip bgp 172.16.13.0BGP routing table entry for 172.16.13.0/24, version 9Paths: (2 available, best #2, table default)  Advertised to update-groups:     1  Refresh Epoch 1  20 10    23.20.40.21 from 23.20.40.21 (21.21.21.21)      Origin IGP, localpref 100, valid, external      rx pathid: 0, tx pathid: 0  Refresh Epoch 1  30 10    23.30.40.31 from 23.30.40.31 (31.31.31.31)      Origin IGP, localpref 100, valid, external, best      rx pathid: 0, tx pathid: 0x0

Configuration

On R12:

ios
configure terminalroute-map PREPEND-OUT permit 10 set as-path prepend 10router bgp 10 neighbor 23.10.30.31 route-map PREPEND-OUT outendclear ip bgp 23.10.30.31 soft out

Prepending adds extra copies of the local AS number to the routes sent to one neighbor, so the path through that neighbor looks longer to everyone behind it. Only the local AS number should be prepended. Adding someone else's AS number would make that AS drop the route because of loop prevention.

This route map has no match statement, so it applies to every route sent to R31. soft out sends the routes again with the new policy.

Verification

text
R41# show ip bgp 172.16.13.0BGP routing table entry for 172.16.13.0/24, version 10Paths: (2 available, best #1, table default)  Advertised to update-groups:     1  Refresh Epoch 1  20 10    23.20.40.21 from 23.20.40.21 (21.21.21.21)      Origin IGP, localpref 100, valid, external, best      rx pathid: 0, tx pathid: 0x0  Refresh Epoch 1  30 10 10    23.30.40.31 from 23.30.40.31 (31.31.31.31)      Origin IGP, localpref 100, valid, external      rx pathid: 0, tx pathid: 0

The path through AS 30 is now 30 10 10, one entry longer than 20 10, so R41 switches to AS 20:

text
R41# traceroute 172.16.13.1 source Loopback1 numericTracing the route to 172.16.13.1VRF info: (vrf in name/id, vrf out name/id)  1 23.20.40.21 7 msec 6 msec 3 msec  2 23.10.20.11 10 msec 8 msec 7 msec  3 10.11.13.13 9 msec *  10 msec

R31 itself still uses its direct link to R12:

text
R31# show ip bgp 172.16.13.0BGP routing table entry for 172.16.13.0/24, version 12Paths: (2 available, best #2, table default)  Advertised to update-groups:     1  Refresh Epoch 1  40 20 10    23.30.40.41 from 23.30.40.41 (41.41.41.41)      Origin IGP, localpref 100, valid, external      rx pathid: 0, tx pathid: 0  Refresh Epoch 1  10 10    23.10.30.12 from 23.10.30.12 (12.12.12.12)      Origin IGP, localpref 100, valid, external, best      rx pathid: 0, tx pathid: 0x0

10 10 is still shorter than 40 20 10. One prepend is enough to move AS 40 without moving AS 30. With two prepends, the direct path would be 10 10 10, as long as the path through R41, and R31's choice would come down to a tiebreaker.

Prepending is only a request. The other AS can override it with its own weight or local preference, because both are compared before the AS path.

Task 8: Choose the Entry Link with MED

Objective: AS 10 has two links to AS 20. Make AS 20 use the R21–R11 link by advertising a MED of 50 on R11 and a MED of 100 on R12.

Before the change, R22 uses its own link to R12, because an eBGP path is preferred over the iBGP path from R21:

text
R22# show ip bgp 172.16.13.0BGP routing table entry for 172.16.13.0/24, version 8Paths: (2 available, best #2, table default)  Advertised to update-groups:     3  Refresh Epoch 1  10    10.21.22.21 from 10.21.22.21 (21.21.21.21)      Origin IGP, metric 0, localpref 100, valid, internal      rx pathid: 0, tx pathid: 0  Refresh Epoch 2  10    23.20.10.12 from 23.20.10.12 (12.12.12.12)      Origin IGP, localpref 100, valid, external, best      rx pathid: 0, tx pathid: 0x0

Configuration

On R12:

ios
configure terminalroute-map MED-OUT permit 10 set metric 100router bgp 10 neighbor 23.20.10.22 route-map MED-OUT outendclear ip bgp 23.20.10.22 soft out

R11 gets the same route map with set metric 50, applied outbound to 23.10.20.21.

The multi-exit discriminator (MED) is shown as Metric in the BGP table. It is a hint from one AS to a neighboring AS about which entry point to use, and the lowest value wins. MED is step 6 of the algorithm. By default, it is only compared between paths received from the same neighboring AS, which is the case here: both of R22's paths lead directly to AS 10. The neighboring AS carries the MED to its own iBGP neighbors, but it does not pass it on to a third AS.

Verification

text
R22# show ip bgp 172.16.13.0BGP routing table entry for 172.16.13.0/24, version 16Paths: (2 available, best #1, table default)  Advertised to update-groups:     1  Refresh Epoch 1  10    10.21.22.21 from 10.21.22.21 (21.21.21.21)      Origin IGP, metric 50, localpref 100, valid, internal, best      rx pathid: 0, tx pathid: 0x0  Refresh Epoch 2  10    23.20.10.12 from 23.20.10.12 (12.12.12.12)      Origin IGP, metric 100, localpref 100, valid, external      rx pathid: 0, tx pathid: 0

The external path from R12 has a metric of 100, and the internal path from R21 has a metric of 50. The internal path is now best, even though R22 has its own direct link to AS 10. MED is compared at step 6, one step before eBGP over iBGP, so the lower MED decides first.

text
R22# traceroute 172.16.13.1 source Loopback1 numericTracing the route to 172.16.13.1VRF info: (vrf in name/id, vrf out name/id)  1 10.21.22.21 6 msec 9 msec 3 msec  2 23.10.20.11 8 msec 9 msec 9 msec  3 10.11.13.13 8 msec *  8 msec

R22 sends the traffic across AS 20 to R21, which hands it to R11.

The MED stops at AS 20. On R41, the path through R21 has no metric at all:

text
R41# show ip bgp 172.16.13.0 | begin Refresh  Refresh Epoch 1  20 10    23.20.40.21 from 23.20.40.21 (21.21.21.21)      Origin IGP, localpref 100, valid, external, best      rx pathid: 0, tx pathid: 0x0  Refresh Epoch 1  30 10 10    23.30.40.31 from 23.30.40.31 (31.31.31.31)      Origin IGP, localpref 100, valid, external      rx pathid: 0, tx pathid: 0