Quick Linux Tip #129:
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.
Leave a Reply