Stop your test apps from hogging host ports
Container Basics On Linux (Namespaces/Cgroups)
Stop your test apps from hogging host ports
🧩 The Challenge
Running multiple instances of the same service for testing, or spinning up a quick app that needs a specific port (like 8080)? You hit port conflicts instantly, and it’s a pain to constantly change configs or kill processes on your host. This slows everything down.
💡 The Fix
You can launch your app into its own completely separate network environment. It’ll get its own loopback interface and think it’s the only one on port 8080, all without touching your main system’s network stack. No more port conflicts for throwaway tests.
sudo unshare -Umpf --mount-proc --net sh -c "ip link set lo up && python3 -m http.server 8080"
⚙️ Why It Works
This `unshare` command creates new user, mount, PID, and network namespaces for the `sh` command. Specifically, `–net` gives it a fresh network stack. Inside this isolated shell, we bring up its *own* loopback interface, then start the web server. It’s completely oblivious to what’s happening on your host’s network.
🚀 Pro-Tip: Need to access it from the outside? That’s when you start playing with `veth` pairs and bridges. For quick, internal testing or just preventing conflicts, this is your ticket.
Linux Tips & Tricks | © ngelinux.com | 9/25/2026
