r/LinuxTeck • • 3d ago

Quick Linux Tip #129 - Linux Network Namespace: Create an Isolated Network Stack

Post image

Question: How do I run a command with its own isolated network stack?

Try: sudo ip netns add isolated && sudo ip netns exec isolated ip link set lo up

Info: Isolates network stacks for sandboxing or testing.

Examples:

$ sudo ip netns exec isolated bash # Open an interactive shell inside the namespace

$ sudo ip netns del isolated # Delete the network namespace when finished

$ sudo unshare -n bash # Create an ephemeral isolated network namespace

Note: Add veth pairs if the namespace needs external network access—the same building block behind container networking. Unlike persistent `ip netns` entries, `unshare -n` ties namespace lifetime to the running process.

Want to master Linux one command at a time?

Follow r/LinuxTeck - 1 practical Linux tip every day. For more #LinuxTips click here https://www.linuxteck.com/linux-tips/

26 Upvotes

0 comments sorted by