On this page
Where to run the server
The server has to stay on and sit in the home network, next to the devices you want to reach. WireGuard is the usual pick: it is light enough for a router and opens a single UDP port. OpenVPN is the other option, mostly when a router offers nothing else.
The router
GoodIt is always on and already holds the public address, so nothing has to be forwarded to another box. OpenWrt has WireGuard as packages, with a page in its web interface (LuCI); many stock firmwares have a WireGuard or OpenVPN server in their VPN section
Watch outA weak processor caps the speed; menus and limits differ from model to model
A Raspberry Pi or a mini PC
GoodCheap to keep on, an ordinary Linux with the same files as on any server
Watch outNeeds a fixed local address and a forwarded port
A computer that stays on
GoodNo new hardware
Watch outSleep, updates and reboots take the VPN down with them
A VPS outside
GoodWorks when the home has no public IPv4
Watch outHome connects out to it; one more hop, and a machine you have to trust
What the home side needs
- 1
A public IPv4 address
With the VPN off, compare the WAN address on the router's status page with the one a “what is my IP” page shows. The same: good. Different, and especially anything from 100.64.0.0 to 100.127.255.255, the range reserved for carrier NAT: the address is shared, see the next section. A private WAN address can also mean a second router of your own in front.
- 2
A name that follows it
Home addresses change. Dynamic DNS, which most routers have on a DDNS page, keeps a name pointed at the current one. Write that name in Endpoint on your devices.
- 3
A fixed local address for the server
Reserve one in the router's DHCP, for example 192.168.1.10. Not needed if the router itself is the server.
- 4
One forwarded UDP port
External UDP 51820 to 192.168.1.10, UDP 51820. That is the only port: not the NAS's page, not a camera, not remote desktop.
- 5
A test from outside
Turn Wi-Fi off on the phone and connect over mobile data. From inside the home many routers don't let you reach their own public address, and the test fails though everything works.
No public IPv4: CGNAT
Behind CGNAT incoming connections stop at the provider's equipment, and no setting on your router changes that. Outgoing connections work, and every way around it is built on them.
- Ask the provider for a public IPv4 address. It is often a small paid option, and then everything above works as written.
- IPv6. If the provider gives real IPv6, the server can be reached at its IPv6 address from networks that have IPv6 too. Allow the port in the router's IPv6 firewall.
- A VPS in the middle. The home server connects out to a small VPS and keeps the path open with
PersistentKeepalive = 25; your phone connects to the same VPS and reaches home through it. Every packet makes a detour, and the VPS decrypts traffic on the way, so rent it yourself. - A mesh network such as Tailscale, NetBird or ZeroTier. Their apps get through NAT on both sides by themselves and fall back to relays when they can't. One device at home can open the whole home network to the others: Tailscale calls it a subnet router, and it lets you reach printers and cameras that can't run the app. You depend on their coordination server, or run your own.
Only the home network, or everything: AllowedIPs
AllowedIPs of the peer in a WireGuard file works as a routing table: what is listed goes into the tunnel, the rest goes the usual way. To reach home it is enough to list the home network and the tunnel's own network. In the examples the home network is 192.168.1.0/24, the tunnel 10.8.0.0/24, the server 192.168.1.10.
[Interface]
PrivateKey = DEVICE_PRIVATE_KEY
Address = 10.8.0.2/32
DNS = 192.168.1.1
[Peer]
PublicKey = SERVER_PUBLIC_KEY
Endpoint = home.example.net:51820
AllowedIPs = 10.8.0.0/24, 192.168.1.0/24
PersistentKeepalive = 25DNS = 192.168.1.1 makes the names your router knows work, such as the NAS's. Every name is then looked up at home, which is slower from far away; without the line, open home devices by their IP addresses.
10.8.0.0/24, 192.168.1.0/24What goes through homeOnly traffic to home devices
When it fitsEveryday access to the NAS and cameras; sites go as usual
192.168.1.20/32What goes through homeOne device
When it fitsOnly the NAS, nothing else at home
0.0.0.0/0, ::/0What goes through homeAll traffic
When it fitsPublic Wi-Fi: sites see your home address, and the speed is your home upload
- Home devices have to answer the tunnel. A NAS that gets a packet from 10.8.0.2 sends the reply to the router, which knows nothing about the tunnel. Either the server masquerades tunnel traffic as its own address (the NAT line in PostUp, as in the guides on a WireGuard server and a Raspberry Pi), or the router gets a static route: 10.8.0.0/24 via 192.168.1.10.
- Forwarding on the server.
net.ipv4.ip_forward=1, or only the server itself answers. - Different numbers at home and away. If a café's Wi-Fi is also 192.168.1.0/24, the device can't tell which 192.168.1.20 you mean. Moving the home network to something rarer, such as 192.168.57.0/24, saves trouble for years.
- On the server each device's AllowedIPs is its own tunnel address,
10.8.0.2/32: that is how the server knows which key may send from which address. - Devices that find each other by broadcast, like some camera apps and media players, won't see anything through WireGuard: it carries IP packets between addresses, not the home network's broadcasts. Add such a device by its IP address.
Check the way to a home device
With the tunnel up and away from home, put your device's address in place of 192.168.1.20. It is in the router's list of devices.
Test-NetConnection 192.168.1.20 -Port 445
Find-NetRoute -RemoteIPAddress 192.168.1.20 | Select-Object InterfaceAlias445 is a shared folder, 80 or 443 a web page, 554 a camera's RTSP stream, 8123 Home Assistant. TcpTestSucceeded : True means the device answers, and InterfaceAlias should be the tunnel.
route -n get 192.168.1.20
nc -vz -w 3 192.168.1.20 445interface: should be utunN.
ip route get 192.168.1.20
nc -vz -w 3 192.168.1.20 445After dev comes the tunnel's name.
Keep it safe
- One open port, the VPN's. Don't forward the NAS's web page, a camera or remote desktop to the internet: those are what scanners look for. Behind the VPN they need no open port at all.
- WireGuard keeps quiet. Its server doesn't answer packets without a valid key, so a scan of the port finds nothing there.
- A key for each device. If a phone is lost, delete its
[Peer]on the server, and only that phone loses access. - Look at what is already open. Go through the router's port forwarding list and its UPnP table: a camera or a NAS may have opened a port for itself. Close what you didn't open.
- Shared access. If someone else gets a key, the server's firewall can let that peer reach one device rather than the whole home.
- Update the router and the server. The VPN is now the door into the house.
It connects, but home doesn't answer
No handshake at all
CauseThe port isn't forwarded, the address changed, or CGNAT
What to doCompare the WAN address again; test from mobile data;
wg showon the server showslatest handshakeWorks at home, not outside
CauseEndpoint holds the local address
What to doPut the public address or the DDNS name there
A handshake, the server answers, other devices don't
CauseNo forwarding or NAT on the server, or no route back
What to do
ip_forward=1, the masquerade line, or a static route on the routerWorks on mobile data, not from a friend's Wi-Fi
CauseBoth networks use the same addresses
What to doRenumber the home network
The NAS opens by IP, not by name
CauseThe name is known only to the home DNS
What to do
DNS =with the router's address, or use addressesEverything is slow while connected
CauseAllowedIPs is 0.0.0.0/0, and the home upload is slow
What to doList only the home network