All posts Guide

How to Reach an OPNsense Firewall Behind CGNAT Without Opening a Port

GUIDE 5 MIN READ NETDEFENSE TEAM

Behind carrier-grade NAT, a firewall has no public address of its own. Its ISP shares one address among many customers, so there’s no port to forward and nothing to point a VPN client at. The usual workarounds are a VPN back to a site that does have an address, a jump host somewhere, or a call to the ISP about a static IP.

This guide reaches that firewall from your browser instead, through a connection the firewall opens itself.

TL;DR

  • The NetDefense agent on the firewall only dials out. When you connect, it opens one more outbound connection, to a NetDefense relay, and your session meets it there.
  • The firewall needs no port forward, no public IP and no VPN client. It does need an outbound HTTPS connection.
  • Click Connect on the firewall’s page for a shell and the firewall’s own WebAdmin, already signed in, or run ndcli device connect from your terminal.
  • A remote session is a shell. It takes an interactive login and the Read-Write role. Read-Only members get a read-only WebAdmin session instead (early access).

Why it works behind CGNAT

The agent keeps a connection out to NetDefense, the way a browser reaches a website. Nothing in this setup connects in to the firewall, so it doesn’t matter that nothing on the internet could.

When you open a session, NetDefense sends the agent a signed request down that connection. The agent opens a second outbound connection, to a NetDefense relay, your side connects to the relay as well, and the relay pairs the two. The session ends as soon as either side leaves, and a session nobody joins within 5 minutes ends on its own.

What the firewall does need

Outbound HTTPS to the NetDefense addresses listed on Service Endpoints. A network that blocks outbound HTTPS blocks the agent too, and then nothing in this guide works.

Two ways a session travels

Your organization picks one of two session transports for everyone, and neither needs a port forward on either side:

  • Websocket relay, the default. Both ends connect to the NetDefense relay, which passes the session along. Each leg to the relay is encrypted with TLS, but the relay sits inside the session, so it isn’t end-to-end encrypted.
  • Direct-peer + encrypted relay, experimental. Your client and the firewall try to reach each other directly, peer to peer, over UDP through their NATs. When they can’t, a regional relay forwards their packets instead. A direct-peer + encrypted relay session is end-to-end encrypted between your client and the firewall either way, so the relay can’t read what it forwards. The direct path needs outbound UDP, and no port forward on either side. Where UDP is blocked, a direct-peer + encrypted relay session stays on the regional relay, still end-to-end encrypted.

Direct paths are for ndcli and the MCP server. In an organization set to direct-peer + encrypted relay, a session from the web console’s Connect goes through the regional relay, because a browser can’t open the direct path.

A Superuser of the organization chooses the transport and the relay region. The Remote Access guide covers both, and what each end needs.

Step 1: Put the agent on the firewall

Install the NetDefense plugin on the firewall and approve it in the web console, as in Devices. Registering is outbound too: the firewall appears in your console as Pending, and you approve it from the Devices page. Only an approved, enabled firewall can take a session.

Step 2: Connect

Open the firewall from Devices and click Connect. The page that opens has two tabs:

  • Terminal, a shell on the firewall in your browser. By default it opens OPNsense’s own console menu, and option 8 drops to a shell. A setting in the plugin’s Advanced section can open a shell directly instead.
  • WebAdmin, the firewall’s own web interface, through the same connection and already signed in. Your browser never receives the firewall’s credentials.

Pop Out moves the terminal to a window of its own, and Disconnect ends the session.

Who can open a session

A remote session is a shell on the firewall, so it’s guarded like one:

  • An interactive login. A session needs you signed in. A personal access token can’t open one, whatever its scope, so a script or a CI job holding a token can’t reach a firewall’s shell.
  • The Read-Write role, or Superuser. A Read-Only member’s session is read-only: the WebAdmin only, with no shell, and the firewall itself blocks configuration changes. It still shows logs and settings, and a search of the lists that hold secrets can recover one, so treat it as access to those secrets. Read-only sessions are in early access.
  • The firewall’s own policy. The plugin’s Remote Access Policy can make every session to that firewall read-only, whoever opens it.

Each session is also a task: on the Tasks page, tick Include Connect sessions to list them, with who opened each one.

Treat session access like an SSH key

Anyone with Read-Write access to the organization can open a shell on its firewalls by default. Give the role to the people who’d hold the SSH keys anyway.

From your own terminal

ndcli device connect opens the same session from your terminal. It starts a shell and, alongside it, a tunnel to the firewall’s WebAdmin on a local port, and prints the tunnel’s link. The first browser that opens the link gets the session, and the tunnel answers only that browser.

ndcli bash
$ ndcli auth login
$ ndcli device connect br-east-albany
$ ndcli device connect br-east-albany --shell
$ ndcli device connect br-east-albany --browser

With ndcli 1.51.0 or later, --shell opens the shell only, and --browser opens only the WebAdmin, in your default browser. With both flags you get both. device connect needs the same interactive login: NDCLI_TOKEN won’t open a session.

The Remote Access guide covers sessions and read-only access in depth.

Related reading

Security Security Fixes From Our November Security Review: Agent 1.33.0 and ndcli 1.52.0
Feature NDCLI 1.51.0 Opens the WebAdmin of device connect in Your Browser
Guide How to Roll Out OPNsense Updates Across a Fleet in Stages

Enjoyed this post? Explore more in the documentation.