LinuxCommandLibrary
GitHubF-DroidGoogle Play Store

nsenter

runs a program with namespaces of another process

TLDR

Run command in all namespaces of a process
$ nsenter -t 1234 -a command
copy
Enter mount namespace of a process
$ nsenter -t 1234 --mount command
copy
Enter network namespace of a process
$ nsenter -t 1234 --net command
copy
Enter PID namespace of a process
$ nsenter -t 1234 --pid command
copy
Enter multiple namespaces (UTS, time, IPC)
$ nsenter -t 1234 -u -T -i -- command
copy
Enter namespace via procfs reference
$ nsenter --net=/proc/1234/ns/net command
copy

SYNOPSIS

nsenter [options] [program [arguments]]

DESCRIPTION

nsenter runs a program with namespaces of another process. It is particularly useful for entering Docker containers, debugging processes in different namespaces, or working with chroot jails. If no program is specified, it runs the default shell.

PARAMETERS

-t, --target pid

Specify source process for namespace contexts
-a, --all
Enter all namespaces of the target process
-m, --mount[=file]
Enter mount namespace
-u, --uts[=file]
Enter UTS (hostname/domainname) namespace
-i, --ipc[=file]
Enter IPC namespace
-n, --net[=file]
Enter network namespace
-p, --pid[=file]
Enter PID namespace
-U, --user[=file]
Enter user namespace
-C, --cgroup[=file]
Enter cgroup namespace
-T, --time[=file]
Enter time namespace
-S, --setuid uid
Set user ID in entered namespace
-G, --setgid gid
Set group ID in entered namespace
-F, --no-fork
Do not fork before executing the program
-w, --wd[=directory]
Set working directory
-r, --root[=directory]
Set root directory

INSTALL

sudo apt install util-linux
copy
sudo dnf install util-linux
copy
sudo pacman -S util-linux
copy
sudo apk add util-linux-misc
copy
sudo zypper install util-linux
copy
brew install util-linux
copy
nix profile install nixpkgs#util-linux
copy

CAVEATS

Entering a PID namespace causes nsenter to fork by default. Use --no-fork to disable this behavior. Appropriate privileges are required to enter namespaces owned by other users.

HISTORY

nsenter is part of the util-linux package. It uses the setns(2) system call introduced in Linux 3.0 to enter existing namespaces.

SEE ALSO

unshare(1), clone(2), namespaces(7)

Braincup
Open source brain training for math, memory and focus
Braincup mini-games
41 mini-games · Apache-2.0
No ads · No tracking
Play in browser
Download Braincup on the App StoreGet Braincup on Google PlayGet Braincup on F-Droid
276 stars
From the maker of Linux Command Library
Copied to clipboard
Braincup
Open source brain training for math, memory and focus. 41 mini-games, from mental arithmetic to Sudoku, N-Back and Solo Chess.
Apache-2.0 licensed · No ads · No tracking · No account
From the maker of Linux Command Library
Download Braincup on the App StoreGet Braincup on Google PlayGet Braincup on F-Droid