Skip to content
TrungCLN

NetworkingIntermediate

VPN with 2 tunnels and BGP: how long does failover really take?

By Cao Le Nam TrungPublished Updated 16 min read

OfficeAWS Cloudtunnel-1 soft failuretunnel-2 carries trafficOffice LANRouter BGPVPN GatewayVPC
Diagram drawn with the official AWS Architecture Icons.

Key results

  • Hard failure (interface DOWN): BGP drops the route at once, traffic moves to the other tunnel, no ping is lost.
  • Soft failure (interface UP, 100% packet loss): for about 20 seconds traffic is still sent into the dead path while BGP waits for the 30-second hold timer.
  • AS-path prepending turns tunnel-2 into a backup path; BFD is the way to detect failures faster.

What you need

  • No prior BGP knowledge: the guide explains it from scratch.
  • A Linux machine with Docker and containerlab (about 4 GB RAM). Setup is in the "Lab setup" guide.
  • The "AWS" side here is an FRRouting router playing AWS, not real AWS; the BGP behaviour is the same.
Time
40 min
Cost
$0, runs on your own machine
  • AWS Site-to-Site VPN
  • BGP
  • BFD
  • FRRouting
  • containerlab

When you connect an office to AWS with Site-to-Site VPN, AWS always gives you two tunnels. The idea is simple: if one breaks, you still have the other. But “you still have the other” does not mean traffic moves over instantly. This guide rebuilds that exact setup on your own machine, breaks it on purpose in two different ways, and measures how long traffic takes to move.

You do not need to know BGP beforehand. Every concept is explained where it first appears, and every configuration line says what it does and why it is set that way.

A few concepts first

Tunnel
An encrypted connection that runs across the Internet. Packets travel over the public Internet, but outsiders cannot read them.Example: AWS Site-to-Site VPN gives you 2 tunnels, each ending on a different device on the AWS side.
BGP (dynamic routing)
A protocol that lets two routers tell each other "these are the IP ranges in my network", so you do not type every route by hand.Example: The office router tells AWS that 10.10.0.0/16 lives in the office.
ASN
The number that identifies each side in BGP, a bit like a postcode. When the two sides have different ASNs it is called eBGP.Example: 64512 is the default Amazon-side ASN; 64512 to 65534 is the private range you can use freely.
Keepalive
A small message BGP sends at regular intervals to say "I am still here".Example: This guide sends a keepalive every 10 seconds.
Hold timer
If no keepalive arrives within this time, BGP declares the peer dead and removes every route learned from it.Example: The AWS VPN default is 30 seconds.
Failover
When the primary path fails, traffic automatically moves to the backup path.Example: tunnel-1 fails, traffic goes through tunnel-2.

BGP works like the picture below: the two routers keep announcing their networks to each other and send regular keepalives to know the other side is alive.

Office routerAS 65000 · 10.10.0.0/16AWS-side routerAS 64512 · 172.31.0.0/16"To reach 10.10.0.0/16, send it to me""To reach 172.31.0.0/16, send it to me"Keepalive every 10 seconds: "I am still here"Hold timer 30 seconds: after 30 s of silence, drop every route learned from the peer
BGP is like two gatekeepers who keep telling each other "my network is here, send deliveries to me", and phone each other regularly to check the other side is still alive.

Lab architecture

OfficeAWS (emulated with FRRouting)tunnel-1 · 169.254.10.0/30tunnel-2 · 169.254.20.0/3010.10.0.0/16AS 65000AS 64512172.31.0.0/16BGP on both tunnels · keepalive 10 s · hold timer 30 s
The lab builds exactly this with two FRRouting containers. Each tunnel is a separate link with its own /30, just like the "inside tunnel" ranges AWS assigns.
Component Value Why this value
Office network 10.10.0.0/16 A private range that does not overlap with the AWS side. If both sides used the same range, the router would not know where to send packets.
AWS-side network 172.31.0.0/16 The same as the default VPC range in every AWS account.
Office / AWS ASN 65000 / 64512 Two different ASNs so we run eBGP like the real thing. 64512 is the default Amazon-side ASN.
Tunnel endpoint IPs 169.254.10.0/30, 169.254.20.0/30 A /30 has exactly 2 usable addresses, one for each end of the tunnel. AWS also assigns a 169.254.x.x/30 to every tunnel.

Step 1: Build the topology with containerlab

What you are doing: creating 2 virtual routers and wiring them together. containerlab reads a YAML file that says “these devices exist and are cabled like this”, then creates the containers and the virtual cables for you.

Create this folder layout. onprem is the office router, aws is the router playing AWS:

01-bgp-2-tunnels/
├── topo.clab.yml
├── onprem/ (daemons, frr.conf, vtysh.conf)
└── aws/ (daemons, frr.conf, vtysh.conf)
topo.clab.yml
name: bgp2t
topology:
defaults:
kind: linux
image: quay.io/frrouting/frr:9.1.0
nodes:
onprem:
binds:
- onprem/daemons:/etc/frr/daemons
- onprem/frr.conf:/etc/frr/frr.conf
- onprem/vtysh.conf:/etc/frr/vtysh.conf
aws:
binds:
- aws/daemons:/etc/frr/daemons
- aws/frr.conf:/etc/frr/frr.conf
- aws/vtysh.conf:/etc/frr/vtysh.conf
links:
- endpoints: ["onprem:eth1", "aws:eth1"] # tunnel 1
- endpoints: ["onprem:eth2", "aws:eth2"] # tunnel 2
Line Meaning Why
name: bgp2t Lab name containerlab names the containers clab-bgp2t-<router name>; every later command uses that name.
image: quay.io/frrouting/frr:9.1.0 Each router is an FRRouting container FRRouting is open-source routing software with Cisco-like syntax. Pinning the version means a re-run gives the same result.
binds Mounts config files from your machine into the container Edit the file on your machine and the router sees it; deleting the container does not lose the config.
links Connects eth1 to eth1 and eth2 to eth2 Each link plays one tunnel. Two separate links let us break them one at a time.

Step 2: Configure BGP

What you are doing: writing the office router config so it speaks BGP with the AWS router over both tunnels.

onprem/frr.conf
frr defaults traditional
hostname onprem
interface eth1
ip address 169.254.10.1/30
interface eth2
ip address 169.254.20.1/30
interface lo
ip address 10.10.0.1/16
router bgp 65000
bgp router-id 10.10.0.1
no bgp ebgp-requires-policy
neighbor 169.254.10.2 remote-as 64512
neighbor 169.254.10.2 timers 10 30
neighbor 169.254.20.2 remote-as 64512
neighbor 169.254.20.2 timers 10 30
address-family ipv4 unicast
network 10.10.0.0/16
exit-address-family
Line Meaning Why it is set this way
interface eth1 + ip address 169.254.10.1/30 IP for the office end of tunnel-1 Both routers must share the same /30 to talk directly. The office takes .1, AWS takes .2.
interface lo + ip address 10.10.0.1/16 A fake “office LAN” on the loopback interface The lab has no real office PCs. Loopback is always UP, so 10.10.0.0/16 always exists and can be announced.
router bgp 65000 Turns on BGP with ASN 65000 Our own ASN. The other side must use this exact number in its remote-as line.
bgp router-id 10.10.0.1 The router’s identity in BGP Pinned to the loopback IP so it never changes when an interface flaps.
no bgp ebgp-requires-policy Allows route exchange without a filter policy FRRouting blocks eBGP by default until a filter exists, to avoid leaking routes. The lab skips it for brevity; production should use filters (prefix-list, route-map).
neighbor 169.254.10.2 remote-as 64512 Declares the BGP peer at the far end of tunnel-1 BGP does not discover peers on its own. You must give the peer’s IP and ASN.
neighbor ... timers 10 30 Keepalive 10 s, hold timer 30 s Matches the 30-second default hold time on the AWS side. Keepalive is usually a third of the hold timer, so losing 1 or 2 keepalives does not kill the session.
network 10.10.0.0/16 Announces the office network to the peer This is the “to reach 10.10.0.0/16, send it to me” message. The range must really exist in the routing table (thanks to the loopback above) for BGP to announce it.

aws/frr.conf is identical except for: .2 on eth1 and eth2; loopback 172.31.0.1/16; router bgp 64512; peers are .1 with remote-as 65000; network 172.31.0.0/16.

The two small remaining files:

  • daemons: set zebra=yes, bgpd=yes, bfdd=yes. FRRouting runs each protocol as a separate process; without bgpd, the BGP config above does nothing.
  • vtysh.conf: one line, service integrated-vtysh-config, so all configuration lives in a single frr.conf.

Start the lab:

Terminal window
sudo containerlab deploy -t topo.clab.yml

Step 3: Check the normal state

What you are doing: asking the office router “which paths do you know to the AWS network?”. Always look at the healthy state before breaking anything, so you have something to compare with.

Terminal window
docker exec clab-bgp2t-onprem vtysh -c "show ip bgp"
Output of show ip bgp: network 172.31.0.0/16 has two paths via 169.254.10.2 and 169.254.20.2, and a ping from 10.10.0.1 to 172.31.0.1 receives all 3 packets
Real run on the lab machine: the office router sees two paths to 172.31.0.0/16, one per tunnel, and a ping from the office network to the AWS network succeeds.

How to read the output:

Network Next Hop Metric LocPrf Weight Path
*> 10.10.0.0/16 0.0.0.0 0 32768 i
*= 172.31.0.0/16 169.254.10.2 0 0 64512 i
*> 169.254.20.2 0 0 64512 i
Symbol Meaning
* Valid route, can be used.
> The best route BGP picked.
= A route used alongside the best one: traffic is load-shared (ECMP) across both tunnels.
Next Hop Send packets to this IP, i.e. which tunnel’s far end.
Path The list of ASNs to cross. 64512 i means one hop through the AWS network to the destination.

There are two lines for 172.31.0.0/16, via 169.254.10.2 (tunnel-1) and 169.254.20.2 (tunnel-2). Both tunnels are working. Which line carries > can change between runs; with ECMP it does not matter, because traffic uses both.

Step 4: Hard-fail tunnel-1

What you are doing: shutting down tunnel-1’s interface completely, like pulling the cable or powering off the far-end device. This is a hard failure.

Terminal window
docker exec clab-bgp2t-aws ip link set eth1 down
docker exec clab-bgp2t-onprem vtysh -c "show ip bgp"
docker exec clab-bgp2t-onprem ping -c3 -I 10.10.0.1 172.31.0.1
After eth1 is shut down: the BGP table has a single path to 172.31.0.0/16 via 169.254.20.2, and 3 pings get 3 replies, 0% packet loss
Real run: right after the interface goes down, only the tunnel-2 path remains and no ping is lost.

How to read it: a single path remains, via 169.254.20.2, and ping shows 0% packet loss. When an interface goes DOWN, the operating system tells the router at once; the router closes the BGP session on that tunnel and removes the route immediately.

Bring the interface back up before the next step: docker exec clab-bgp2t-aws ip link set eth1 up.

Step 5: Soft-fail tunnel-1

RouterRouterRouterRouterpackets droppedHard failureSoft failureInterface DOWNrouter knows and drops the route at onceInterface still UP, all packets droppedrouter only knows when the hold timer expires✕?
A hard failure is a road with a barrier across it: you see it at once. A soft failure is a bridge collapsed in the middle while the sign still says "road open".

What you are doing: keeping the interface UP but dropping 100% of packets on tunnel-1. This is a soft failure, and it is the most common kind in real life: a flaky Internet link, a firewall blocking by mistake, a provider problem somewhere in the middle.

netem is a Linux feature that simulates bad networks (loss, delay). The command below turns on 100% loss on eth1, then every 2 seconds counts how many paths to the AWS network the office router still has:

Terminal window
sudo containerlab tools netem set -n clab-bgp2t-aws -i eth1 --loss 100
for i in $(seq 2 2 36); do
printf "%3ss paths to VPC: %s\n" $i \
$(docker exec clab-bgp2t-onprem vtysh -c "show ip bgp" | grep -c 64512); sleep 2
done
Loop output: from 2 to 20 seconds the router still sees 2 paths to the VPC; from 22 seconds on it sees only 1
Real run (loop output): for the first 20 seconds the router still believes in 2 paths; only from second 22 is it down to 1.

Both measurements on one chart make the difference obvious:

For about 20 seconds part of the traffic goes into a dead path2 paths1 path0s6s12s18s24s30s36shold timer expires, BGP drops the pathHard failure (interface DOWN): instant switchSoft failure (interface UP, packets dropped)
Real measurements from steps 4 and 5: how many paths to the AWS network the office router still holds, over time since tunnel-1 failed.

How to read it: for about 20 seconds, the router still believes there are two paths and keeps sending part of the traffic into the dead tunnel. The interface is still UP, so the router has no idea. It only finds out when the hold timer expires without a keepalive.

To detect failures faster, use BFD (Bidirectional Forwarding Detection): a protocol built only to check that a path is alive, using very small packets sent very often. According to the FRRouting documentation, BFD detects failures in under a second and then tells BGP to drop the route. The daemons file already enables bfdd, so you can try it next.

Remove the simulated loss before the next step:

Terminal window
sudo containerlab tools netem set -n clab-bgp2t-aws -i eth1 --loss 0

Step 6: Primary and backup paths with AS-path prepending

OfficeAWSOfficeAWStunnel-1tunnel-2tunnel-1: primarytunnel-2: backupDefault: load sharing (ECMP)After AS-path prepend
The AS path is like the number of stops on a bus route: BGP always picks the route with fewer stops. Add fake stops to tunnel-2 and it is only used when tunnel-1 fails.

What you are doing: turning tunnel-2 into a backup path that is only used when tunnel-1 fails.

Why you need it: load-sharing across two tunnels sounds good but can break connections. Many firewalls track every connection (stateful). If a packet leaves through tunnel-1 and the reply comes back through tunnel-2, the firewall has never seen that connection and drops the reply. With one primary and one backup, traffic goes and returns on the same path.

How: BGP prefers the path with the shorter AS path (fewer networks to cross). We make the AWS router announce over tunnel-2 with a longer AS path by repeating its own ASN:

Terminal window
docker exec clab-bgp2t-aws vtysh -c "conf t" \
-c "route-map PREPEND permit 10" -c "set as-path prepend 64512 64512 64512" \
-c "router bgp 64512" -c "address-family ipv4 unicast" \
-c "neighbor 169.254.20.1 route-map PREPEND out" -c "end" -c "clear ip bgp * soft out"
Command Meaning Why
route-map PREPEND permit 10 Creates a rule called PREPEND that edits routes A route-map is where BGP lets you change route attributes before sending them.
set as-path prepend 64512 64512 64512 Adds ASN 64512 three more times to the AS path Use your own ASN so you never impersonate someone else’s network. Three times is long enough to always lose to the other path.
neighbor 169.254.20.1 route-map PREPEND out Applies the rule only when sending over tunnel-2 Tunnel-1 keeps the short AS path, so it becomes the primary.
clear ip bgp * soft out Re-sends routes with the new rule “soft” re-sends without tearing down the BGP session, so nothing is interrupted.
BGP table after prepending: the path via 169.254.10.2 is marked best with path 64512, the path via 169.254.20.2 has 64512 repeated 4 times and is not selected
Real run: the tunnel-2 path has a longer AS path and is no longer selected.
*> 172.31.0.0/16 169.254.10.2 0 0 64512 i
* 169.254.20.2 0 0 64512 64512 64512 64512 i

How to read it: the tunnel-2 path is still valid (*) but no longer has > or =. Tunnel-1 is the primary; tunnel-2 waits, and if tunnel-1 fails BGP picks tunnel-2 immediately.

Applying this on real AWS

  • Use dynamic routing (BGP) for any VPN that must fail over on its own. With static routing, your device has to detect a dead tunnel by itself.
  • According to the AWS documentation, traffic from AWS to your network prefers one tunnel and moves to the other if something fails on the AWS side. Traffic from your side to AWS can use both tunnels, so your device configuration decides whether you load-share.
  • If the same prefix has both a static route and a BGP route on the virtual private gateway, the static route wins. Mixing the two easily makes failover behave unexpectedly.
  • The default BGP hold time on the AWS side is 30 seconds, as in this lab. Your firewall must allow TCP 179 (BGP) on the inside tunnel IPs, or the BGP session never comes up.
  • During maintenance AWS updates one tunnel at a time. You only ride through it cleanly if both tunnels are UP and failover has been tested.

Common errors

Symptom Usual cause How to check
show ip bgp summary shows Active or Connect, never Established Wrong peer IP, wrong remote-as, or the two tunnel ends are in different /30s Compare every neighbor line on both sides; ping 169.254.10.2 from the office router
The session is up but no routes arrive and the summary says (Policy) Missing no bgp ebgp-requires-policy, or no filter that allows the routes Add that line, or write a permitting route-map
The peer never receives 10.10.0.0/16 The network line does not match a range that really exists in the routing table show ip route 10.10.0.0/16 must return a result

Clean up

Terminal window
sudo containerlab destroy -t topo.clab.yml --cleanup

FAQ

Why does a hard failure fail over faster than a soft one? A hard failure takes the interface DOWN, so the router closes the BGP session at once. With a soft failure the interface stays UP and the router only notices when the hold timer expires without a keepalive.

Should I just set a very low hold timer instead of enabling BFD? A very low hold timer makes BGP sessions drop on brief network hiccups. BFD is purpose-built for fast, lightweight failure detection, so it is the better choice when your devices support it.

Which traffic direction does AS-path prepending affect? Traffic coming into the network of whoever prepends: the other side sees a longer AS path and picks a different route to send to them.

Direct Connect is primary, VPN is backup, both announce the same prefix. Which does AWS prefer? Direct Connect. For the same prefix length, the virtual private gateway prefers BGP routes learned over Direct Connect to those from Site-to-Site VPN.

References

Cao Le Nam Trung

Cao Le Nam Trung

Cloud & Network Engineer · TrungCLN

Designs and runs AWS infrastructure, hybrid networking (VPN, BGP) and cloud security. Every guide on this site is built and run for real before it is written.

LinkedIn YouTube Facebook

Related guides