Reachability: NAT, HTTPS, and Tunnels
Module 5 · DevSecOps II: Deploying to the Cloud

Reachability: NAT, HTTPS, and Tunnels

Why a running server isn't automatically reachable from a phone: private addresses and NAT, blocked ports, and mobile platforms' HTTPS requirements. Then how a tunnel service like ngrok works, what it trades away, and what replaces it in production.

“It’s Running, So Why Can’t the Phone Reach It?”

The API answers in a desktop browser at http://<public-ip>:3000/movies, yet the mobile app’s request fails. Three separate networking facts explain it.

1. Private addresses and NAT

Most devices don’t have a public internet address. Your laptop, your phone on Wi-Fi, and a container in a dev workspace all have private IP addresses (ranges like 10.x.x.x or 192.168.x.x) that only mean something inside their local network. A router performs NAT (network address translation): it rewrites outgoing traffic to use one shared public address and tracks the replies.

NAT has a key consequence: outbound connections work; unsolicited inbound connections don’t. Your phone can reach a server, but nothing on the internet can start a connection to a service sitting behind your home router or inside a dev container — unless something is explicitly forwarded.

2. Ports and firewalls

A connection targets an address and a port. Common services use well-known ports — 80 for HTTP, 443 for HTTPS. Uncommon ports like 3000 may be blocked by mobile carriers, corporate and campus networks, or the server’s own firewall (the security group from the last lesson). A URL that works from one network can fail from another.

3. HTTPS requirements on mobile

HTTP sends everything in plain text: anyone on the path — a café Wi-Fi operator, a compromised router — can read or alter it. HTTPS is HTTP over TLS (Transport Layer Security), which provides:

  • Encryption — eavesdroppers see only scrambled data.
  • Integrity — tampering is detected.
  • Server authentication — a certificate issued by a trusted certificate authority proves the server really owns the domain name.

Because of this, modern mobile platforms block plain-HTTP requests by default (iOS through App Transport Security, Android by disabling cleartext traffic for current app targets). Developers can add exceptions, but the platforms are steering everyone toward HTTPS — and a bare IP address can’t easily get a publicly trusted certificate.


Tunnels: Borrowing a Public HTTPS Address

A tunnel service such as ngrok solves all three problems at once by flipping the direction of the connection:

PhoneExpo Go appTunnel provider edgepublic URL with a validcertificate · TLS ends hereEC2 instancetunnel agentExpress APIlocalhost:3000HTTPS :4431. agent dials out2. requests flow back down it
  1. A small agent on the server opens an outbound connection to the provider. Outbound traffic passes NAT and most firewalls.
  2. The provider assigns a public HTTPS URL on port 443, covered by its own trusted certificate.
  3. When the phone calls that URL, the provider terminates TLS, then sends the request back down the agent’s existing connection to localhost:3000.

From the phone’s point of view it’s talking to a normal, trusted HTTPS endpoint. That’s why the deploy job in the last lesson installs the agent, authenticates it with an auth token (stored as a pipeline secret), starts the tunnel, and prints the public URL — which then becomes the frontend’s API_URL.

ProblemHow the tunnel helpsProduction alternative
Server behind NAT or firewallAgent connects outboundA public load balancer or reverse proxy
Unusual port blockedPublic URL uses 443Serve on 443 directly
Phone requires HTTPSProvider’s certificateYour own domain with a free certificate (e.g. Let’s Encrypt)
URL changes oftenPaid plans offer fixed domainsStable DNS name you control

What You Trade Away

Tunnels are excellent for development, demos, and webhook testing. Know the trade-offs before relying on one:

  • A third party sits in the middle. TLS ends at the provider, so it can see the decrypted traffic. Fine for a public movie list; a real concern for personal or regulated data.
  • Dependency and limits. Free tiers rate-limit traffic, and URLs can change on restart — every change means updating the app’s configuration.
  • It routes around your perimeter. The same property that makes tunnels convenient — “bypassing” NAT and firewalls by connecting outward — is why security teams watch for them. An unapproved tunnel on a company laptop can expose internal systems to the internet without anyone in IT knowing.
⚠️ Common Pitfall: Assuming HTTPS Means the Whole Path Is Private

Common mistake: believing that because the phone shows an HTTPS URL, the traffic is encrypted all the way to the API.

With a tunnel, TLS covers phone → provider; the provider → agent leg travels inside the tunnel’s own encrypted connection, but the provider itself handles plain requests. With a load balancer, TLS often ends at the balancer and continues as plain HTTP inside the cloud network. Always ask where TLS terminates and who can see traffic after that point.

🧠 Knowledge Check

1. Why can a tunnel agent behind NAT be reached from the internet, when the API itself can't?

2. Which is NOT provided by TLS?

3. A mobile app's fetch to http://<ip>:3000/movies fails, but it works in a desktop browser. What's a likely cause?

4. What's the main privacy consideration of routing an API through a tunnel provider?


Up Next

The app is deployed, scanned, and reachable. Now the user story grows: “I want to get movie recommendations from my selections.” Module 6 adds a second backend service — and with it, microservices and machine learning.