External Access Behind CG NAT

Started by Ryushin, March 20, 2025, 12:07:05 AM

Previous topic - Next topic
I'm currently on Starlink using the 40GB Business Priority plan which gives me a IPv6 /56 block and a single public IPv4 address.  Due to them changing my plan in 28 days that will force me to go behind CG-NAT, I need to come up with a solution that will allow external access to my server. 

There were a lot of recommendations to use Tailscale which I just go into this morning.  It solves a few of my problems but not for external access to my server.

So I initially thought I could go with something like NordVPN and a static IPv4 IP.  Got that all set up in Opnsense and found out I cannot port forward traffic down the VPN to my firewall.  So that's out.

Searching for VPNs that support port forwarding I found PIA VPN and that offers port forwarding.  But you have to use special scripts to make use of it, at least on PFSense.  Is there a VPN service that offers a public IPv4 IP and will port forward all traffic to a specific host?

Ideally, since I get a IPv6 /56 block from Starlink, if there was some service that would do a IPv4 to IPv6 gateway that would be ideal, but I could not find such a service.

All my DNS is on HE.net and I use them also for Dynamic DNS.

Thoughts?  Suggestions?


Quote from: Ryushin on March 20, 2025, 12:07:05 AMIt solves a few of my problems but not for external access to my server.

Check out tailscale funnel or cloudflared

Late to this one, but the question comes up constantly, so here is the whole decision tree. The key point is that a consumer VPN like NordVPN is the wrong tool: it gives you outbound privacy, not an inbound public address you can forward from. What you want is an endpoint with a public IPv4 that you control, and your OPNsense box dialing out to it.

First, check whether you actually lost inbound. Many ISPs that put IPv4 behind CGNAT still hand out routable IPv6. If your /56 survived, you can skip everything below: add an AAAA record for the server (HE.net can do dynamic AAAA updates too), give the server a stable address, and allow the port on WAN under Firewall > Rules > WAN with the IPv6 destination set to that host. Anyone with IPv6 can reach you directly. The catch is that IPv4-only visitors cannot, which is why people end up with the next option.

If you need IPv4 reachability (or IPv6 is gone too), rent the smallest VPS you can find with a public IPv4 and make OPNsense a WireGuard client of it. WireGuard is built into current OPNsense releases (VPN > WireGuard). Outline:

- VPS: wg0 = 10.20.0.1/24, enable `net.ipv4.ip_forward=1`, open UDP 51820.
- OPNsense: instance at 10.20.0.2/32, one peer (the VPS) with allowed IPs 10.20.0.1/32, endpoint set to the VPS, keepalive 25 seconds. Assign the WireGuard interface and add a firewall rule that passes the service port from that interface to your server.
- VPS forward, for example for HTTPS to a server at 192.168.1.50 (add that /32 to the peer's allowed IPs on the VPS):
    iptables -t nat -A PREROUTING -i eth0 -p tcp --dport 443 -j DNAT --to-destination 192.168.1.50:443
    iptables -t nat -A POSTROUTING -o wg0 -j MASQUERADE
  The MASQUERADE line is the one people forget. Without it the server answers visitors via your normal WAN, the reply comes from the wrong address, and connections time out. The cost is that the server sees the VPS as the client; if you need real client IPs, run haproxy or nginx in TCP mode on the VPS with PROXY protocol instead.
- Point your DNS record at the VPS's static address. You can stop updating it dynamically.

Other routes depending on what the server is:
- Just your own devices need to reach it: Tailscale (or Headscale if you want to self-host the control plane). No public address involved, works through CGNAT.
- Public HTTPS site or web app, with no VPS wanted: Cloudflare Tunnel (cloudflared) or Tailscale Funnel, as already suggested above. Both are aimed at web traffic; they are a poor fit for arbitrary TCP or UDP services, where every visitor would need a client installed.
- You just need a shell on a machine behind the NAT: reverse SSH. From the inside machine, `ssh -N -R 127.0.0.1:2222:localhost:22 tunnel@vps.example.com` (wrapped in a systemd unit with Restart=always, or autossh), then connect with `ssh -J you@vps.example.com -p 2222 user@localhost`.

For that last case, if you would rather have a hosted relay than manage the VPS, I work on RescueShell, and this guide explains how to check whether you are behind CGNAT and compares the options: https://rescueshell.com/guides/ssh-behind-cgnat/ . It is only relevant for shell access to a Linux machine with OpenSSH, not for serving web traffic.