A private network between my computers

Two Linux boxes, a Raspberry Pi, two phones and a tablet on one ZeroTier network: what runs over it, what broke, and the fallback to the home network when it is down.

The box I carry reaches the box at home over ZeroTier, tried first, and over the home network, tried second. A line underneath says two phones, a tablet and a Raspberry Pi are on the same network. The box I carry reaches the box at home over ZeroTier, tried first, and over the home network, tried second. A line underneath says two phones, a tablet and a Raspberry Pi are on the same network.

Six of my devices sit on one ZeroTier network: the two Linux boxes, a Raspberry Pi that never goes off, two phones and a tablet. Each has an address on it that stays the same wherever the device is, so ssh to the box at home is the same command from the next room as from anywhere else.

ZeroTier is peer to peer. When two members can reach each other directly the packets go straight between them, and with both boxes in the house the private network costs nothing I can measure:

$ ping -c 10 -i 0.3 -q HOME_BOX
10 packets transmitted, 10 received, 0% packet loss, time 2737ms
rtt min/avg/max/mdev = 0.537/0.719/0.963/0.136 ms

Why not forward a port

I don’t want sshd answering on my home address for every scanner to find, and the same goes for the desktops and the camera page. With ZeroTier a new device is one join and one approval from me, and the router isn’t involved.

Because members talk to each other directly, nothing depends on the Pi being up. When it’s down the cameras and the alerts stop, and the two boxes carry on reaching each other.

The cost is that membership is held by ZeroTier’s hosted controller, which is somebody else’s service and not something I can rebuild from my own repos.

What runs over it

Nearly everything between the two boxes: ssh, the heavy jobs the box I carry sends to the one at home, its nightly backup, which is a restic repository on the home box reached over sftp, and the hourly health checks, where each box reads the other’s last run. Syncthing uses it too, and the home network when both are on it.

The phones and the tablet use it for ssh from Termux, for the desktop, for the camera page on the Pi and for the alerts the Pi pushes through ntfy.

What went wrong

A newly joined phone lost its first pings to one box and then got 8 of 8. ZeroTier takes a moment to find a direct path.

The Pi once lost its path to a phone and didn’t get it back until ZeroTier was restarted. Its five-minute check now covers that: if a machine that’s always on answers on the home network and not over ZeroTier, it restarts ZeroTier, at most once an hour.

Android was the awkward member. It stops background apps to save battery, so ZeroTier and Termux are exempt from battery optimisation on all three devices, and one phone’s Android skin still stops ZeroTier from time to time. Android also allows one VPN at a time, so a phone running another VPN app is off the network until I switch.

Rebuilding a machine nearly cost it its place. A node’s identity lives in /var/lib/zerotier-one, and a fresh install makes a new one, with a new address that would need approving and then changing everywhere the old one is written down. When I reinstalled the home box I stopped the service, put the old identity back from the old disk and started it again. It came up as the same member on the same address, and nothing else had to change.

When it’s down

Most of my scripts reached the other box by its ZeroTier address only, so a stopped ZeroTier looked like a dead machine. The status and health checks now try ZeroTier with a five-second timeout, then the box’s name on the home network, and say that ZeroTier is down when they had to.

I proved it by stopping ZeroTier on the box I carry and running the status command. It reached the home box over the home network in 13 seconds and named ZeroTier as the cause. With ZeroTier and the home network both gone, each box works on its own until one of them comes back.

Featured projects

All projects

Latest writing

All writing