3 ms·
it might be a bit offtopic but there is a somewhat easy solution to isolate networking for some applications if needed; sudo ip netns add lonly sudo ip net
by mercora 5y ago
it might be a bit offtopic but there is a somewhat easy solution to isolate networking for some applications if needed;
sudo ip netns add lonly
sudo ip netns exec lonly sudo -u $USER -i
this should start an interactive shell session with isolated networking, the shell will only see a separate loopback interface without further ado. anything started like this will share the same isolated network environment but you can add and use as many separate network namespaces as needed...
https://www.man7.org/linux/man-pages/man8/ip-netns.8.html https://www.man7.org/linux/man-pages/man8/ip-netns.8.html
- Hello71 5y agothere's an easier way that doesn't require root and also doesn't break your environment variables: unshare -Ucn program
- mercora 5y agohuh, for some reason i did not know about this utility but it really looks like a better approach. i feel a bit unsure if running in a new user namespace could break things in subtle ways somehow though. however, it works without user namespace separation too. the cgroup namespace separation is required on my machine to make it work without root for some reason yet unknown to me.
- jfrunyon 5y agoIt already doesn't require root, nor does it necessarily break your environment variables.