Dev.to WebDev 🛠 Dev 👁 0 📖 10 min read

Local Tunnels Made Simple: Expose localhost with One SSH Command

Every developer has been there. You are running an app on localhost:3000, it looks great, and now a client, teammate, or your phone needs to see it. You could deploy to a staging server, open ports on the router, or ask

Local Tunnels Made Simple: Expose localhost with One SSH Command

Every developer has been there. You are running an app on localhost:3000, it looks great, and now a client, teammate, or your phone needs to see it. You could deploy to a staging server, open ports on the router, or ask a network administrator for help, but all of those options take time and are often impossible when you do not control the network. A local tunnel gives you a public URL in seconds by connecting out from your machine to a tunnel server. In this guide, you will learn how to create HTTP and TCP tunnels, what happens under the hood, how Pinggy compares with a DIY VPS, and how to keep your local machine safe while the tunnel is active.

Why Localhost Is Hard to Reach

Your local machine usually sits behind a router or a mobile network. The address localhost points only to your own computer, and nothing outside your machine can use it. A web server listening on port 8080 is reachable from your browser because your browser is running on the same machine, but a colleague on the internet cannot type your private LAN address such as 192.168.1.20:8080 and expect a connection. That address is not routable from the outside, and many ISPs use carrier-grade NAT, which means even your public IP address is shared with other customers.

Firewalls make things harder. Most consumer routers block inbound connections by default, and office networks often filter all incoming traffic. However, outbound connections are usually allowed. Your machine can reach the internet, download packages, call APIs, and open SSH connections. A local tunnel exploits this asymmetry. Instead of waiting for an inbound connection, your machine makes an outbound connection to a public server and keeps it open.

How a Local Tunnel Works

A local tunnel is a persistent channel between your computer and a tunnel server. The client on your computer dials out to the server, and the server keeps that connection alive. When someone visits the public URL that the server provides, the server pushes the request back through the open channel to the local port where your app is listening.

This is very close to SSH remote port forwarding. The command ssh -R creates a remote forward, but Pinggy simplifies the rest: it runs the server side, provides a public hostname, and handles TLS certificates. The same mechanism can carry many protocols. An HTTP tunnel is good for websites and APIs, while a TCP tunnel can carry SSH, database connections, or game server traffic.

Blog Image

Pinggy runs this channel over SSH on port 443, the same port used by HTTPS. That makes it less likely to be blocked by restrictive firewalls, because closing 443 would break secure web browsing for the whole network.

The Fastest HTTP Tunnel Setup

The fastest way to expose a local web app is to paste this command into your terminal:

ssh -p 443 -R0:localhost:8080 [email protected]

Replace 8080 with the port where your app is running. The qr@ part is optional, but it prints a QR code in the terminal so you can open the same URL on your phone without typing it.

Within a second or two you will see two public HTTPS links. One link is on free.pinggy.net and the other is on run.pinggy-free.link. Both point to the same app on your machine, and either one works from any browser.

Blog Image

There is no account needed for this quick test. The free plan gives you a fresh random URL every time and keeps the tunnel alive for 60 minutes. When the session ends, run the command again to get a new link.

Customizing Your HTTP Tunnel

For more control, sign in to the Pinggy Dashboard and create an access token. With a token, you can start a tunnel with a persistent subdomain. On the free plan, the URL changes after every reconnect. On a paid plan, you can keep the same subdomain indefinitely and even attach your own custom domain. A permanent URL is much easier for webhook integrations and client demos.

Some development servers are picky about the Host header. If your app is a dev server such as Vite and the tunnel URL returns an error like Blocked request. This host is not allowed, the dev server is rejecting the public hostname. You can tell Pinggy to rewrite the Host header before it reaches your local server. For example:

ssh -p 443 -R0:localhost:5173 [email protected] u:Host:localhost:5173

The u: option in the command forwards a modified request header. This is useful whenever a framework validates the domain name against a list of allowed origins.

The Pinggy CLI Option

If you would rather use a dedicated tool instead of raw SSH, the Pinggy CLI takes the same arguments and adds a terminal UI, automatic reconnects, and a little more convenience for longer sessions.

npm install -g pinggy

The package is published on npm, and it requires Node.js 22 or newer. Once installed, you can run pinggy with arguments similar to the SSH examples. The CLI is useful on Windows environments where the built-in SSH client behaves differently or when you want reconnect logic without writing a wrapper script.

TCP Local Tunnel Setup

HTTP tunnels are not the only option. You can expose an SSH server, a PostgreSQL database, an MQTT broker, or a game server with a TCP tunnel. The command changes only the username at the end:

ssh -p 443 -R0:localhost:22 [email protected]

Replace 22 with the port of the local service you want to share. Once the tunnel starts, you will recieve a public address in the form:

tcp://HOST:PORT

Use that host and port with your normal client. For an SSH server, you would run something like:

ssh -p PORT user@HOST

For a database, put the host and port into your database client and connect as if the database were running on a remote server.

On the free plan, the TCP port changes every time you reconnect. The paid plan lets you reserve a port from the dashboard, so clients can use a stable address.

Alternative: VPS with SSH Remote Port Forwarding

You can build a local tunnel by hand with a VPS. The idea is to rent a small server with a public IP, configure SSH remote port forwarding, and then ask clients to connect through that server. This gives you full control over the network path and the server software.

