To access raspberry pi behind cgnat, you need the Pi to open an outbound connection to a system you can reach, rather than waiting for an inbound connection. This guide checks whether CGNAT is the cause, then compares reverse SSH, a mesh VPN, and a cloud relay before covering the proxy-farm case.
Why port forwarding fails behind CGNAT
Normal port forwarding assumes that your router has a public IPv4 address. The router receives a connection on that address and sends the selected port to the Raspberry Pi on your LAN.
CGNAT adds another NAT device at the ISP. Your router forwards a port inside your network, but the ISP’s CGN device still has no rule telling it to send unsolicited traffic to your connection. A dynamic DNS name can follow an address; it cannot create that missing inbound mapping.
The telltale range is 100.64.0.0/10, the shared address space reserved for carrier-grade NAT in RFC 6598. Your ISP may also put the router behind another private range. The reliable check is to compare the router’s WAN address with the public address seen by an external service.
What you need
Prepare these items before choosing a method:
- A Raspberry Pi with Raspberry Pi OS or another Linux distribution.
- SSH enabled on the Pi and a normal, non-root Linux user.
- A working outbound internet connection. The Pi does not need a public IP.
- A laptop or desktop from which you will connect.
- For reverse SSH, a small VPS with a public address and an SSH account.
- For a mesh VPN or cloud relay, an account and client software for the service you choose.
If the Pi is part of a 4G build, the same constraint applies to the dongle connection: the cellular provider may give you a private or shared address. The Raspberry Pi mobile proxy guide covers the hardware side, while this article focuses on reachability.
Step 1: Confirm the Pi is behind CGNAT
Why: This separates a CGNAT problem from a disabled SSH service, a wrong local address, or a firewall rule.
On the Pi, list its IPv4 addresses and the public IPv4 address visible on the internet:
ip -4 addr show
curl -4 https://api.ipify.org; echo
Now sign in to the router or cellular modem and note its WAN or internet address. Do not confuse that with the Pi’s LAN address from ip -4 addr show.
You are probably behind CGNAT when the router’s WAN address is different from the address returned by api.ipify.org, especially when the WAN address is in 100.64.0.0/10, 10.0.0.0/8, 172.16.0.0/12, or 192.168.0.0/16. A private address on the Pi alone is normal and does not prove CGNAT; most home networks use one layer of NAT even when the router has a public address.
Success looks like this: the Pi can make outbound connections, but a port opened only on your router is not reachable from another network. If the router and public addresses match, ordinary port forwarding may work; test SSH locally first before changing the router.
Step 2: Use a reverse SSH tunnel
Why: A reverse tunnel lets the Pi dial out to a public VPS, then carries your later SSH session back through that already-established connection.
This method is useful when you control a VPS and want a direct SSH path. The remote forwarding syntax is documented in the OpenBSD ssh manual: the listening port is on the remote SSH server, while its traffic is forwarded to the local side.
Prepare the VPS
Log in to the VPS and create a restricted tunnel account:
sudo adduser --disabled-password --gecos "" tunnel
sudo install -d -m 700 -o tunnel -g tunnel /home/tunnel/.ssh
The VPS only needs to accept SSH from the Pi. The forwarded port below binds to the VPS loopback address, so it is not exposed as a new public service.
Create a key and make the first connection
On the Pi, replace piuser with your Linux username and vps.example.com with the VPS hostname:
ssh-keygen -t ed25519 -f ~/.ssh/reverse-vps -C "pi-reverse"
ssh-copy-id -i ~/.ssh/reverse-vps.pub tunnel@vps.example.com
Start the tunnel from the Pi:
ssh -NT \
-o ExitOnForwardFailure=yes \
-o ServerAliveInterval=30 \
-o ServerAliveCountMax=3 \
-o StrictHostKeyChecking=yes \
-R 127.0.0.1:22022:127.0.0.1:22 \
-i ~/.ssh/reverse-vps tunnel@vps.example.com
Leave that terminal open for the first test. From another shell on the VPS, connect through the forwarded port:
ssh -p 22022 piuser@127.0.0.1
Success looks like a shell on the Pi, even though the client connected to 127.0.0.1:22022 on the VPS. If ssh reports that the remote forward failed, check the VPS SSH policy and whether another tunnel is already using port 22022.
Keep the tunnel running after a reboot
Once the test works, create a systemd unit on the Pi. Use the real home directory and username in place of piuser:
[Unit]
Description=Reverse SSH tunnel to VPS
After=network-online.target
Wants=network-online.target
[Service]
User=piuser
ExecStart=/usr/bin/ssh -NT -o ExitOnForwardFailure=yes -o ServerAliveInterval=30 -o ServerAliveCountMax=3 -o StrictHostKeyChecking=yes -o UserKnownHostsFile=/home/piuser/.ssh/known_hosts -i /home/piuser/.ssh/reverse-vps -R 127.0.0.1:22022:127.0.0.1:22 tunnel@vps.example.com
Restart=always
RestartSec=10
[Install]
WantedBy=multi-user.target
Save it as /etc/systemd/system/pi-reverse.service, then run:
sudo systemctl daemon-reload
sudo systemctl enable --now pi-reverse.service
systemctl status --no-pager pi-reverse.service
Keep the -R bind address as 127.0.0.1 unless you have a specific reason to expose the forwarded port to the VPS network. A loopback-only port means the VPS itself is the next authentication boundary.
Step 3: Use a mesh VPN for private access
Why: A mesh VPN is usually the cleanest choice when only you or your team needs to administer the Pi, not the general internet.
Install a mesh VPN client on both the Pi and your laptop using the provider’s current instructions. On the Pi, bring the client up and inspect its assigned address:
sudo tailscale up
tailscale ip -4
tailscale status
The commands above use Tailscale as an example. Replace them with the equivalent commands for your chosen mesh VPN if you use another provider. From the laptop, connect to the private overlay address shown by the client:
ssh piuser@100.x.y.z
A mesh VPN tries to make a direct encrypted path. If NAT or firewall conditions prevent that, many services can relay the already-encrypted traffic through their coordination network. That is different from exposing SSH on a public port: access is limited to devices and users admitted to the private network.
Success looks like a stable SSH session over the overlay address while the Pi has no inbound router rule. Use the VPN’s device ACLs or policy file to restrict who can reach TCP port 22.
Step 4: Use a cloud relay for a browser or public service
Why: A cloud relay is a better fit when you need a named hostname, browser-based access, or a web service reachable by an authorised outside user.
The relay agent on the Pi opens the connection outward. For example, Cloudflare Tunnel’s documentation describes this as an outbound-only connection model: the origin does not need a publicly routable IP or an inbound listener. Other managed relay products use the same basic pattern.
The general setup is:
- Install the relay agent on the Pi using the provider’s official package instructions.
- Create a tunnel in the provider’s dashboard or CLI and bind a hostname such as
pi.example.comtossh://localhost:22or to the local web service you actually need. - Add an identity policy before making the hostname available. Require your account, an approved email domain, a device certificate, or another explicit control.
- Start the agent as a system service and test the hostname from a network that is not the Pi’s local network.
For a Cloudflare-style SSH setup, the configuration shape is similar to this, with the tunnel UUID and credentials path supplied by the service:
tunnel: TUNNEL_UUID
credentials-file: /home/piuser/.cloudflared/TUNNEL_UUID.json
ingress:
- hostname: pi.example.com
service: ssh://localhost:22
- service: http_status:404
Do not publish an SSH hostname without an access policy. A relay removes the port-forwarding problem; it does not remove the need for SSH keys, account controls, updates, and logging.
For proxy farms: cloud router plus web terminal
Reverse SSH and mesh VPNs solve administration. They do not by themselves turn several 4G dongles into customer-ready HTTP and SOCKS5 endpoints.
For a Raspberry Pi proxy farm, ProxyKite uses an outbound connection from your Pi or Linux box to a cloud router. There is no static IP or open inbound port to configure, so the box can remain behind a home router, mobile connection, or CGNAT. The router publishes the proxy endpoints while the hardware and SIM data plans remain yours.
The ProxyKite getting-started guide has the current installer command. After installation, the service can provide HTTP and SOCKS5 access per dongle, rotation by link or on demand, sticky sessions, SMS tools, quotas, and a web terminal to the box. The licence is $9 per active dongle per month, with no per-GB charge; traffic uses your own SIM data plan.
If you are using Huawei E3372 HiLink sticks, see the Huawei E3372 proxy guide before wiring a larger fleet. For power, hub, and capacity planning, use the 4G proxy farm setup guide.

