Back to blog

Self-Hosting Behind CGNAT: Why Port Forwarding Fails and What to Do Instead

October 2, 2026 5 min read

You set up Jellyfin, Home Assistant, or a WireGuard server at home. It works on your LAN. You forward the port on your router, test from your phone on mobile data, and nothing connects. Your config is probably fine. Your ISP probably isn't giving you a public IPv4 address.

What CGNAT is

IPv4 addresses ran out, so many ISPs put customers behind carrier-grade NAT: one shared public address for many households. Your router's WAN address isn't publicly routable. There's a second NAT you don't control between you and the internet, so an inbound connection to the shared public IP has no way to reach you, and a port forward on your own router can't change that.

It's common on mobile and 5G home internet, satellite, and a growing share of cable and fiber ISPs.

Check whether you're behind it

  1. Open your router's admin page and note the WAN / Internet IP.
  2. Look up your public IP from any "what is my IP" site.
  3. If they differ, you're behind another NAT. A WAN address in 100.64.0.0/10 (100.64.0.0 to 100.127.255.255) is the range reserved for CGNAT. A WAN address in 10.x, 172.16-31.x, or 192.168.x also means an upstream NAT.

If both addresses match, you have a real public IP, and the problem is a firewall rule or an ISP block on that port, not CGNAT.

Your options

  • Ask the ISP for a public IP. Sometimes free, sometimes a paid add-on. If it's cheap, this is the simplest fix.
  • IPv6. If your ISP gives you native IPv6, services can be reachable directly over it (behind a proper firewall). The catch is that the clients connecting also need IPv6, and many networks still don't have it.
  • Cloudflare Tunnel. Your server makes an outbound connection, so no public IP is needed. It suits web services. Your traffic passes through Cloudflare, and its rules on what you may proxy (large media in particular) have changed over time, so read the current terms first.
  • A mesh VPN like Tailscale. Works through NAT with relay fallback. It's excellent for reaching your own devices, and not designed for exposing a service to the public.
  • A relay on a VPS. What the rest of this post covers. It works for any TCP or UDP service, you control the path, and it costs a few dollars a month. The price is added latency and the VPS's bandwidth limits.

Rule of thumb: if only you and your own devices need access, you don't need to expose anything publicly. If other people need to reach it, use a tunnel for web services or a VPS relay for everything else.

How the relay works

Your home machine opens an outbound WireGuard connection to a VPS. Outbound traffic passes through CGNAT fine. A keepalive keeps the NAT mapping open. The VPS has a real public IP, so it can send traffic back down the tunnel to your home machine. There are two ways to use that.

Private access. Your laptop and phone also connect to the VPS's WireGuard network, and you reach the home machine at its tunnel address. Nothing is exposed to the internet. This should be your default.

Public exposure. The VPS accepts connections on a public port and forwards them through the tunnel to your home service.

The tunnel

On the VPS (/etc/wireguard/wg0.conf):

[Interface]
Address = 10.8.0.1/24
ListenPort = 51820
PrivateKey = <vps-private-key>

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

On the home machine:

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

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

PersistentKeepalive = 25 is what keeps the CGNAT mapping alive so the VPS can reach you. AllowedIPs = 10.8.0.1/32 sends only tunnel traffic through the VPS, not all of your home traffic. If you want other devices to use the tunnel too, widen it to 10.8.0.0/24.

New to this setup? How to set up WireGuard on Ubuntu covers the key generation and service steps.

Publishing a service

For HTTP(S), put a reverse proxy on the VPS and send it over the tunnel. With Caddy:

media.example.com {
    reverse_proxy 10.8.0.2:8096
}

You get automatic TLS, and the real client address arrives in X-Forwarded-For.

For anything that isn't HTTP, forward the port with iptables on the VPS (enable net.ipv4.ip_forward=1 first):

iptables -t nat -A PREROUTING -i eth0 -p tcp --dport 8096 -j DNAT --to-destination 10.8.0.2:8096
iptables -A FORWARD -i eth0 -o wg0 -p tcp -d 10.8.0.2 --dport 8096 -j ACCEPT
iptables -t nat -A POSTROUTING -o wg0 -j MASQUERADE

Replace eth0 with your VPS's interface. The MASQUERADE rule matters: without it the reply from your home machine leaves via your home router instead of back through the tunnel, and connections hang. The cost is that your service sees the tunnel address as the client, not the real one. If you need real client IPs on a non-HTTP service, you need policy routing on the home side. Also open the port in the VPS firewall (see firewall basics for your VPS), and remember ufw blocks forwarded traffic unless you allow it with ufw route.

Security

  • Every forwarded port is now public attack surface, reachable from the VPS's address. Put authentication in front of it and don't forward admin panels or SSH.
  • Bind the service to the tunnel address where you can, not 0.0.0.0.
  • Forward only the ports you need. For anything just you use, private access means there's nothing to attack at all.
  • Check the VPS provider's terms and traffic allowance before you route media streaming through it. Some plans cap bandwidth. See what a VPS is and SSH basics if you're new to managing one.

Where Nullsify fits

Nullsify has no relay or port-forwarding feature, so be clear about what it does here. It installs and manages a WireGuard server on a VPS you rent, and gives each device its own revocable config. Your home machine can be one of those devices. That covers the VPS side, the keys, and per-device access, which fits the private-access pattern best.

Two things stay manual. The configs it generates send all of a device's traffic through the VPS (AllowedIPs = 0.0.0.0/0), so for a home server you'd edit that to the tunnel subnet. And the DNAT or reverse-proxy rules for public exposure are yours to write. Choose the plain WireGuard protocol for this, not AmneziaWG or VLESS, so the home machine only needs standard WireGuard. The agent that runs on your VPS is public on GitHub, but the dashboard is a hosted service, not something you can self-host. If that's a dealbreaker, the hand-written configs above work on their own.

Ready to run your own VPN?

Bring your own VPS and have VLESS, AmneziaWG, or WireGuard running in minutes — no manual setup required.