🎁 New User? Get 20% off your first purchase with code NEWUSER20 Register Now →
Menu

Categories

lsns Command

Advanced Performance & Debugging man(8)

List Linux namespaces

📅 Updated: Mar 16, 2026
SYNTAX
lsns [OPTIONS]

What Does lsns Do?

The lsns command lists information about all Linux namespaces currently active on the system. Namespaces are the fundamental isolation mechanism behind containers (Docker, Podman, LXC) — they partition kernel resources so that processes in different namespaces have independent views of the system.

Linux supports several namespace types: PID (process IDs), NET (network stack), MNT (mount points), UTS (hostname), IPC (inter-process communication), USER (user/group IDs), CGROUP (cgroup hierarchy), and TIME (system clock). Each container typically has its own set of namespaces, isolating it from the host and other containers.

lsns is invaluable for container debugging, security auditing, and understanding how processes are isolated. System administrators use it to verify container isolation, identify namespace leaks, and troubleshoot inter-container communication issues.

Options & Flags

OptionDescriptionExample
(no options) List all namespaces lsns
-t TYPE Filter by namespace type (pid, net, mnt, uts, ipc, user, cgroup, time) lsns -t net
-p PID Show namespaces of a specific process lsns -p 1234
-J JSON output for scripting lsns -J
-o COLUMNS Specify output columns lsns -o NS,TYPE,NPROCS,PID,COMMAND
-u Show only namespaces with unique owners lsns -u

Practical Examples

#1 List all namespaces

Show all active namespaces with type, number of processes, PID of creator, user, and command.
$ sudo lsns

#2 List network namespaces

Show only network namespaces. Each container has its own network namespace with separate interfaces and routing.
$ sudo lsns -t net

#3 Check container isolation

Show all namespaces for a specific container process. Verify it has separate PID, NET, MNT, UTS namespaces.
$ sudo lsns -p $(docker inspect --format '{{.State.Pid}}' mycontainer)

#4 Count namespaces per type

Count how many namespaces of each type exist. More NET/PID namespaces = more containers.
$ sudo lsns -o TYPE --noheadings | sort | uniq -c | sort -rn

#5 JSON output for automation

Get namespace info in JSON for scripting and monitoring dashboards.
$ sudo lsns -J -t pid | jq '.namespaces[] | {ns: .ns, procs: .nprocs, command: .command}'

Tips & Best Practices

Namespaces and containers: Each Docker/Podman container creates 6-8 namespaces. The number of namespace sets roughly equals the number of running containers plus the host.
Combine with nsenter: Find the target namespace with lsns, then enter it with nsenter: nsenter -t PID -n (enter network namespace) or nsenter -t PID -p -m (enter PID and mount namespaces).
Requires root for full listing: Without root, lsns only shows your own namespaces. Use sudo for a complete listing including all containers and system namespaces.

Frequently Asked Questions

What are Linux namespaces?
Namespaces isolate kernel resources for processes. PID namespace gives separate process numbering, NET provides separate network stacks, MNT provides separate filesystems. Containers use all these for isolation.
How do I enter a container namespace?
Find the PID with lsns or docker inspect, then: nsenter -t PID -n (network), nsenter -t PID -p (PID), nsenter -t PID -m (mount). Use -a for all namespaces.
How many namespaces does a container use?
A typical container uses 6-8 namespaces: PID, NET, MNT, UTS, IPC, USER (optional), CGROUP (optional), and TIME (Linux 5.6+).
What is the difference between lsns and ip netns?
ip netns manages named network namespaces only. lsns lists ALL namespace types (PID, NET, MNT, etc.) including unnamed ones used by containers.

Master Linux with Professional eBooks

Curated IT eBooks covering Linux, DevOps, Cloud, and more

Browse Books →