Is it possible to rename linux network namespaces

2

1

Is it possible to rename a linux network namespace. I am using ubuntu server 14. I just created a network namespace and configured it, but would like to rename it.

David Custer

Posted 2015-05-06T22:31:33.383

Reputation: 115

1

Looks like maybe the answer is no. http://man7.org/linux/man-pages/man8/ip-netns.8.html http://man7.org/linux/man-pages/man7/namespaces.7.html

– Dean Spicer – 2015-05-07T01:07:45.697

Answers

2

Yes. Namespaces themselves have no name; ip just attaches one by mounting the namespace fd on top of a blank file. So you could do this:

touch /run/netns/NewName
mount --move /run/netns/OldName /run/netns/NewName
rm /run/netns/OldName

In case mount --move does not work, the following should:

touch /run/netns/NewName
mount --bind /run/netns/OldName /run/netns/NewName
umount /run/netns/OldName
rm /run/netns/OldName

user1686

Posted 2015-05-06T22:31:33.383

Reputation: 283 655

If you are rebinding the old netns to the newns, you will not be able to rm it until you are done with the newly-nmed netns. – MariusMatutiae – 2015-06-13T12:55:36.460

@MariusMatutiae Only if you forget to umount the old namespace, no? – user1686 – 2015-06-13T16:17:59.293

Nope, I just tried it, and it did not work. I was curious because it's a trick I did not know. – MariusMatutiae – 2015-06-13T16:30:47.710

Hm, well, it certainly works here – as soon as findmnt no longer shows the old namespace as mounted, it is removable with both rm and ip netns rm. – user1686 – 2015-06-13T16:35:03.880

No, it does not work here. rm'ing the old netns prompts a device busy reply: a lazy unmount + rm leaves me unable to access the new netns. Linux hague 3.16.0-40-generic #54~14.04.1-Ubuntu SMP Wed Jun 10 17:30:45 UTC 2015 x86_64 x86_64 x86_64 GNU/Linux Kubuntu fully updated. I wonder what the difference is: perhaps the fact that when I try to do this I already have several NICs and openvpns open, i.e. a fully operational netns? – MariusMatutiae – 2015-06-14T13:34:48.260