The important distinction is direction: a normal remote-access tunnel lets you reach the Pi; a proxy cloud router also gives your authorised users a controlled public endpoint for the traffic that the Pi sends through its own mobile connection.
Step 5: Verify the connection from outside
Why: A tunnel can look healthy from the Pi while the client-side route, authentication, or service binding is still wrong.
Test from a different network, such as a phone hotspot or a remote workstation. For each method, verify the specific path:
- Reverse SSH: on the VPS, run
ssh -p 22022 piuser@127.0.0.1. - Mesh VPN: run
tailscale ping 100.x.y.z, thenssh piuser@100.x.y.z. - Cloud relay: connect to the configured hostname using the relay’s client or SSH proxy command.
- Proxy farm: use the endpoint format from the ProxyKite panel and check that the expected dongle IP is returned by a permitted test request.
On the Pi, check the service and recent logs:
systemctl --no-pager --full status pi-reverse.service
journalctl -u pi-reverse.service -n 50 --no-pager
Use the matching service name for a mesh VPN or relay agent. A successful check should prove both authentication and an application-level response, not just that a process is running.
Security basics
Use these defaults for any method:
- Use an ed25519 SSH key and disable password login only after key login works in a second terminal.
- Use a dedicated Linux user with no unnecessary
sudoaccess. Do not run the tunnel as root. - Keep reverse forwards bound to loopback on the VPS. Do not change them to
0.0.0.0unless you also have a deliberate firewall and authentication design. - Update Raspberry Pi OS, OpenSSH, the VPN client, and the relay agent regularly.
- Restrict mesh VPN ACLs and cloud relay policies to named users or devices.
- Keep the Pi’s services bound to the interfaces they need. A tunnel should not turn every local admin service into a public endpoint.
If you manage the Pi locally and have a recovery path, you can use a host firewall. Apply the SSH allow rule before enabling a default-deny policy, then verify the active session remains usable.
Troubleshooting
The router port is open, but the Pi is still unreachable
Recheck the router WAN address against the result of curl -4 https://api.ipify.org. If they differ, the router rule stops at the ISP’s CGN device. Switch to an outbound tunnel, ask the ISP for a public address, or use IPv6 if your setup provides a globally reachable prefix.
The reverse tunnel says “remote forward failed”
On the VPS, check whether the port is already in use:
ss -ltnp | grep 22022
If it is occupied, choose another loopback port in both the -R command and the client SSH command. If no process owns it, check the VPS’s SSH server policy for remote TCP forwarding and inspect the tunnel account’s authorized key options.
The tunnel works once and then disappears
Check systemctl status, journalctl, and the Pi’s outbound firewall. The keepalive options in the example help detect a dead session; systemd restarts it after a real disconnect. Confirm that the Pi’s clock is correct and that DNS still resolves the VPS or relay hostname.
Mesh VPN connects, but SSH is refused
The VPN path and the SSH service are separate. On the Pi, run sudo systemctl status ssh and ss -ltnp | grep ':22'. Then check the VPN ACL and whether SSH is listening on the expected interface.
FAQ
Can I port forward through CGNAT?
Not through the ISP’s CGN device that you do not control. A port rule on your own router only works when the router has a reachable public address or the ISP provides a corresponding inbound mapping.
Is a Raspberry Pi private IP proof that I have CGNAT?
No. A private Pi address is normal behind a home router. Compare the router’s WAN address with an externally observed address; a mismatch is the useful signal.
Which option is best for one Raspberry Pi?
A mesh VPN is usually the simplest for private administration from your own devices. Choose reverse SSH when you already operate a VPS and want a plain SSH path, or a cloud relay when you need a named web or SSH service for authorised outside users.
Can ProxyKite work when the Raspberry Pi is behind CGNAT?
Yes. ProxyKite’s box connection is outbound, so you do not need a static IP or port forwarding. It provides the cloud routing layer for your own Huawei E3372 HiLink dongles and Raspberry Pi/Linux hardware; it does not supply the dongles, SIM cards, data plans, or bandwidth.