·8 min read·Updated Nov 29, 2026

Self-Host Behind CGNAT: Tunnel a Home Server Through a VPS

Behind CGNAT or a blocked port? Tunnel a home server through a VPS with WireGuard: nftables or nginx forwarding, real client IPs, and what the VPS sees.

If your ISP puts you behind carrier-grade NAT (CGNAT) or blocks inbound ports, you can still self-host from home. Rent a small VPS with a public IPv4 address. Have your home server dial out to it over WireGuard, then forward public traffic from the VPS down the tunnel. Because the home machine opens the connection, your router never needs an open port, and visitors only ever see the VPS's IP.

This guide covers both forwarding methods: one where TLS stays end-to-end and one where the VPS terminates it. It also shows how to keep real client IPs and what each part of the setup can still see. If you're still deciding whether to host at home at all, read Home Server vs. No-KYC VPS: Which Is Actually More Private? first.

How to tell if you're actually behind CGNAT

Compare the WAN address on your router's status page with what the internet sees:

curl -4 https://ifconfig.me

If the router shows an address in 100.64.0.0/10 (RFC 6598 shared address space), or any private range that doesn't match the result above, you're behind CGNAT. Port forwarding on your router can't help, because the NAT that blocks you is on the ISP's side. Some ISPs will give you a public IPv4 address if you ask, sometimes for a fee. Ask them first, because it's simpler than anything below.

The architecture in one paragraph

The VPS runs WireGuard on a fixed UDP port with the tunnel address 10.8.0.1. The home server is a WireGuard peer at 10.8.0.2. It connects outbound to the VPS and sends a keepalive packet every 25 seconds so the CGNAT mapping stays open. Public traffic hits the VPS on ports 80 and 443, and the VPS forwards it to 10.8.0.2. The home server only routes the tunnel subnet through WireGuard, so the rest of your household traffic is unaffected.

This assumes Debian 12 or Ubuntu 22.04/24.04 on both ends and IPv4 only. For a deeper walkthrough of WireGuard itself (key handling, MTU and leak testing), see the self-hosted WireGuard VPN guide. This article only covers what's different for a reverse tunnel.

Step 1: WireGuard on the VPS

sudo apt install wireguard
wg genkey | sudo tee /etc/wireguard/vps.key | wg pubkey | sudo tee /etc/wireguard/vps.pub
sudo chmod 600 /etc/wireguard/vps.key

/etc/wireguard/wg0.conf on the VPS:

[Interface]
Address = 10.8.0.1/24
ListenPort = 51820
PrivateKey = <contents of vps.key>

[Peer]
# home server
PublicKey = <home public key>
AllowedIPs = 10.8.0.2/32

There's no Endpoint for the home peer. The VPS doesn't know your home address in advance and learns it when the home side connects. Enable forwarding and start the tunnel:

echo 'net.ipv4.ip_forward=1' | sudo tee /etc/sysctl.d/99-forward.conf
sudo sysctl --system
sudo systemctl enable --now wg-quick@wg0

Allow UDP 51820 in your firewall. If you use the default-drop ruleset from our nftables baseline guide, add the port to the input chain before you reload.

Step 2: WireGuard on the home server

Generate a key pair the same way, then create /etc/wireguard/wg0.conf:

[Interface]
Address = 10.8.0.2/24
PrivateKey = <home private key>

[Peer]
PublicKey = <vps public key>
Endpoint = <VPS public IPv4>:51820
AllowedIPs = 10.8.0.1/32
PersistentKeepalive = 25

Two lines matter here:

  • AllowedIPs = 10.8.0.1/32 keeps the tunnel narrow. If you set 0.0.0.0/0, all of your home server's outbound traffic would exit through the VPS. That's a different project with different routing problems.
  • PersistentKeepalive = 25 is required behind CGNAT. Without it, the ISP's NAT drops the idle mapping and the VPS can't reach you until the home side sends something again.

Bring it up and verify from both ends:

sudo systemctl enable --now wg-quick@wg0
sudo wg show          # look for a recent "latest handshake"
ping -c3 10.8.0.1     # from home

Step 3: Choose how to forward traffic

This decision determines what the VPS can see.

Option A: Pass-through with TLS ending at home (recommended for privacy)

The VPS forwards raw TCP and never holds your TLS certificate or private key, so it only relays encrypted bytes. The obvious tool is nftables DNAT, but it has a catch. You need masquerade (oifname "wg0" masquerade) so replies come back through the tunnel, and with masquerade every visitor appears to come from 10.8.0.1. That breaks rate limiting, fail2ban and any log you care about.

nginx's stream module solves this with the PROXY protocol, which passes the real client address to the home server ahead of the encrypted stream. On the VPS (install libnginx-mod-stream if your nginx package doesn't already include it), add this at the top level of /etc/nginx/nginx.conf, outside the http {} block:

stream {
    server {
        listen 443;
        proxy_pass 10.8.0.2:443;
        proxy_protocol on;
    }
    server {
        listen 80;
        proxy_pass 10.8.0.2:80;
        proxy_protocol on;
    }
}

On the home server's nginx, accept the PROXY header only from the tunnel:

