BGP Part 2: iBGP Neighbors and How They Differ from eBGP
Black Belt: Advanced Routing
Build an iBGP session between two routers in the same AS, then fix the problems iBGP is known for: unreachable next hops and routes that are not passed on. Use prefix-lists, route-maps, weight, local preference and AS-path prepending to make one ISP primary and the other backup, and finish with a side-by-side comparison of how iBGP and eBGP treat routes.
Practice this in the lab
Every command in this lesson runs in the Practice Lab on two simulated IOS XE routers with two ISPs: BGP 2: iBGP, next-hop-self, primary and backup ISP. The lab shows what each ISP receives from you as you type.
Why iBGP Exists
In Part 1, R1 learned routes from ISP-A over eBGP. R2 is in the same AS and has its own link to ISP-B. Each router knows only its own ISP's routes. For the AS to make one sensible decision about where to send traffic, R1 and R2 have to tell each other what they learned, with all the BGP attributes intact. That is the job of iBGP: a BGP session between two routers with the same AS number.
You could redistribute BGP into OSPF instead, but you would lose the AS path, local preference and every other attribute, and you would risk pushing a huge number of routes into a protocol that was not built for it. Do not do that.
AS 64500 AS 64510
+---------+ +---------+
| ISP-A | | ISP-B |
+----+----+ +----+----+
| .2 | .6
| 203.0.113.0/30 | 203.0.113.4/30
| .1 eBGP | .5
+----+----+ +----+----+
| R1 +-----------------------+ R2 |
| 10.0.0.1| 10.1.12.0/30 (OSPF) | 10.0.0.2|
+---------+ .1 iBGP .2 +---------+
AS 65001
owns 198.51.100.0/24
The goal for this lesson: ISP-A is primary and ISP-B is backup, in both directions.
Peer Between Loopbacks
An eBGP neighbor is normally the address on the other end of the cable. iBGP neighbors are usually peered between loopback addresses instead. A loopback never goes down, so if there are two paths between R1 and R2 the session survives a link failure as long as the IGP (here OSPF) can still find a way.
That means the loopbacks must be reachable before BGP starts. This is the IGP's job:
R1(config)# interface Loopback0
R1(config-if)# ip address 10.0.0.1 255.255.255.255
R1(config-if)# exit
R1(config)# router ospf 1
R1(config-router)# router-id 10.0.0.1
R1(config-router)# network 10.0.0.1 0.0.0.0 area 0
R1(config-router)# network 10.1.12.0 0.0.0.3 area 0
R1(config-router)# end
R1# show ip route 10.0.0.2
Routing entry for 10.0.0.2/32
Known via "ospf 1", distance 110, metric 2, type intra area
R1# ping 10.0.0.2 source Loopback0
!!!!!
R2 gets the same with its own addresses. Always test with source Loopback0, because that is the address the BGP session will use.
Configure the iBGP Neighbor
R1(config)# router bgp 65001
R1(config-router)# neighbor 10.0.0.2 remote-as 65001
R1(config-router)# neighbor 10.0.0.2 description R2 iBGP
R1(config-router)# neighbor 10.0.0.2 update-source Loopback0
R1(config-router)# address-family ipv4 unicast
R1(config-router-af)# neighbor 10.0.0.2 activate
R2(config)# router bgp 65001
R2(config-router)# bgp router-id 10.0.0.2
R2(config-router)# no bgp default ipv4-unicast
R2(config-router)# neighbor 10.0.0.1 remote-as 65001
R2(config-router)# neighbor 10.0.0.1 description R1 iBGP
R2(config-router)# neighbor 10.0.0.1 update-source Loopback0
R2(config-router)# address-family ipv4 unicast
R2(config-router-af)# neighbor 10.0.0.1 activate
remote-as 65001is the same as the local AS, so the router treats this as iBGP. Nothing else marks it as internal.update-source Loopback0tells the router to open the BGP session from its loopback address. Without it, R1 would connect from 10.1.12.1 (the outgoing interface), and R2 has no neighbor configured with that address, so R2 refuses the connection. Configure it on both sides so the session comes up no matter which router connects first.- There is no TTL limit to worry about. iBGP packets are sent with a TTL of 255, so the neighbor can be many hops away.
Verify the Neighbor
R1# show bgp ipv4 unicast summary
BGP router identifier 10.0.0.1, local AS number 65001
Neighbor V AS MsgRcvd MsgSent TblVer InQ OutQ Up/Down State/PfxRcd
10.0.0.2 4 65001 6 8 4 0 0 00:02:31 0
203.0.113.2 4 64500 58 55 4 0 0 00:47:02 2
R1# show bgp ipv4 unicast neighbors 10.0.0.2
BGP neighbor is 10.0.0.2, remote AS 65001, internal link
Description: R2 iBGP
BGP version 4, remote router ID 10.0.0.2
BGP state = Established, up for 00:02:31
...
Connection state is ESTAB, I/O status: 1, unread input bytes: 0
Local host: 10.0.0.1, Local port: 179
Foreign host: 10.0.0.2, Foreign port: 41822
The same reading rules as Part 1 apply: a number under State/PfxRcd means Established. The neighbor detail now says internal link, and Local host: 10.0.0.1 confirms the session is sourced from the loopback.
Problem 1: The Next Hop Is Not Reachable
The session is up and R1 is sending R2 the routes from ISP-A. Look at them on R2:
R2# show bgp ipv4 unicast
Network Next Hop Metric LocPrf Weight Path
i 0.0.0.0 203.0.113.2 0 200 0 64500 i
i 192.0.2.0/24 203.0.113.2 0 200 0 64500 i
*>i 198.51.100.0/24 10.0.0.1 0 100 0 i
R2# show bgp ipv4 unicast 192.0.2.0/24
BGP routing table entry for 192.0.2.0/24, version 0
Paths: (1 available, no best path)
Not advertised to any peer
64500
203.0.113.2 (inaccessible) from 10.0.0.1 (10.0.0.1)
Origin IGP, metric 0, localpref 200, internal
R2# show ip route 192.0.2.0
% Network not in table
The two ISP routes have no * and no >. They are in the BGP table but they are not valid, so they are not installed in the routing table and not advertised to anyone. The detail view says why: the next hop is inaccessible.
This is the first big difference between the two kinds of session:
- When a router advertises a route to an eBGP neighbor, it sets the next hop to itself.
- When a router advertises an eBGP-learned route to an iBGP neighbor, it leaves the next hop unchanged.
So R2 is told "to reach 192.0.2.0/24, go to 203.0.113.2", which is ISP-A's address on a link only R1 is attached to. R2 has no route to 203.0.113.0/30, and BGP will not use a path whose next hop it cannot reach. This is the same rule from Part 1 seen from the receiving side: reachability comes first. A prefix must be in the routing table before it is advertised, and a next hop must be reachable before a received path can be used.
The 198.51.100.0/24 route is fine because R1 originated it, so its next hop is R1's loopback, which OSPF knows.
The fix: next-hop-self
R1(config)# router bgp 65001
R1(config-router)# address-family ipv4 unicast
R1(config-router-af)# neighbor 10.0.0.2 next-hop-self
R1(config-router-af)# end
R1# clear bgp ipv4 unicast 10.0.0.2 soft out
R2# show bgp ipv4 unicast
Network Next Hop Metric LocPrf Weight Path
*>i 0.0.0.0 10.0.0.1 0 200 0 64500 i
*>i 192.0.2.0/24 10.0.0.1 0 200 0 64500 i
*>i 198.51.100.0/24 10.0.0.1 0 100 0 i
R2# show ip route bgp
B* 0.0.0.0/0 [200/0] via 10.0.0.1, 00:00:12
B 192.0.2.0/24 [200/0] via 10.0.0.1, 00:00:12
B 198.51.100.0/24 [200/0] via 10.0.0.1, 00:03:40
next-hop-self makes R1 rewrite the next hop to its own loopback when it sends routes to R2. Now the paths are valid, best and installed. Configure it on every edge router toward its iBGP neighbors, so R2 gets the same line pointing at R1.
The other fix is to advertise the ISP link subnets into OSPF (as passive interfaces) so the original next hop is reachable. Both work. next-hop-self is more common because it keeps provider link addresses out of your IGP.
Notice two more things in that output: the i after the status codes means the path was learned over iBGP, and the routing table shows [200/0]. iBGP routes have an administrative distance of 200, not 20.
Problem 2: iBGP Does Not Pass iBGP Routes On
eBGP stops loops with the AS path: a router rejects any update that already contains its own AS. Inside one AS the path does not change, so that check cannot work. iBGP uses a blunt rule instead, often called iBGP split horizon:
A route learned from an iBGP neighbor is never advertised to another iBGP neighbor.
With only R1 and R2 this does not matter. Add a third router, R3, that peers only with R2:
ISP-A --eBGP-- R1 --iBGP-- R2 --iBGP-- R3
R1 learns 192.0.2.0/24 from ISP-A (eBGP) -> advertises it to R2
R2 learns 192.0.2.0/24 from R1 (iBGP) -> does NOT advertise it to R3
R3 never hears about 192.0.2.0/24
There are three ways to deal with this:
- Full mesh: every iBGP router peers with every other one. Because the sessions run between loopbacks, they do not need to be directly cabled. This is fine for a handful of routers, but the number of sessions is n(n-1)/2, so 10 routers need 45 sessions.
- Route reflectors: one or two routers are allowed to break the rule and reflect iBGP routes to their clients. Everyone else peers only with the reflectors. This is what most networks use.
- Confederations: split the AS into smaller private sub-ASes. Rare outside very large networks.
Making R2 a route reflector for R1 and R3 takes one line per client, on R2 only:
R2(config-router-af)# neighbor 10.0.0.1 route-reflector-client
R2(config-router-af)# neighbor 10.0.0.3 route-reflector-client
A reflector does not change the next hop of the routes it reflects, so the next hop R1 set with next-hop-self (10.0.0.1) must still be reachable from R3 through the IGP.
Bring Up R2's eBGP Session
R2's session to ISP-B is built exactly like R1's in Part 1, including the Null0 anchor route so the network statement has an exact match in the routing table. R2 originates the /24 too, so the prefix stays advertised if R1 fails.
R2(config)# ip route 198.51.100.0 255.255.255.0 Null0
R2(config)# ip prefix-list OUR-NETS seq 5 permit 198.51.100.0/24
R2(config)# ip prefix-list ISP-B-IN seq 5 permit 0.0.0.0/0
R2(config)# ip prefix-list ISP-B-IN seq 10 permit 192.0.2.0/24
R2(config)# route-map ISP-B-IN permit 10
R2(config-route-map)# match ip address prefix-list ISP-B-IN
R2(config-route-map)# exit
R2(config)# route-map ISP-B-OUT permit 10
R2(config-route-map)# match ip address prefix-list OUR-NETS
R2(config-route-map)# exit
R2(config)# router bgp 65001
R2(config-router)# neighbor 203.0.113.6 remote-as 64510
R2(config-router)# neighbor 203.0.113.6 description ISP-B
R2(config-router)# address-family ipv4 unicast
R2(config-router-af)# network 198.51.100.0 mask 255.255.255.0
R2(config-router-af)# neighbor 203.0.113.6 activate
R2(config-router-af)# neighbor 203.0.113.6 route-map ISP-B-IN in
R2(config-router-af)# neighbor 203.0.113.6 route-map ISP-B-OUT out
R2(config-router-af)# neighbor 10.0.0.1 next-hop-self
Local Preference Across the AS
In Part 1, R1 set local-preference 200 on everything it accepts from ISP-A. R2 leaves ISP-B's routes at the default of 100. Now that both sessions are up, look at R2:
R2# show bgp ipv4 unicast
Network Next Hop Metric LocPrf Weight Path
*>i 0.0.0.0 10.0.0.1 0 200 0 64500 i
* 203.0.113.6 0 0 64510 i
*>i 192.0.2.0/24 10.0.0.1 0 200 0 64500 i
* 203.0.113.6 0 64510 64500 i
* i 198.51.100.0/24 10.0.0.1 0 100 0 i
*> 0.0.0.0 0 32768 i
R2 has two valid paths to the default route: one straight out its own link to ISP-B, and one through R1. Normally a router prefers an eBGP path over an iBGP path, but that is step 7 in the best-path list. Local preference is step 2, and 200 beats 100, so R2 sends internet traffic across to R1 and out ISP-A. Local preference was set once, on R1, and it travelled over iBGP to make the whole AS agree. This is the behavior that makes it the right tool for choosing an exit.
Compare with R1, which only has one path for the ISP routes:
R1# show bgp ipv4 unicast
Network Next Hop Metric LocPrf Weight Path
*> 0.0.0.0 203.0.113.2 0 200 0 64500 i
*> 192.0.2.0/24 203.0.113.2 0 200 0 64500 i
* i 198.51.100.0/24 10.0.0.2 0 100 0 i
*> 0.0.0.0 0 32768 i
R1 does not see ISP-B's routes at all. That is not a fault: a BGP router advertises only its best path, and R2's best paths for those prefixes are the ones it learned from R1. It will not send them back. If the ISP-A session fails, R1 withdraws its routes, R2's ISP-B paths become best, and R2 advertises them to R1 with itself as next hop. That is the backup working.
Check what each router is sending the other with the same commands as Part 1:
R1# show bgp ipv4 unicast neighbors 10.0.0.2 advertised-routes
Network Next Hop Metric LocPrf Weight Path
*> 0.0.0.0 203.0.113.2 0 200 0 64500 i
*> 192.0.2.0/24 203.0.113.2 0 200 0 64500 i
*> 198.51.100.0/24 0.0.0.0 0 32768 i
R2# show bgp ipv4 unicast neighbors 10.0.0.1 routes
Network Next Hop Metric LocPrf Weight Path
*>i 0.0.0.0 10.0.0.1 0 200 0 64500 i
*>i 192.0.2.0/24 10.0.0.1 0 200 0 64500 i
* i 198.51.100.0/24 10.0.0.1 0 100 0 i
One thing that confuses people: advertised-routes prints the routes as they sit in R1's own table, so the next hop can still show 203.0.113.2 and the local weight is listed. The next-hop-self rewrite happens as the update is sent, which is why R2 sees 10.0.0.1. Weight is not sent at all. Always confirm on the receiving router.
Weight on an iBGP Router
Weight stays on the router where it is set. It is never included in an update, to iBGP or eBGP neighbors, and it is checked before local preference. That makes it the tool for a one-router exception.
Say ISP-B is the better way to reach 192.0.2.0/24 from R2's site, and only that prefix. Match it with a prefix-list and set the weight in R2's inbound route-map:
R2(config)# ip prefix-list VIA-ISP-B seq 5 permit 192.0.2.0/24
R2(config)# route-map ISP-B-IN permit 5
R2(config-route-map)# match ip address prefix-list VIA-ISP-B
R2(config-route-map)# set weight 500
R2(config-route-map)# end
R2# clear bgp ipv4 unicast 203.0.113.6 soft in
R2# show bgp ipv4 unicast 192.0.2.0/24
BGP routing table entry for 192.0.2.0/24, version 12
Paths: (2 available, best #2, table default)
64500
10.0.0.1 (metric 2) from 10.0.0.1 (10.0.0.1)
Origin IGP, metric 0, localpref 200, valid, internal
64510 64500
203.0.113.6 from 203.0.113.6 (203.0.113.6)
Origin IGP, localpref 100, weight 500, valid, external, best
Sequence 5 runs before the existing sequence 10, so this one prefix gets weight 500 and everything else falls through to sequence 10 unchanged. On R2 the ISP-B path now wins even though its local preference is lower and its AS path is longer, because weight is compared first.
R1 is not affected. R2 now advertises its ISP-B path to R1 (it is R2's best), but the weight does not travel with it, and R1 still prefers its own path with local preference 200. If you wanted every router to change its mind, you would raise the local preference instead. Remove sequence 5 again to return to the plain primary and backup design.
Prefix-Lists and Route-Maps on an iBGP Session
The syntax is identical to eBGP: neighbor ... prefix-list NAME in|out and neighbor ... route-map NAME in|out, followed by a soft clear. For example, to make sure R1 never passes very small prefixes to R2:
R1(config)# ip prefix-list NO-SMALL seq 5 deny 0.0.0.0/0 ge 25
R1(config)# ip prefix-list NO-SMALL seq 10 permit 0.0.0.0/0 le 32
R1(config)# router bgp 65001
R1(config-router)# address-family ipv4 unicast
R1(config-router-af)# neighbor 10.0.0.2 prefix-list NO-SMALL out
R1(config-router-af)# end
R1# clear bgp ipv4 unicast 10.0.0.2 soft out
What changes is how you should use them:
- Do your filtering and attribute setting at the eBGP edge, as routes enter and leave the AS. That is where local preference is set, where prepends are added, and where unwanted routes are dropped.
- Keep iBGP sessions as plain as you can. iBGP routers should share a consistent view. If one router filters a route its neighbors still use, traffic can be forwarded to a router that has no route for it and dropped.
- A route-map on an iBGP session can set local preference, MED, communities and (inbound) weight. Prepending is not done here: iBGP does not add your AS to the path. Your AS number is only added when a route leaves the AS, so that is where prepends belong.
AS-Path Prepending at the Backup Edge
Local preference took care of outbound traffic. For inbound traffic, the internet should prefer ISP-A, so make the path through ISP-B look longer. This belongs on R2's eBGP session, outbound:
R2(config)# route-map ISP-B-OUT permit 10
R2(config-route-map)# set as-path prepend 65001 65001 65001
R2(config-route-map)# end
R2# clear bgp ipv4 unicast 203.0.113.6 soft out
Compare what each ISP receives:
ISP-A# show bgp ipv4 unicast 198.51.100.0/24 | include 65001
65001
ISP-B# show bgp ipv4 unicast 198.51.100.0/24 | include 65001
65001 65001 65001 65001
Between R1 and R2 the same prefix has an empty AS path (look at the Path column for 198.51.100.0/24 in the tables above: just the origin code i). That is iBGP leaving the path alone. The first 65001 only appears when the route crosses an eBGP session.
As in Part 1, prepending is a hint. ISP-B will still deliver traffic from its own customers directly to you, and a longer path is only compared after local preference inside every other network.
iBGP and eBGP Side by Side
| Behavior | eBGP | iBGP |
|---|---|---|
| Neighbor's AS | Different from yours | Same as yours |
| Neighbor location | Directly connected by default (TTL 1) | Anywhere the IGP can reach (TTL 255), usually loopback to loopback |
| AS path when advertising | Your AS is prepended | Not changed |
| Next hop when advertising | Set to the advertising router | Not changed for eBGP-learned routes (use next-hop-self) |
| Loop prevention | Drop updates that contain your own AS | Never advertise iBGP-learned routes to another iBGP neighbor |
| Who a learned route is passed to | All eBGP and iBGP neighbors | eBGP neighbors only (unless a route reflector is used) |
| Local preference | Not sent | Sent, and honored by every router in the AS |
| MED | Sent to the neighboring AS | Carried unchanged inside the AS |
| Weight | Never sent | Never sent |
| Administrative distance | 20 | 200 |
| Best-path tie | Preferred over an iBGP path (step 7) | Loses to an eBGP path when everything above is equal |
Code in show bgp ipv4 unicast | No letter after the status | i after the status (*>i) |
Why the distances are 20 and 200: an eBGP route is news from outside that no IGP could know, so it should win (20 beats OSPF's 110). An iBGP route might describe a network inside your AS that OSPF also knows, and the IGP's own path should be trusted first (110 beats 200).
When that happens you will see an r in the BGP table:
R2# show bgp ipv4 unicast
Network Next Hop Metric LocPrf Weight Path
r>i 10.20.0.0/24 10.0.0.1 0 100 0 i
R2# show bgp ipv4 unicast rib-failure
Network Next Hop RIB-failure RIB-NH Matches
10.20.0.0/24 10.0.0.1 Higher admin distance n/a
RIB-failure sounds alarming but usually is not. It means BGP's best path was not installed because the routing table already has that prefix from a source with a lower distance (here OSPF). The route is still valid and is still advertised to neighbors.
The Finished Configurations
R1 keeps everything from Part 1 and gains the iBGP neighbor:
router bgp 65001
neighbor 10.0.0.2 remote-as 65001
neighbor 10.0.0.2 description R2 iBGP
neighbor 10.0.0.2 update-source Loopback0
!
address-family ipv4
neighbor 10.0.0.2 activate
neighbor 10.0.0.2 next-hop-self
exit-address-family
R2 in full:
interface Loopback0
ip address 10.0.0.2 255.255.255.255
!
router ospf 1
router-id 10.0.0.2
network 10.0.0.2 0.0.0.0 area 0
network 10.1.12.0 0.0.0.3 area 0
!
ip route 198.51.100.0 255.255.255.0 Null0
!
ip prefix-list OUR-NETS seq 5 permit 198.51.100.0/24
ip prefix-list ISP-B-IN seq 5 permit 0.0.0.0/0
ip prefix-list ISP-B-IN seq 10 permit 192.0.2.0/24
!
route-map ISP-B-IN permit 10
match ip address prefix-list ISP-B-IN
!
route-map ISP-B-OUT permit 10
match ip address prefix-list OUR-NETS
set as-path prepend 65001 65001 65001
!
router bgp 65001
bgp router-id 10.0.0.2
bgp log-neighbor-changes
no bgp default ipv4-unicast
neighbor 10.0.0.1 remote-as 65001
neighbor 10.0.0.1 description R1 iBGP
neighbor 10.0.0.1 update-source Loopback0
neighbor 203.0.113.6 remote-as 64510
neighbor 203.0.113.6 description ISP-B
!
address-family ipv4
network 198.51.100.0 mask 255.255.255.0
neighbor 10.0.0.1 activate
neighbor 10.0.0.1 next-hop-self
neighbor 203.0.113.6 activate
neighbor 203.0.113.6 route-map ISP-B-IN in
neighbor 203.0.113.6 route-map ISP-B-OUT out
exit-address-family
Add the password, TTL security and maximum-prefix lines from Part 1 to the ISP-B session as well.
Result: outbound traffic from both routers leaves through ISP-A (local preference 200 set on R1, shared over iBGP). Inbound traffic prefers ISP-A (shorter AS path). If R1 or ISP-A fails, R2 and ISP-B take over in both directions with no manual change.
More to Explore
- Communities: tags you attach to routes so policy can be written once ("anything tagged 65001:100 gets local preference 200"). They are not sent unless you add
neighbor ... send-community. Many ISPs publish communities that let you set their local preference or prepend on your behalf, which is stronger than prepending yourself. - Peer groups and templates: define the iBGP settings once and apply them to many neighbors.
- BFD:
neighbor ... fall-over bfddetects a dead neighbor in under a second instead of waiting for the 180-second hold timer. - RPKI origin validation: check that the AS announcing a prefix is allowed to. See RPKI & BGP Security.
Common Mistakes
- Missing
update-source Loopback0: with it missing on both routers the session sits in Active, because each TCP connection arrives from an address the other router does not expect. With it on only one router, the session depends on that router being the one that connects. - Loopbacks not in the IGP: no route to the neighbor, so the session stays Idle.
- No
next-hop-self: routes appear inshow bgp ipv4 unicastwithout*or>, andshow bgp ipv4 unicast <prefix>says the next hop is inaccessible. - Expecting iBGP routes to be relayed: a third router that peers with only one iBGP neighbor will miss routes. Use a full mesh or a route reflector.
- Looking for a route with distance 20 inside the AS: iBGP routes are distance 200 and lose to OSPF, EIGRP and static routes for the same prefix.
- Trying to steer the whole AS with weight: weight never leaves the router. Use local preference.
- Only one router originating your prefix: if that router fails, your block disappears from the internet even though the other ISP link is up.
Summary
- iBGP is a BGP session inside one AS. Peer between loopbacks, use
update-sourceon both sides, and let the IGP provide reachability. - iBGP does not change the next hop. Use
next-hop-selfon edge routers, or the learned routes are unusable. - iBGP-learned routes are not passed to other iBGP neighbors. Build a full mesh or use route reflectors.
- Local preference travels across iBGP and decides the exit for the whole AS. Weight stays on one router and overrides it there.
- The AS path is only changed on eBGP sessions, so prepending is configured at the edge, outbound to the ISP you want as backup.
- eBGP routes have distance 20 and iBGP routes 200. A router advertises only its best path, and only if that path is valid.
- The same show commands work for both:
show bgp ipv4 unicast summary,show bgp ipv4 unicast,show bgp ipv4 unicast <prefix>, andshow bgp ipv4 unicast neighbors <ip> advertised-routes | routes | received-routes.