VPN to your home network: reach the NAS, cameras and PC from anywhere

To get into your home network from outside, run a VPN server at home, on the router, a Raspberry Pi or a computer that stays on, and connect to it from your phone or laptop. WireGuard is the usual choice: it needs a public IPv4 address at home, or a name that follows it, and one forwarded UDP port. If the provider keeps you behind CGNAT, put a small VPS in the middle or use a mesh network. AllowedIPs in the device's file decides whether only the home network goes through the tunnel or all your traffic.

Updated

AllowedIPs calculator: the whole internet except what you pick

Your home server's file in Veli. Veli connects to a WireGuard server at home like to any other: drop its .conf into Profiles → Add, or scan its QR code on Android.

Download Veli for free
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. 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. 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. 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. 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. 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.

The device's file, home network only
[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 = 25

DNS = 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/24

    What goes through homeOnly traffic to home devices

    When it fitsEveryday access to the NAS and cameras; sites go as usual

  • 192.168.1.20/32

    What goes through homeOne device

    When it fitsOnly the NAS, nothing else at home

  • 0.0.0.0/0, ::/0

    What 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.

Windows: PowerShell
Test-NetConnection 192.168.1.20 -Port 445
Find-NetRoute -RemoteIPAddress 192.168.1.20 | Select-Object InterfaceAlias

445 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.

macOS: Terminal
route -n get 192.168.1.20
nc -vz -w 3 192.168.1.20 445

interface: should be utunN.

Linux: Terminal
ip route get 192.168.1.20
nc -vz -w 3 192.168.1.20 445

After 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 show on the server shows latest handshake

  • Works 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 doip_forward=1, the masquerade line, or a static route on the router

  • Works 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 doDNS = with the router's address, or use addresses

  • Everything is slow while connected

    CauseAllowedIPs is 0.0.0.0/0, and the home upload is slow

    What to doList only the home network

Sources

How we write and check

In Veli

Your home server's file in Veli

Veli connects to a WireGuard server at home like to any other: drop its .conf into Profiles → Add, or scan its QR code on Android. On Windows, macOS and Linux the app follows the file's AllowedIPs as wg-quick does, so with only the home network listed, only that goes into the tunnel. A file with 0.0.0.0/0 can be narrowed in the app: Apps and sites → “Through the VPN only…” with 192.168.1.0/24 in “Sites and IP addresses”, for this profile alone through “Apps and sites for this profile” in its “⋯” menu.

On Android the app doesn't read AllowedIPs: Apps and sites decides what goes into the tunnel, and the “Local network” switch in Settings → Protection, on from the start, sends private addresses such as 192.168.x.x around it. So on a phone open the profile's menu → “Apps and sites for this profile” → “Through the VPN only…” and add the home network. Two more things: the kill switch (Settings → Security on a computer, off after install) closes everything outside the tunnel, the internet too when a profile carries only home; and “Your own server” is made for rented servers, where what it installs keeps devices off the networks around the server, so the home server is set up by hand or on the router.

FAQ

How do I access my home network remotely?

Run a VPN server at home, on the router, a Raspberry Pi or an always-on computer, forward its one UDP port, and connect to it from your phone or laptop. Then open home devices by their local addresses.

Do I need a static IP to VPN into my home network?

No, a public one is enough: dynamic DNS gives it a name that follows every change. A static address inside the provider's network, behind CGNAT, doesn't help.

Can I VPN into my home network behind CGNAT?

Not directly. Ask the provider for a public IPv4, use IPv6, put a VPS in the middle, or use a mesh network that gets through NAT by itself.

Is a VPN safer than port forwarding for a NAS or cameras?

Yes. Instead of the web pages of every device, one VPN port is open, and it doesn't answer anyone without a key.

Will all my internet go through home?

Only if AllowedIPs on the device is 0.0.0.0/0. With just the home network listed, only traffic to home devices takes the tunnel.

Can I use my router's built-in VPN server?

Yes, if it has one: the router already holds the public address, so it is the simplest place. Check that it exports WireGuard or OpenVPN files that a client app can import.

The home network in, the rest as usual

Veli is a free client for Windows, macOS, Linux and Android. It opens your home WireGuard file and, if you choose, sends only the home network through it.