Free tech learning for everyone, from basics to pro

Routing & SwitchingNetworking SecurityAdvanced

Lab: dual-homed BGP to two ISPs with iBGP, next-hop-self and local preference

In short: This lab builds a realistic multihomed edge. Each edge router peers with one ISP, the two edges run iBGP with next-hop-self, outbound prefix lists stop transit, local preference makes ISP-A the primary exit, and AS path prepending makes ISP-B the backup for inbound traffic. You then test failover by shutting down links.

What you need

Four IOSv or CSR1000v/Catalyst 8000v routers in Cisco Modeling Labs, EVE-NG or GNS3: ISP-A, ISP-B, EDGE-1 and EDGE-2, plus a loopback on each ISP to act as "the internet" (8.8.8.0/24 on both, so both ISPs can reach it). Your company owns 203.0.113.0/24, uses AS 64500, and runs OSPF internally between the edges so their loopbacks can reach each other.

Lab topologyISP-AAS 65010EDGE-1AS 64500iBGPbetween edgesEDGE-2AS 64500ISP-BAS 65020
Figure 1. Two edge routers, one per provider, with iBGP between them and the LAN behind both.

Step 1: eBGP to each provider

! EDGE-1
router bgp 64500
 neighbor 198.51.100.1 remote-as 65010
 neighbor 2.2.2.2 remote-as 64500
 neighbor 2.2.2.2 update-source Loopback0
 address-family ipv4
  network 203.0.113.0 mask 255.255.255.0
  neighbor 198.51.100.1 activate
  neighbor 198.51.100.1 prefix-list OURS out
  neighbor 2.2.2.2 activate
  neighbor 2.2.2.2 next-hop-self
ip prefix-list OURS permit 203.0.113.0/24
ip route 203.0.113.0 255.255.255.0 Null0

EDGE-2 mirrors this with ISP-B (AS 65020) and iBGP to EDGE-1's loopback 1.1.1.1.

Step 2: why next-hop-self matters

eBGP routes keep the ISP's address as the next hop when passed over iBGP. EDGE-2 does not know how to reach ISP-A's link address, so without next-hop-self it marks those routes as inaccessible. Run show ip bgp on EDGE-2 before and after adding it: the routes change from unusable to valid.

Step 3: prefer ISP-A for outbound traffic

! EDGE-1
route-map FROM-ISP-A permit 10
 set local-preference 200
router bgp 64500
 address-family ipv4
  neighbor 198.51.100.1 route-map FROM-ISP-A in

Local preference is shared over iBGP, so EDGE-2 also prefers ISP-A's routes and sends outbound traffic to EDGE-1. Confirm with show ip bgp 8.8.8.0 on EDGE-2: the best path (>) should be via 1.1.1.1 with LocPrf 200.

Step 4: make ISP-B the backup for inbound traffic

! EDGE-2
route-map TO-ISP-B permit 10
 set as-path prepend 64500 64500 64500
router bgp 64500
 address-family ipv4
  neighbor 192.0.2.1 route-map TO-ISP-B out

In a real network, also confirm the provider honours prepending or offers a backup community. In the lab, check on a router connected to both ISPs that the path via ISP-A is preferred because it is shorter.

Step 5: test failover

  1. From a LAN host behind both edges, run a continuous ping to 8.8.8.8 and a traceroute.
  2. Shut EDGE-1's link to ISP-A. Watch show ip bgp summary: the session drops after the hold timer (or instantly if the interface goes down).
  3. Traffic should move to EDGE-2 and ISP-B. Count the lost pings.
  4. Add neighbor 198.51.100.1 fall-over bfd with BFD on the interface and repeat. Failover should drop to under a second when the link fails without the interface going down.

Things to try next

  • Remove the outbound prefix list on EDGE-2 and see ISP-B learn ISP-A's routes through you. That is accidental transit.
  • Replace prepending with a community and a route map on ISP-B that lowers local preference when it sees it.
  • Add IPv6 with a /48 and a second address family.

Practice

Why does EDGE-2 mark ISP-A's routes as inaccessible before next-hop-self is configured?
The routes keep ISP-A's link address as the next hop, which EDGE-2 has no route to.
Which attribute makes both edge routers prefer ISP-A for outbound traffic?
Local preference, set inbound on EDGE-1 and shared through iBGP.
How can you make BGP failover faster than the hold timer?
Use BFD with neighbor ... fall-over bfd.

Key takeaways

  • Peer each edge router with one ISP and run iBGP between the edges.
  • Use next-hop-self on iBGP so internal routers can reach eBGP next hops.
  • Local preference picks the outbound exit; prepending influences inbound traffic.
  • Filter outbound advertisements and test failover, ideally with BFD.
Tracks your learning on this device only. See your progress on the learning paths.
Verified author✓ Valid
Issued to
Mohamed Fayas
Role
Founder of FM TecHub
Credentials
CCNABTEC HND Network EngineeringBEng (Hons) Computer Networking & Cloud Security
Issuer
FM TecHub · fmtechub.com

He writes practical, plain-English guides on networking, security and cloud.

More about the author →

Original content written by Mohamed Fayas for FM TecHub. © 2026 FM TecHub. You're welcome to share a link to this page; please don't copy the text elsewhere without permission.

Email updates: coming soon

New notes, tools and security news from FM TecHub by email, explained simply. Free. We're not collecting email addresses yet; see our privacy policy.

PortServiceStatus
SMTP/25Email updatesopening soon

Meanwhile, stay connected: