Teng Li · ML Engineer

Networking field notes

How Does the VPN Get Out?

If a VPN carries all my internet traffic, what carries the VPN?

My mental model of a VPN used to be simple: switch it on, and my traffic goes through another machine before reaching a website.

Then, while configuring OpenWrt, I ran into something confusing. I could reach the remote machine, but traffic I asked it to forward still failed.

I realized that “the VPN is connected” only told half the story.

On this page

01Your Wi-Fi is still doing the work

Let's call my laptop A and a remote VPN server B.

Without a VPN, a simplified trip to a website looks like this:

Laptop A → Wi-Fi → home router → internet → website

After configuring my internet traffic to go through B, the trip becomes:

Laptop A → Wi-Fi → home router → internet → B → website

The Wi-Fi, router, and internet provider are still doing their jobs. The difference is that the data reaches B first. B then passes it on to the website.

A VPN does not create another internet. It uses the network I already have.

02Put the original letter inside another envelope

Computers organize network data into packets. For now, think of a packet as a letter with a delivery address.

When I visit a website, the original letter says:

To: the website
Contents: data for the website

A VPN such as WireGuard encrypts that original packet, then wraps it in a new packet addressed to B. WireGuard calls this encapsulation: it carries IP packets over UDP. Its conceptual overview describes the mechanism.

The outer packet is addressed to VPN server B. Its encrypted payload contains the original packet, which is still addressed to the website.
01The outer address gets the packet to B. The encrypted original still names the website. Full-size ↗

The website's address has not been erased. It is still inside. There is now another address on the outside saying, in effect, “take this to B first.”

The existing network delivers the outer packet to B. B opens it, decrypts the original packet, sees that the final recipient is the website, and forwards it.

That is the tunnel in this example: wrap at one end, carry over an existing network, unwrap at the other. There is no dedicated pipe dug through the internet.

03But which way does the new envelope go?

To send ordinary internet traffic through a VPN, the laptop needs an instruction roughly like this:

Send internet-bound packets to the VPN.

The rules a computer uses to decide where a packet goes are called routes.

The original packet is addressed to the website. Sending it into the VPN is exactly what I want.

But the VPN then produces a new packet, addressed to B. That new packet needs a routing decision too.

What if the same rule sends it straight back into the same VPN?

An incorrect route sends the newly generated outer packet back into the same VPN, producing another layer of wrapping instead of delivering it to B.
02An incorrect route sends the transport packet back into the VPN that generated it. Full-size ↗

The letter that should be on its way keeps returning to the wrapping desk.

This is a circular dependency: I need packets to reach B for the tunnel to work, but I am asking that same tunnel to carry the packets that make it work.

04Leave a way out for the VPN's own packets

One understandable solution is a separate route for B's underlying network address:

Ordinary internet packets → the VPN
Outer transport packets addressed to B → the original network

The two stages of the same request can now make different choices. The original packet enters the VPN for wrapping. The resulting outer packet takes the existing network path to B.

Inside laptop A, the original packet is encrypted and wrapped. A route for B sends the outer packet through Wi-Fi and the existing network. B unwraps it and forwards the original packet to the website.
03Two routing decisions: the original packet enters the VPN; the outer packet takes the existing network to B. Full-size ↗

Software can also mark the transport packets it generates and use routing rules that treat those marked packets differently. WireGuard's routing guide shows endpoint routes and this marking approach. Implementations vary; the requirement is that the packets carrying the tunnel have a usable way out.

B receives the outer packet, unwraps it, and sends the original packet onward.

05Reaching B is different from asking B to forward

That brings me back to the OpenWrt problem.

An SSH connection to B asks B itself to provide a service. Once the packet reaches B and is handed to its SSH service, it has reached its destination.

Using B to visit a website asks B to keep delivering the packet:

SSH to B:
A → B → B's own SSH service

Internet access through B:
A → B → B's forwarding rules → website

The second path has another leg, with forwarding rules that must allow it. In Tailscale, using a device to forward public internet traffic this way is the exit-node feature.

My OpenWrt incident involved the firewall configuration for that forwarding path. Reaching the machine did not establish that it could forward my traffic.

It also explains why SSH can remain available during some forwarding failures, letting me log in and repair them. That is conditional. If the machine loses power or its underlying network connection fails, SSH can disappear too.

The next time a VPN says “connected” but does not work, I will split the question in two:

I used to stare at the word “connected.” Now I want to draw where the packet actually got to.

← All writing