server {
    listen 443 ssl proxy_protocol;
    server_name example.com;
    set_real_ip_from 10.8.0.1;
    real_ip_header proxy_protocol;
    # ssl_certificate, ssl_certificate_key, locations...
}

Add the same proxy_protocol parameter to your port-80 listener. Once a listener expects PROXY protocol, it rejects plain connections, so a LAN client that connects directly to that port will fail. If you need LAN access, add a separate listener.

Certificates live at home. Let's Encrypt HTTP-01 validation still works because port 80 is forwarded. DNS-01 avoids that dependency.

Option B: Reverse proxy terminating TLS on the VPS

Here Caddy or nginx on the VPS gets the certificate and proxies plain HTTP over the tunnel to 10.8.0.2. It's simpler to set up, X-Forwarded-For handles client IPs, and you can cache or rate-limit at the edge. The trade-off is that the VPS sees decrypted requests, including cookies, form posts and session tokens. The WireGuard hop is encrypted, but the VPS itself is now in the plaintext path.

Use Option B for low-sensitivity sites or when you need HTTP-layer features at the edge. Use Option A for anything with logins, private data or a password manager.

Step 4: Verify from outside

Point your domain's A record at the VPS, then test from a network that isn't your home connection, such as a phone on mobile data:

curl -sI https://example.com

Then check the home server's access log. You should see the visitor's real IP, not 10.8.0.1. If you see 10.8.0.1, the PROXY protocol settings don't match on the two ends. Finally, confirm your home IP doesn't appear anywhere public. Check the DNS records, the certificate's SAN list and any page that echoes server headers.

Troubleshooting

  • The tunnel works, then stops after a few minutes. PersistentKeepalive is missing or set too high for your ISP's NAT timeout. Try 25 or lower.
  • Small requests work but large pages hang. This is usually an MTU problem. WireGuard's default of 1420 can be too high on some CGNAT or PPPoE paths. Set MTU = 1380 in both [Interface] sections and test again.
  • The VPS can ping 10.8.0.2 but nginx gets "connection refused." The home service is listening only on 127.0.0.1 or the LAN address, or the home firewall blocks wg0.
  • Every client shows up as 10.8.0.1. You're using DNAT with masquerade, or set_real_ip_from is missing. See Option A.
  • Docker at home ignores your firewall. Published container ports bypass normal INPUT rules. Bind containers to 10.8.0.2 or 127.0.0.1 explicitly.

What this setup hides, and what it doesn't

The tunnel moves your public face from your home IP to the VPS IP. Each party still sees something:

  • Visitors and scanners see only the VPS address. They don't see your home IP unless something else leaks it.
  • The VPS host can see your home IP as the WireGuard endpoint, along with traffic volume and timing. With Option B, it could also see request content. Account-level privacy, such as signing up without an email or paying in crypto, doesn't change this network-level fact. If you need that link broken too, our article on anonymous VPS access explains the options and their costs.
  • Your ISP sees encrypted UDP going to one IP. It can't see the content, but the connection pattern is visible.
  • The home server itself can still leak your IP through anything that connects outbound: link previews, webhooks, federation, outgoing mail or update checks to third parties. Those requests leave through your home connection, not the tunnel. Most of the leak paths in our guide to hiding an origin IP behind a proxy apply here too.

If the VPS is ever seized or imaged, the WireGuard config and connection state point to your home connection. Treat the tunnel as protection from casual exposure and scanning, not as anonymity.

Practical limits

  • Throughput is capped by your home upload speed. The VPS port is rarely the bottleneck. Asymmetric residential lines often top out at a fraction of their download speed.
  • Traffic crosses the VPS twice, once from the visitor and once through the tunnel. Depending on how your host meters traffic, a 50 GB month of serving can count close to double. Measure it with vnstat on the VPS for a few weeks before you assume a small allowance is enough.
  • Latency stacks up. Visitors pay the round trip to the VPS plus the VPS-to-home leg. Choose a VPS location near both your audience and yourself.
  • Your uptime is still home uptime. Power cuts, router reboots and ISP outages take the site down. The VPS can only show an error page while that happens.

How it compares to Cloudflare Tunnel and similar services

Managed tunnels like Cloudflare Tunnel or Tailscale Funnel solve the same CGNAT problem with less setup and no server to maintain. The trade-offs are an account tied to an identity provider, TLS terminated on infrastructure you don't control, and the service's terms deciding what you can serve. A VPS tunnel costs a few euros a month and some admin time. In return, you choose where TLS ends and who holds the relay.

Choosing a VPS for the relay

A forwarding relay needs very little: a dedicated public IPv4 address, full root on KVM so you can load WireGuard and tune nftables, and enough monthly traffic for your realistic double-counted usage. 1 vCPU and 2 GB of RAM is plenty for WireGuard and nginx stream. IronBalkans' entry plan (Iron 1, listed at €7.99/mo with 1 TB of traffic at the time of writing; check current pricing before you pay) covers that profile. It's IPv4-only, which doesn't matter for this setup. You can sign up without an email and pay in Monero, Bitcoin or Litecoin. Just remember the point above: the relay host sees your home endpoint whatever name is on the account.

Written by IronBalkans. Last reviewed Nov 29, 2026.