DEV Community

Ian Ochieng
Ian Ochieng

Posted on

"It works on my machine": 6 ways to share your localhost (and pick the right one in 30 seconds)

You've just finished a feature. It runs perfectly on localhost:3000. You send the link to a teammate and they reply:

"This site can't be reached."

Of course. localhost means this machine. Nobody else's.

This post walks through six ways to share your localhost, from "same Wi-Fi, zero install" to "public HTTPS URL in one command". Before you scroll, take the quiz below. It'll tell you which section to jump to.


🧭 Quick quiz: which one do you need?

Answer these three questions and keep score in your head.

1. Who needs to see it?

  • (a) My phone or a laptop on the same Wi-Fi
  • (b) Someone outside my network: a client, a teammate at home, a webhook

2. Can you install something?

  • (a) Nope, locked-down machine
  • (b) Sure

3. How long does the link need to live?

  • (a) Ten minutes, for a quick demo
  • (b) Days or weeks, with the same URL every time

👉 Click for your answer


1. Same Wi-Fi? Just bind to 0.0.0.0

Most dev servers listen on 127.0.0.1 by default. That's the loopback interface: only your own machine can connect to it. Tell the server to listen on all interfaces instead:

# Vite
npm run dev -- --host

# Next.js
npx next dev -H 0.0.0.0

# Python static server
python3 -m http.server 8000 --bind 0.0.0.0

# Go
http.ListenAndServe("0.0.0.0:8080", nil)
Enter fullscreen mode Exit fullscreen mode

Then find your machine's local IP:

hostname -I              # Linux
ipconfig getifaddr en0   # macOS
ipconfig                 # Windows (look for "IPv4 Address")
Enter fullscreen mode Exit fullscreen mode

Open http://192.168.x.x:3000 on your phone. Done.

Good for: testing on real mobile devices.
Watch out for: public/café Wi-Fi often blocks device-to-device traffic, and your firewall (ufw, Windows Defender) may need to allow the port.


2. SSH tunnel: nothing to install

If you have ssh (and you do), you have a tunnel:

ssh -R 80:localhost:3000 nokey@localhost.run
Enter fullscreen mode Exit fullscreen mode

It prints a public HTTPS URL. Anyone on the internet can open it until you close the terminal.

Good for: locked-down machines and one-off demos.
Watch out for: the free URL changes every session.


3. Cloudflare quick tunnel

Install cloudflared, then:

cloudflared tunnel --url http://localhost:3000
Enter fullscreen mode Exit fullscreen mode

You get a random https://something.trycloudflare.com URL. No account needed for quick tunnels.

Want a stable URL on your own domain? Log in and create a named tunnel. Same tool, permanent hostname.

Good for: fast, free, HTTPS by default.


4. ngrok

The classic. Sign up once, add your auth token, then:

ngrok http 3000
Enter fullscreen mode Exit fullscreen mode

The killer feature is the local inspector at http://127.0.0.1:4040. You can see every request that hit your tunnel and replay it. If you're debugging Stripe, GitHub or M-Pesa webhooks, this saves hours.

Good for: webhook development.


5. Tailscale Funnel

If you already use Tailscale to reach your own devices, Funnel exposes a port to the public internet on a stable *.ts.net HTTPS address:

tailscale funnel 3000
Enter fullscreen mode Exit fullscreen mode

If you only need your team to see it (not the whole internet), skip Funnel and share over the tailnet privately. That's the more secure option.

Good for: long-lived links with the same URL every time.


6. VS Code port forwarding

Open the Ports panel (next to Terminal), click Forward a Port, enter 3000, sign in with GitHub. Right-click the port and set visibility to Public if someone without a GitHub login needs it.

Good for: zero context-switching if you're already in the editor.


🐛 "The tunnel works but my app is broken"

You'll probably hit at least one of these:

"Blocked request. This host is not allowed." (Vite)
Newer Vite versions reject unknown hostnames. Add the tunnel host to your config:
// vite.config.js
export default {
  server: { allowedHosts: ['.trycloudflare.com', '.ngrok-free.app'] },
}
Enter fullscreen mode Exit fullscreen mode

For webpack-dev-server, the equivalent is allowedHosts: 'all'.


The page loads but API calls fail
Your frontend is probably still calling http://localhost:8080/api. On their machine, that's their localhost. Use a relative path (/api) behind a dev proxy, or tunnel the backend too.

Login works locally but not through the tunnel
Cookies set with Secure or SameSite rules, plus OAuth redirect URIs, are tied to the hostname. Add the tunnel URL to your OAuth app's allowed redirects and check your cookie domain.

Hot reload is dead
HMR runs over a WebSocket. Most tunnels support WebSockets, but your dev server may try to connect to localhost. In Vite, set server.hmr.clientPort: 443 when you're behind an HTTPS tunnel.


🔒 Before you share: a 4-point safety check

A public tunnel is a public server. Bots find new URLs within minutes.

  • [ ] No real secrets or production data in the app you're exposing
  • [ ] Debug panels and admin routes are off (or behind auth)
  • [ ] You'll close the tunnel when the demo ends
  • [ ] For anything longer than a demo, add auth (most tunnel tools support basic auth or SSO)

Cheat sheet

Need Command
Phone on the same Wi-Fi npm run dev -- --host
Public URL, no install ssh -R 80:localhost:3000 nokey@localhost.run
Public URL, no account cloudflared tunnel --url http://localhost:3000
Webhook debugging ngrok http 3000
Stable URL tailscale funnel 3000
Already in VS Code Ports panel → Forward a Port

💬 Your turn

I'm curious what everyone actually uses:

  1. Which method is your go-to? Drop the number (1–6) in the comments.
  2. What's the weirdest bug you've hit through a tunnel? I'll add the best ones to the troubleshooting section above.
  3. Challenge: run one of these commands right now and share your app with someone. Then tell me how long it took, from typing the command to them opening the link. ⏱️

If this saved you a "can't be reached" message, a ❤️ or 🦄 helps other devs find it.

Top comments (1)

Collapse
 
krusenas profile image
Karolis •

Last public URL I opened got a probe on the admin route before I'd even sent the link. Put basic auth on before the tunnel comes up, not after. I built Webhook Relay, it has HTTP tunnels for this.