List namespaces with lsns
In this step, you will learn how to list the namespaces present on your system using the lsns
command. Namespaces are a fundamental concept in Linux that provide isolation for various system resources, such as processes, network interfaces, mount points, and more. This isolation is key to technologies like containers.
The lsns
command is part of the util-linux
package and is used to list information about the namespaces on your system.
First, let's ensure the util-linux
package is installed. While it's usually present, it's good practice to check. We can use apt
for this.
Open your terminal if it's not already open. You can find the Xfce Terminal icon on the left side of your desktop.
Now, type the following command to update your package list:
sudo apt update
Press Enter. You might see output similar to this:
Hit:1 http://archive.ubuntu.com/ubuntu jammy InRelease
Get:2 http://archive.ubuntu.com/ubuntu jammy-updates InRelease [119 kB]
...
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
...
Next, let's install util-linux
. Type the following command and press Enter:
sudo apt install util-linux
You might see output indicating that the package is already installed, which is fine. If it installs, you'll see progress bars and confirmation.
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
util-linux is already the newest version (x.xx.x-xu).
0 upgraded, 0 newly installed, 0 to remove and xx not upgraded.
Now that we're sure lsns
is available, let's use it to list the namespaces. Type the following command and press Enter:
lsns
You will see output similar to this, showing different types of namespaces and the processes associated with them:
NS TYPE NPROCS PID PPID CMD
4026531835 cgroup 1 1 0 /sbin/init
4026531836 pid 1 1 0 /sbin/init
4026531837 user 1 1 0 /sbin/init
4026531838 uts 1 1 0 /sbin/init
4026531839 ipc 1 1 0 /sbin/init
4026531840 mnt 1 1 0 /sbin/init
4026531841 net 1 1 0 /sbin/init
4026532720 cgroup 10 700 699 /usr/lib/xfce4/xfconf/xfconfd
4026532721 pid 10 700 699 /usr/lib/xfce4/xfconf/xfconfd
4026532722 user 10 700 699 /usr/lib/xfce4/xfconf/xfconfd
4026532723 uts 10 700 699 /usr/lib/xfce4/xfconf/xfconfd
4026532724 ipc 10 700 699 /usr/lib/xfce4/xfconf/xfconfd
4026532725 mnt 10 700 699 /usr/lib/xfce4/xfconf/xfconfd
4026532726 net 10 700 699 /usr/lib/xfce4/xfconf/xfconfd
...
The output shows columns like NS
(Namespace ID), TYPE
(Type of namespace, e.g., cgroup, pid, user, uts, ipc, mnt, net), NPROCS
(Number of processes in the namespace), PID
(Process ID), PPID
(Parent Process ID), and CMD
(Command).
This command gives you a high-level overview of the namespaces active on your system and the processes running within them.
Click Continue to proceed to the next step.