Subject: Re: list of all network namespaces

From: Jiri Benc <[email-masked]>
Date: Thu, 17 Sep 2015 11:40:59 +0200

On Wed, 16 Sep 2015 17:54:34 -0700, Rick Jones wrote:
> On 09/16/2015 05:46 PM, Ani Sinha wrote:
> > just a stupid question. Is it possible to get a list of all active
> > network namespaces in the kernel through /proc or some other
> > interface?

Not reliably and not efficiently. You can look at what plotnetcfg does:
https://github.com/jbenc/plotnetcfg/blob/master/netns.c

> Presumably you could copy what "ip netns" does, which appears to be to 
> look in /var/run/netns .  At least that is what an strace of that 
> command suggests.

That only works for namespaces added by the ip tool (and presumably a
few other tools which leave a symlink in /var/run/netns as a courtesy).
Depending on what you need, it may be enough. Be aware that you won't
find all net namespaces in the system this way, though.

 Jiri

-- 
Jiri Benc