Menu

Show posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.

Show posts Menu

Messages - rescueshell

#1
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.