Howto query and change network namespace on linux?
5,023
See the man page:
ip netns identify PID - Report network namespaces names for process
This command walks through /var/run/netns and finds all the network
namespace names for network namespace of the specified process.
So you would do something like:
ip netns identify $$
Related videos on Youtube
Author by
Isaac
Updated on September 18, 2022Comments
-
Isaac almost 2 years
I was wondering if there is a way to
- Query the network namespace the current shell is in
- Change the current network namespace of the current shell
I know I can do things like
sudo ip netns exec <namespace_name> <some command>
to execute a certain command in a certain network namespace, but I was thinking of something like
:~$ sudo query_current_namespace some_namespace :~$ sudo change_current_namespace_to other_namespace :~$ sudo query_current_namespace other_namespac :~$ dothings in newnamespace
Just like changerooting into into some subdir, so I won't have to prefix every command with the
sudo ip netns exec <namespace>
thingy.Searching the net it looks like I would have to write my own littel C Program, like suggested in this blog post. Is there allready a "standard" tool for this?
Edit: I just found that I could do
sudo ip netns exec <namespace> bash
which will give me a root shell in a new namespace. So almost there, but how do I query the current namespace?
-
Isaac almost 11 yearsOn what kind of system have you found this man page? At least on ubuntu 12.04 and fedora 18, the option
identify
is not present. The man page does not list it and the command does not recocnise it. -
Michael Hampton almost 11 yearsIt's on my Fedora 19 system.
-
Isaac almost 11 yearsI see, so its brand spankin new ;) Still, I am amazed that it takes that long (since linux 2.6.29) for such a cool feature to make it into admin tools.