Home > IoT > Remotely Access IoT Behind NAT Router and Firewall

Remotely Access IoT Behind NAT Router and Firewall

Author: Ganesh Velrajan

Last Updated: Aug 17, 2026

If you’ve tried to SSH, VNC, or RDP directly into your IoT device from outside your network and gotten a connection timeout or “connection refused,” you’ve hit the NAT/firewall wall. This article is the practical fix — how to confirm that’s actually what’s happening, and how to set up a working connection without touching your router.

TL;DR: A NAT router or firewall blocks unsolicited inbound connections by design, so a direct SSH/VNC/RDP attempt from outside the network fails. SocketXP’s agent makes an outbound connection from the device to the SocketXP Cloud Gateway instead — no inbound port, no router configuration, and it works identically behind CGNAT. Install the agent, log in, and your device is reachable within minutes.

Confirm It’s Actually NAT or a Firewall

Before troubleshooting further, rule out the obvious: is this really a NAT/firewall block, or something else (wrong IP, service not running, wrong port)?

  • From inside the same network, connect to the device using its local IP (e.g. ssh pi@192.168.1.50). If this works, the SSH/VNC/RDP service itself is fine — the problem is purely inbound routing from outside.
  • From outside the network, connecting to the router’s public IP on the same port times out or is refused. This is the expected NAT/firewall behavior — routers do not forward unsolicited inbound traffic to any internal device unless explicitly configured to.
  • Check for CGNAT: compare your router’s reported WAN IP (in its admin page) against what an external service reports as your public IP — curl ifconfig.me run from a device on that network. If they don’t match, your ISP is using Carrier-Grade NAT, and port forwarding is not possible at all, regardless of router configuration, because your router doesn’t hold a real public IP to forward to.

If that matches what you’re seeing, the fix below applies directly.


Why This Happens

A NAT router translates your private IP addresses to a single public one, and keeps a table of outbound connections so return traffic can find its way back. It has no entry for a connection nobody inside the network initiated — so an inbound SSH attempt from outside has nowhere to go, and the router’s firewall drops it by default as a security measure.

That’s the short version. For the full mechanics — how the NAT table works, why dynamic IPs and DDNS complicate things further, and why port forwarding, DMZ, and UPnP are all weaker workarounds rather than real solutions — see How NAT Routers and Firewalls Secure Devices Behind Them. If you’re deciding between port forwarding, a VPN, and a tunnel-based solution, see Port Forwarding vs. VPN vs. Secure Tunnel for IoT Remote Access.

The rest of this article covers the fix: reversing the direction of the connection so NAT and the firewall never see it as unsolicited inbound traffic.


Setting Up SocketXP to Get Past NAT and Firewalls

SocketXP’s agent runs on the device and initiates an outbound SSL/TLS connection to the SocketXP Cloud Gateway. Because the device starts the connection, it looks like ordinary outbound traffic to the NAT router and firewall — nothing to configure, nothing to open.

Step 1: Install the Agent

Follow the download instructions for your device’s architecture (ARM64, ARMv7, ARMv6, MIPS, or x86_64).

Step 2: Authenticate the Device

sudo socketxp login 

Your auth token is available in the SocketXP portal after creating a free account. This registers the device with the SocketXP Cloud Gateway and generates a unique device credential locally.

Step 3: Create the Tunnel Configuration

Create /etc/socketxp/config.json, pointing at the local SSH daemon:

{
    "tunnels": [
        {
            "destination": "tcp://127.0.0.1:22"
        }
    ]
}

Step 4: Install as a Persistent systemd Service

sudo socketxp service install --config /etc/socketxp/config.json
sudo systemctl daemon-reload
sudo systemctl enable socketxp
sudo systemctl start socketxp

Step 5: Verify the Tunnel Is Up

sudo systemctl status socketxp

Open the SocketXP portal — the device should now appear in the Devices list as online. No router login, no port forwarding rule, no DDNS setup. The agent reconnects automatically if the network drops or the device reboots, so the tunnel survives the same connectivity blips that would otherwise silently break a port-forwarding setup.

SocketXP agent creating an outbound tunnel through a NAT router and firewall to the SocketXP Cloud Gateway

Accessing the Device: SSH, VNC, RDP, Web App, or Commands

Once the tunnel is up, every access method runs through the same outbound connection — you’re not opening a separate hole per protocol.

For a broader overview of how these five methods compare, see IoT Remote Access Over the Internet.


Conclusion

A NAT router or firewall blocking unsolicited inbound traffic is normal, correct behavior — it’s not misconfigured, and you shouldn’t try to defeat it by opening ports or placing the device in a DMZ. The reliable fix is to flip the connection direction: let the device initiate an outbound tunnel, and reach it through that. That’s what SocketXP does, and it’s the same reason it works whether the device sits behind a home router, an office firewall, or CGNAT with no real public IP at all.

Try SocketXP free for 30 days — no credit card required.

Further reading:


Frequently Asked Questions

  1. Do I need to change any router settings for SocketXP to work behind NAT?

    No. SocketXP's agent initiates an outbound SSL/TLS connection from the device to the SocketXP Cloud Gateway. Because the connection originates from inside your network, it passes through NAT and firewall rules exactly like any other outbound web request — no port forwarding, no firewall rule changes, no router admin access required.

  2. Does SocketXP work behind CGNAT (Carrier-Grade NAT)?

    Yes. CGNAT is only a problem for inbound connections and for peer-to-peer NAT traversal techniques like STUN/hole-punching, which can fail behind symmetric or carrier-grade NAT. SocketXP never attempts an inbound or peer-to-peer connection — the device's outbound tunnel to the gateway works identically whether the device is behind a home router, an office firewall, or several layers of carrier NAT.

  3. How do I know if my IoT device is behind CGNAT?

    Check your router's WAN/internet status page for its public IP address, then compare it to what an external service reports as your public IP (for example, curl ifconfig.me from a device on the same network). If the two addresses don't match, your ISP is performing CGNAT — your router does not hold a truly public IP, and port forwarding will not work no matter how it's configured.

  4. What ports does SocketXP need open on my firewall?

    None that you need to open manually. The SocketXP agent makes a standard outbound HTTPS-style connection (TCP 443) to the SocketXP Cloud Gateway, which is already permitted by default on virtually every router and corporate firewall, the same way a browser or an app update check is permitted. No inbound rule or port forwarding entry is created or required.

  5. Is this different from just putting my IoT device in the router's DMZ?

    Yes, significantly. Placing a device in the DMZ exposes every port on that device directly to the internet, bypassing the firewall entirely — a major attack surface. SocketXP's outbound tunnel exposes nothing; the device has no listening inbound port at all. Only the specific service you tunnel (SSH, VNC, RDP, or a web app) is reachable, and only through an authenticated SocketXP session.

SocketXP IoT Remote Access and Device Management Platform

Remotely access, manage, and update your IoT & AIoT edge fleet with SocketXP's secure and scalable platform.

Start Your Free Trial Now!

Join thousands of satisfied users who trust SocketXP for a secure, reliable, and scalable IoT Edge device management solution. Start your free trial now.