I want to list all the network namespaces on my Linux machine. So far I found two recommended ways to do this:
ip netns list
Unfortunately both commands do not list all the namespaces! The first only lists the namespaces found in /var/run/netns and the second will only find namespaces with at least one process running in it. Docker for example will save its namespaces in /var/run/docker/netns (so they are not shown by ip netns) and there are some namespaces without a running process (so they are not shown by lsns). Is there any command that prints ALL the network namespaces on the host?
I once again came across this shortcoming of lsns and opened an issue in the repository. It is already fixed and in a future version of lsns it will show all the namespaces, even ones, that are only mounted with no process running in them. In the meantime the information is actually available in /proc/mounts. All mounts with the type nsfs should be mounted namespaces. This is not limited to network namespaces, but covers all namespaces.