Most self-hosters eventually want to reach their home lab from outside the house: a dashboard, a file share, a Git server, or a monitoring stack. The traditional answer is to port-forward each service to the internet. Every forwarded port is a service that automated scanners can find, fingerprint, and attack. Each one also needs its own patching, TLS setup, and login hardening.
This guide takes a different approach. You will run WireGuard, a small and modern VPN, on your home server. Your devices connect to it over an encrypted tunnel, and once connected they reach internal services as if they were on the local network. Your services never touch the internet directly. The only thing reachable from outside is the WireGuard UDP port itself.
One precision point matters up front. “No open ports” really means “no open service ports.” WireGuard still needs one inbound UDP port reachable on a machine with a public address. If your home connection does not allow that, this guide includes a relay pattern using a small VPS. The goal is one hardened entry point, not a fleet of exposed services.
This guide is for developers, sysadmins, and home-lab builders who are comfortable with a Linux shell and editing configuration files. The examples assume Debian or Ubuntu on the server and a Linux, macOS, or Windows client.
Before you start
- A home server running Debian or Ubuntu with a sudo-capable user and SSH access on the local network.
- A public IPv4 address on your home router, or a small VPS with a public address if you use the relay pattern in step 8.
- Access to your router’s admin page, so you can forward one UDP port if you are not using a relay.
- A dynamic DNS hostname or other stable name for your home IP, such as YOUR_DOMAIN. Your ISP may change your address, and clients need a name to connect to.
- A device you can use as a test client, ideally one that is not on your home network while you test, such as a phone on cellular data.
- Console or out-of-band access to the server (a monitor, a KVM, or a hosting provider’s web console) in case a firewall change locks you out of SSH.
1. Install WireGuard and check your kernel
Modern Linux kernels include WireGuard. You only need the user-space tools. On Debian or Ubuntu:
sudo apt update
sudo apt install -y wireguard wireguard-tools
sudo modprobe wireguard
lsmod | grep wireguardIf lsmod shows a wireguard module, the kernel side is ready. If you are on an older kernel where the module is missing, install the matching kernel headers and update the system before continuing.
2. Generate keys on the server and each client
WireGuard identifies peers by public key. Each machine generates its own private key, which never leaves that machine, and derives a public key to share. Restrict file permissions while you generate them:
sudo -i
umask 077
wg genkey | tee /etc/wireguard/server_private.key | wg pubkey > /etc/wireguard/server_public.key
cat /etc/wireguard/server_public.keyRepeat the same pattern on each client, using a name such as laptop_private.key so the files stay organized. Keep private keys out of version control, chat messages, and shared notes. You only ever copy public keys between machines.
3. Write the server configuration
Create /etc/wireguard/wg0.conf on the server. This example uses the private range 10.8.0.0/24 for the tunnel. Replace the placeholders with your real keys. The server’s private key is read from the file you created, so paste its contents into the configuration:
[Interface]
Address = 10.8.0.1/24
ListenPort = 51820
PrivateKey = SERVER_PRIVATE_KEY
[Peer]
# Laptop
PublicKey = LAPTOP_PUBLIC_KEY
AllowedIPs = 10.8.0.2/32Two details matter here. The AllowedIPs value on a server peer is the set of addresses that peer is allowed to use, so each client gets a single /32 address. Also, do not add PostUp firewall rules that you do not understand. Manage the firewall directly, as described in step 6.
Lock down the file so only root can read it:
sudo chmod 600 /etc/wireguard/wg0.conf
sudo chown root:root /etc/wireguard/wg0.conf4. Write the client configuration
On each client, create a config file such as wg-home.conf. The client’s AllowedIPs controls what traffic goes through the tunnel. Listing only your tunnel and home LAN subnets creates a split tunnel, so ordinary web traffic does not pass through your home connection. Replace 192.168.1.0/24 with your actual LAN subnet:
[Interface]
Address = 10.8.0.2/32
PrivateKey = LAPTOP_PRIVATE_KEY
[Peer]
PublicKey = SERVER_PUBLIC_KEY
Endpoint = YOUR_DOMAIN:51820
AllowedIPs = 10.8.0.0/24, 192.168.1.0/24
PersistentKeepalive = 25The PersistentKeepalive = 25 line sends a small packet every 25 seconds. Clients behind NAT need this to keep their mapping open so the server can reach them. Do not set AllowedIPs = 0.0.0.0/0 unless you deliberately want all client traffic routed through home. That is a full-tunnel configuration and a different decision.
Add the client to the server by appending a [Peer] block for each client’s public key, as shown in step 3, then reload the interface in step 5.
5. Enable IP forwarding and start the tunnel
To let clients reach devices on your home LAN through the server, the server must forward packets between interfaces. Enable forwarding persistently:
echo 'net.ipv4.ip_forward=1' | sudo tee /etc/sysctl.d/99-wireguard.conf
sudo sysctl --systemNext, bring up the interface and enable it at boot:
sudo systemctl enable --now wg-quick@wg0
sudo wg showThe output of wg show should list your interface, its listening port, and each peer. Before any client connects, the peer will show no handshake. That is normal.
6. Build a firewall that exposes only the VPN endpoint
This is the step that makes the setup worth doing. The policy is simple: deny all inbound traffic by default, allow the WireGuard UDP port from anywhere, and allow SSH only from inside the tunnel once everything works. The example uses ufw, which wraps nftables on current Debian and Ubuntu releases.
Important: allow SSH on your current connection before you enable the firewall, or you may lock yourself out. If you have not confirmed the tunnel works yet, keep SSH open for now and tighten it later.
sudo ufw default deny incoming
sudo ufw default allow outgoing
sudo ufw allow OpenSSH
sudo ufw allow 51820/udp
sudo ufw route allow in on wg0 out on YOUR_LAN_INTERFACE
sudo ufw enable
sudo ufw status verboseThe ufw route rule allows forwarded traffic from the tunnel to your LAN. Without it, clients connect to the server but cannot reach home devices.
Once you have confirmed the tunnel works (see the verification section), restrict SSH so it only accepts connections from the VPN subnet:
sudo ufw delete allow OpenSSH
sudo ufw allow from 10.8.0.0/24 to any port 22 proto tcp
sudo ufw status numberedTest from a second session before closing your first one. If you have a console, keep it available until you are sure.
7. Connect a client and confirm routing
On the client, import wg-home.conf. On Linux, the same tooling works:
sudo wg-quick up ./wg-home.conf
ping -c 3 10.8.0.1
ping -c 3 192.168.1.10Replace 192.168.1.10 with a device on your LAN, such as a NAS or a web dashboard host. If the tunnel address answers but LAN addresses do not, revisit the AllowedIPs line on the client and the forwarding rules on the server.
8. Optional: use a VPS relay when you cannot open a port at home
Some residential connections use carrier-grade NAT or block inbound traffic, so no router rule will make the home server reachable. In that case, run WireGuard on a small VPS with a public address and have the home server connect outward to it. Outbound connections almost always work.
On the VPS, the home server is a peer with a public key and an AllowedIPs value that covers its tunnel address and LAN. On the home server, the VPS is the peer, with Endpoint pointing to the VPS and PersistentKeepalive = 25 set, so the home side keeps the NAT mapping alive. Your laptop then connects to the VPS, which forwards traffic to the home network. Enable IP forwarding on the VPS in the same way as in step 5, and apply the same ufw policy: deny inbound by default and allow only the WireGuard port.
The tradeoff is that the VPS sees traffic metadata for your tunnel and becomes a dependency. Treat it as a hardened gateway, not a general-purpose server, and do not run application services on it.
9. Set up a key rotation routine
WireGuard does not expire keys on its own. Rotate them on a schedule, and immediately after a device is lost, reinstalled, or shared. A practical routine is to rotate client keys once or twice a year and whenever a device changes hands.
To rotate a client key, generate a new pair on the client, replace the public key in the server’s [Peer] block, and reload the interface without dropping other peers:
umask 077
wg genkey | tee new_laptop_private.key | wg pubkey > new_laptop_public.key
# Update PublicKey in the [Peer] block of /etc/wireguard/wg0.conf on the server, then:
sudo wg-quick strip wg0 > /tmp/wg0-stripped.conf
sudo wg syncconf wg0 /tmp/wg0-stripped.conf
shred -u /tmp/wg0-stripped.confThe wg-quick strip command removes wg-quick-only directives such as Address and PostUp, leaving a file that wg syncconf can apply live. Update the client’s PrivateKey to the new key, then delete the old private key file. For a lost device, remove its [Peer] block entirely rather than rotating, so the old key stops working immediately.
Keep a simple record of which key belongs to which device and when it was issued. That makes revocation fast and avoids orphaned peers.
Verify it worked
Run these checks after setup and again after any firewall or key change.
- Handshake present. On the server, run
sudo wg show. Each active peer should show a “latest handshake” within the last few minutes while the client is connected. - Tunnel reachable. From the client,
ping 10.8.0.1should succeed, and a LAN service should load at its private address. - Only one port listening publicly. On the server, run
sudo ss -tulpn. Confirm that the WireGuard port is listening and that any service bound to 0.0.0.0 is one you intend to expose. Services you only want on the LAN should be bound to their LAN address or blocked by the firewall. - External scan. From a network outside your home, such as a phone on cellular data, scan your public address. Run
nmap -Pn -p- YOUR_PUBLIC_IPand expect no open TCP ports. Also runnmap -sU -p 51820 YOUR_PUBLIC_IP. WireGuard typically appears as open or filtered, not clearly open. This is expected, because WireGuard silently drops packets that do not carry a valid handshake, so scanners get no banner or response to fingerprint. - Firewall state. Run
sudo ufw status verboseand confirm the default policy is deny incoming and that SSH is restricted to 10.8.0.0/24.
Common mistakes
- Setting AllowedIPs to 0.0.0.0/0 by accident. This routes all client traffic through home and often breaks local network access. Use explicit subnets unless you want a full tunnel.
- Forgetting PersistentKeepalive behind NAT. Clients on mobile or home networks may connect once and then go quiet. Set the keepalive on any peer that sits behind NAT.
- Missing the ufw route rule or forwarding sysctl. The tunnel comes up, the server responds, but LAN devices are unreachable. Both settings are required for forwarding.
- Locking yourself out of SSH. Enable the firewall only after allowing SSH, and keep console access until the tunnel is verified.
- Exposing services you did not mean to expose. Many Docker images bind to 0.0.0.0 and can bypass ufw rules because Docker writes its own iptables rules. Check published ports with
sudo ss -tulpnand bind containers to specific addresses when needed. - Reusing one key pair everywhere. Each device should have its own key. A shared key makes revocation all-or-nothing.
- Copying private keys between machines. Generate keys where they will be used. Only public keys belong in peer blocks.
- Trusting the tunnel to replace authentication. A VPN controls who can reach the network, not what they can do once there. Keep strong authentication on your internal services, and do not assume every device on the tunnel is trusted.
Takeaway
WireGuard lets you reach a home lab from anywhere while exposing one UDP port instead of a set of web services. The durable parts are the habits: one key per device, a default-deny firewall, SSH limited to the tunnel, a scheduled key rotation, and a quick external scan to confirm nothing else is listening. If your network cannot accept inbound connections, a small relay gives you the same model with one outbound-initiated tunnel.