The tradeoff is operational work. You need to keep the VPS patched, set GatewayPorts in sshd_config, open firewall ports, manage SSH keys, and add your own TLS certificate if you want HTTPS. The configuraton overhead is real, especially if the goal is a two minute demo. There are also subtle networking issues, such as making sure the remote forward survives network changes and dealing with port conflicts.

I still use this approach when I need persistent infrastructure with no third party in the path. For quick development tasks, the SSH command to Pinggy is faster and more convenient.

Why Not Just Use Localtunnel?

You may have heard of Localtunnel, the npm package that powers npx localtunnel --port 8000. It is still a popular way to create a public URL for localhost, but the project has had no client release in years. The free loca.lt server is volunteer-run, and visitors may need to pass through a reminder page before reaching your app. It also supports HTTP only, so you cannot use it for TCP or UDP services.

For HTTP-only cases, it can be enough. For anything else, a single SSH command with Pinggy is simpler and more flexible.

Why Use a Local Tunnel

There are several good reasons to make a local tunnel part of your development workflow:

  • Speed: one command turns your local environment into a live URL with no deployment pipeline.
  • Network independence: NAT, CGNAT, and inbound firewall rules do not matter because the connection starts from your machine.
  • Cost: a tunnel can replace a test server for short demos, and you only pay when you need stability.
  • Protocol coverage: Pinggy handles HTTP, TCP, UDP, and TLS with small changes to the same command.
  • No installation: the SSH client already exists on macOS, Linux, and modern Windows.

The biggest win is confidence. You can show work in progress to a teammate or client the moment it runs on your machine instead of staging it first. Feedback loops become shorter and debugging sessions feel more collaborative.

Real-World Applications for Local Tunnels

Live Demos and Client Reviews

When a prototype runs on your laptop, it is easy to give a client a link for a live demo. They can click through the app and comment in real time, while you fix issues on the spot.

Mobile Development

Point a phone on mobile data at a backend running on your laptop. This is often the quickest way to test on a real device, because the phone is not on the same Wi-Fi network and uses cellular networking instead.

Webhooks and API Integrations

Webhook providers need a public URL to send events. With a local tunnel, you can point Stripe, GitHub, or Slack at your local handler and watch each callback arrive. Pinggy also includes a web debugger that shows request details and lets you replay requests, which is excellent for integration work.

IoT and Home Labs

A TCP tunnel gives you SSH or remote desktop access to a Raspberry Pi behind a home router without opening ports on the router. The same idea works for other devices that do not have a public IP.

Remote Administration

System administrators can reach a server or desktop from outside the network without building a VPN. The SSH outbound connection is usually enough to provide secure remote access.

Client Presentations

Before a beta release reaches production, a tunnel lets remote stakeholders try the build. You can close the tunnel when the presentation is over.

Security Considerations and Protection Strategies

A public URL is powerful, but it also makes your local service reachable by anyone who has the link. That includes admin panels, debug endpoints, and development databases. Do not treat an obscure URL as strong authentication. Public tunnel URLs are scanned by bots within minutes, and the free URL contains your public IP written with dashes, so sharing it is similar to sharing your IP address.

Pinggy gives you several ways to protect a tunnel directly in the command line. Add HTTP basic authentication with b:username:password, a bearer token with k:, or an IP allowlist with w: followed by a CIDR range. For example:

ssh -p 443 -R0:localhost:8000 free.pinggy.io b:demo:choose-a-strong-password

This adds a credentials prompt before anyone can reach your app. Without that, visitors with the link can use the service immediately.

The free plan also shows a short screening page on the first browser visit. That page is designed to discourage phishing abuse, but it is not access control. Always keep development and production data separate, monitor your app logs while the tunnel is open, and close the tunnel with Ctrl+C when you are done. If you need a reusable URL, use a persistent subdomain from the dashboard rather than reusing random links that have been posted in chat channels.

Traffic between visitors and Pinggy is protected by HTTPS, and the connection from the tunnel server to your machine is encrypted inside SSH. The link itself is the weakest part, so share it carefully.

Frequently Asked Questions

Can I use a local tunnel for production traffic?

Local tunnels are designed for development, testing, and short-lived exposure. The free tier is not a production hosting platform. If your service needs high availability and stable infrastructure, deploy it to a real server or use a managed platform.

What if my app listens only on 127.0.0.1?

A tunnel client on the same machine can still connect to localhost, so this is not a problem for Pinggy. The local port does not need to be exposed on all interfaces.

Does the public URL reveal my IP address?

The free URL contains a representation of your public IP address, so yes, it can expose your approximate location and identity. If that matters, use a paid plan with a persistent subdomain or connect through a VPN before starting the tunnel.

Conclusion

Local tunnels are one of the most practical tools in a developer toolbox. They turn an ordinary laptop into a temporarily public server, making it easy to run live demos, test on real devices, receive webhooks, and access remote systems. The trick is to use an outbound SSH connection on port 443, which bypasses most firewalls and NAT limitations. Pinggy makes this as simple as pasting a single command into your terminal.

Before you share teh link, add authentication if the service is sensitive. Choose the right protocol for the job, HTTP or TCP, and always close the tunnel when you no longer need it. Done that way, a local tunnel is fast, secure enough for development, and surprisingly reliable.

Reference

📰 Read the original article on Dev.to WebDev

Originally published by Dev.to WebDev. Aggregated on AIWithGhost for educational purposes — full credit and traffic to the original publisher.