When working on development projects, especially on local environments, you might often need to expose your local server to the internet for testing or sharing with your team. Tunneling is your go-to solution. It works across platforms, but today, we’ll focus on Ubuntu with a couple of tips that apply to other systems too.
Why Use a Tunnel?
Tunneling allows you to expose a locally running web application securely to the outside world. This is super helpful when you’re:
- Sharing a live demo with a client
- Testing webhook integrations
- Collaborating with remote team members on development
One popular tunneling tool is Ngrok, but we’ll also check out alternatives like Localtunnel and Pinggy. Each has its unique perks, so let’s dive in.
1. Ngrok
Ngrok is the go-to for many devs because it’s easy to set up and has a good dashboard.
Installation
For Ubuntu users, installing Ngrok is straightforward:
brew install ngrok/ngrok/ngrok
For other platforms, you can download Ngrok here.
Setup
First, sign up for an account, then add your auth token:
ngrok config add-authtoken <your-token>
Start Tunneling
ngrok http 8080
This exposes your local server running on port 8080 to the world via a public URL.
2. Localtunnel
Localtunnel is another handy tool if you prefer a no-fuss setup with fewer features. It’s quick to get started and works with Node.js.
Installation
Install Localtunnel globally with npm
npm install -g localtunnel
Start Tunneling
lt --port 8080
Bonus: Auto-reconnect
You can set up a script to auto-reconnect in case of disconnections:
until lt --port 8085 --subdomain shubh-local --local-https false; do echo "Try again";
done
You can even create an alias for this command, making it easy to fire up the tunnel with a short keyword.
3. Pinggy
If you’re looking for a lightweight solution, Pinggy might be up your alley. It’s simple and works well if you’re familiar with SSH.
Start Tunneling
ssh -p 443 -R0:localhost:8000 [email protected]
This method doesn’t need much configuration, making it perfect for quick testing.
Conclusion
Tunneling is an essential skill for developers who frequently work with local servers, webhooks, or need to demo apps remotely. Ngrok is still the king when it comes to features, but tools like Localtunnel and Pinggy give you more options based on your specific needs.
Next time you need to share your localhost, give one of these tools a try and see which works best for you!
Happy tunneling 🚀