Self-hosting

Self-hosting behind CGNAT: How tunnels bypass ISP restrictions

A developer tests Levelrail's Cloudflare Tunnel integration to host services without a public IP, highlighting the shift from port forwarding to outbound connections and DNS-based certificate validati

Illustration of a server connecting to the cloud via a tunnel through a firewall
Illustration created for this article

Internet service providers increasingly assign private IP addresses to residential customers, a practice known as carrier-grade NAT (CGNAT). This configuration prevents traditional port forwarding, blocking direct access to self-hosted servers. In a recent technical evaluation, a developer explored how the deployment platform Levelrail manages this constraint by integrating with Cloudflare Tunnels, shifting the connectivity model from inbound listening to outbound dialing.

What happened

The author, a contributor to the open-source project Levelrail, investigated methods to expose self-hosted applications when the underlying network lacks a publicly routable IPv4 address. Traditional home networking relies on port forwarding, where the router directs incoming traffic on specific ports to internal devices. Under CGNAT, the router itself sits behind another layer of network address translation managed by the ISP, rendering local port forwarding ineffective because the public internet cannot directly address the customer's equipment.

To solve this, the author examined Levelrail’s experimental support for Cloudflare Tunnels. This technology allows a server to initiate an outbound connection to Cloudflare’s edge network. Once established, Cloudflare routes public traffic through this secure tunnel to the local service. The author verified that Levelrail can automatically deploy and manage the cloudflared connector container, which handles the outbound handshake. However, the evaluation stopped short of testing live traffic routing, as it required a valid Cloudflare account and token, which were not used in the local test environment.

Key details

  • Levelrail deploys the Cloudflare connector as a Docker container using the image cloudflare/cloudflared:2026.10.7.
  • The tunnel operates in an outbound-only mode, meaning no inbound ports need to be opened on the local firewall or router.
  • Configuration is handled via the levelrail-cli tool, which stores the tunnel token in an encrypted format.
  • The local status indicator reports "connected" if the container is running, even if the tunnel token is invalid or the remote connection fails.
  • Certificate validation cannot use the standard HTTP-01 challenge because port 80 is unreachable; DNS-01 challenges are required instead.
  • The feature is currently marked as experimental in the Levelrail documentation and has not been end-to-end tested with live traffic by the author.

Background

Carrier-grade NAT is a response to IPv4 address exhaustion. ISPs share a single public IP address among many customers, assigning private addresses (like 10.x.x.x or 100.x.x.x) to individual homes. While this conserves addresses, it breaks the assumption that every device can have a unique public identity. Tunnels circumvent this by reversing the connection flow. Instead of waiting for incoming requests, the server reaches out to a relay provider. This method is widely used in zero-trust network architectures, where security policies dictate that no unsolicited inbound traffic should ever reach the internal infrastructure.

Secure Sockets Layer (SSL) certificates, essential for HTTPS, typically prove domain ownership by placing a file on a web server that a certificate authority can fetch via HTTP. When a server is behind CGNAT or a tunnel, this external fetch is impossible. The alternative is DNS-01 validation, where the server proves ownership by creating a specific text record in the domain’s DNS zone. This requires API access to the DNS provider, adding complexity to the setup but enabling encryption without direct web access.

Why it matters

For teams running self-hosted software in residential or restricted corporate environments, CGNAT is a significant barrier. It forces a choice between paying for expensive business-class static IPs or relying on third-party tunneling services. Understanding the operational nuances of these tunnels is critical. For instance, relying solely on local container status for health checks can be misleading. As the author noted, the management interface may report a healthy state while the actual tunnel is down due to authentication errors. This discrepancy can lead to false confidence in service availability.

Furthermore, the shift to DNS-01 validation changes how certificates are managed. Automated renewal processes must now interact with DNS APIs rather than just local web roots. If these integrations fail silently, sites can go offline or serve expired certificates. Teams must ensure their deployment platforms handle these credential rotations securely and verify connectivity through the tunnel provider’s dashboard, not just local logs. This adds a layer of dependency on external services that must be monitored closely.

What you can do

  • Verify if your ISP uses CGNAT by checking if your router’s WAN IP matches the public IP seen by external services.
  • Use outbound tunneling solutions like Cloudflare Tunnels if you cannot obtain a public IPv4 address.
  • Configure DNS-01 challenges for TLS certificates when hosting behind NAT, ensuring your DNS provider supports API updates.
  • Monitor tunnel health via the provider’s dashboard (e.g., Cloudflare Zero Trust) rather than relying only on local container status.
  • Treat experimental features in deployment platforms with caution, testing them in isolated environments before production use.
  • Rotate tunnel tokens immediately if they are exposed, as they grant full access to create connectors for your tunnel.

More news

All news