How can I move an interface out of a network namespace?

Solution 1:

I found an answer. Sure, you cannot do it from within the netns. But, if you execute ip netns exec .... from within the root network namespace, it all works.

ip netns exec <PID> ip link set eth10 netns 1

Then it works! It takes the PID (1 in this case) to which we are assigning it to be in the context of the executing command (wrapper) before we enter the netns. Done!

Solution 2:

You can use the ip netns delete function. From the man page:

ip [-all] netns delete [ NAME ] - delete the name of a network namespace(s)

If NAME is present in /var/run/netns it is umounted and the mount point is removed. If this is the last user of the network namespace the network namespace will be freed and all physical devices will be moved to the default one, otherwise the network namespace persists until it has no more users. ip netns delete may fail if the mount point is in use in another mount namespace.

It can not be used for all purposes, but it's definitely the easiest route.


Solution 3:

What worked for me based on deitch's answer is to execute the command from the custom netns:

ip netns exec myns ip link set eth10 netns 1