Essay · Home lab field notes

Turning apartment Wi-Fi into a site-to-site VPN

A Raspberry Pi, WireGuard, and one mildly hostile captive portal walk into an apartment network.

My new apartment came with “free internet,” a phrase that can mean anything from pleasant surprise to the router is now your landlord. In this case the line was stable—roughly 100 Mbps with a 5 ms ping—but the network still had two awkward properties: every new device met a captive portal, and the building shared one public IP address.

I wanted machines without browsers, including Raspberry Pis and VMs, to get online without a ceremonial login. I also wanted their traffic encrypted across infrastructure I did not control. The answer was a Raspberry Pi router with a permanent WireGuard tunnel back to my family home.

A shared building connection feeds a wall router with captive-portal authentication, leaving headless tenant devices unable to complete the login.

What the apartment network was doing #

Fiber reached the building, then Ethernet ran from the shared equipment to each apartment. A wall-mounted Wi-Fi router provided the last hop. Because the whole building shared a public address, inbound ports and a dedicated global address were unavailable. Tunneling can work around that; the more immediate nuisance was authentication.

Every device had to visit a captive portal and sign in before it could reach the WAN. Fine for a phone. Less charming for a headless VM. The alternatives were to proxy a browser through the machine or ask the operator to whitelist its MAC address—which is especially silly for disposable VMs whose MAC addresses change routinely.

The security model was acceptable for ordinary use: most traffic is HTTPS and client isolation should prevent tenants talking to one another. Still, anyone with access to the shared Ethernet equipment occupies a privileged position, and the router credentials were printed inside the room. I preferred to own the trust boundary.

Put the boundary on a Raspberry Pi #

I used a Raspberry Pi 4 and a USB Ethernet adapter. A router needs at least two interfaces: one facing the apartment network and one facing my devices. The Pi’s built-in port alone was therefore one port short of a party.

A Raspberry Pi with its Ethernet connections.

Ubuntu was the pragmatic OS choice. OpenWrt is excellent if you want a router-style web UI; here I wanted familiar Linux tools. I assigned 192.168.185.0/24 to the LAN side and 192.168.185.1 to the Pi:

enx7403bd7f2042: # USB Ethernet, LAN side
  dhcp4: no
  addresses:
    - 192.168.185.1/24
  nameservers:
    addresses: [1.1.1.1]

The WAN side received an address over DHCP. To satisfy the captive portal once, I opened a SOCKS proxy from my laptop through the Pi:

ssh -D 1070 [email protected]

Pointing the browser’s SOCKS v5 setting at localhost:1070 made the portal see traffic from the Pi. One login later, the router was online.

Devices on 192.168.185.0/24 use the Pi at 192.168.185.1 as gateway. WireGuard crosses the apartment WAN to the family-home endpoint and then the internet.

Route everything through WireGuard #

WireGuard exposed wg0. Masquerading and forwarding moved LAN traffic into it:

sudo iptables -t nat -A POSTROUTING -o wg0 -j MASQUERADE
sudo iptables -A FORWARD -i enx7403bd7f2042 -o wg0 -j ACCEPT

Enable net.ipv4.ip_forward=1 in /etc/sysctl.conf, then apply it with sudo sysctl -p. I first persisted the rules with iptables-persistent, but later moved them into WireGuard’s PostUp and PostDown hooks. That makes the behavior explicit: when the tunnel is up, route through wg0; when it is down, restore the normal WAN route. State coupled to the lifecycle that owns it is generally less haunted.

Give clients addresses automatically #

Static addresses proved the path worked, but assigning them by hand is not a hobby I recommend. ISC DHCP reached end of maintenance in 2022, so I used Kea:

{
  "Dhcp4": {
    "interfaces-config": { "interfaces": ["enx7403bd7f2042"] },
    "subnet4": [
      {
        "subnet": "192.168.185.0/24",
        "pools": [{ "pool": "192.168.185.100 - 192.168.185.200" }],
        "option-data": [
          { "name": "domain-name-servers", "data": "1.1.1.1, 1.0.0.1" },
          { "name": "routers", "data": "192.168.185.1" }
        ]
      }
    ]
  }
}

I used a separate Wi-Fi access point in bridge mode rather than making the Pi carry that load too.

Performance, and the MTU-shaped pothole #

The source screenshots show 242.64 Mbps down, 320.52 Mbps up, and a 4 ms ping without WireGuard. Through the tunnel they show 58.84 Mbps down, 104.61 Mbps up, and 15 ms. The earlier 5 ms baseline in the narrative is a separate observation; the chart below transcribes the screenshots.

Source measurements: direct download/upload 242.64/320.52 Mbps and 4 ms ping; tunneled download/upload 58.84/104.61 Mbps and 15 ms ping. These are not new measurements.

This is an end-to-end comparison of two different paths, not an isolated measurement of WireGuard overhead. The remote internet connection, routing, Pi CPU, USB Ethernet, and encryption can all constrain throughput. One speed test cannot tell us which resource saturated.

Some sites also stalled, Netflix became glacial, certain CDN images vanished, and IMAP misbehaved. Those symptoms pointed to packet loss caused by an unsuitable MTU. Setting WireGuard’s MTU to 1400 fixed them.

The finished box makes any attached device behave as though it were on my home network—without installing WireGuard or negotiating the captive portal on every toaster. More usefully, the same Pi can travel. Plug it into another network and the trusted side of the setup comes with it.

Before treating this as a security boundary #

The source configuration demonstrates routing, not a complete firewall policy. In particular, restoring the normal WAN route when the tunnel goes down is fail-open: connectivity survives, but traffic may no longer traverse the trusted endpoint. If the requirement is “never send tenant traffic outside the tunnel,” enforce a fail-closed forwarding policy and test it by stopping WireGuard while a client has active connections.

Test DNS and IPv6 separately. An IPv4 tunnel and an IPv4 forwarding rule do not automatically cover IPv6 traffic, and a resolver reachable outside the tunnel can leak queries even when application traffic takes the intended path. Keep the WireGuard endpoint reachable over the physical WAN without accidentally routing the tunnel's own transport back into itself.

Finally, MTU 1400 is a result from this installation, not a universal constant. Encapsulation reduces the payload that fits on the path. Small pings succeeding while large transfers stall is a useful clue, but check packet sizes, ICMP Packet Too Big delivery, and path-MTU discovery before copying the number. The useful artifact is the diagnosis and a repeatable failure test, not just the setting that happened to work.

Related articles