$linuxjunkies
>

unshare(1)

Run a program in a new set of Linux namespaces, isolating it from the system.

UbuntuDebianFedoraArch

Synopsis

unshare [OPTION]... [PROGRAM [ARG]...]

Description

unshare creates new Linux namespaces and runs a program in them. Namespaces are used to isolate processes—each namespace instance provides its own view of system resources like the filesystem, network, process IDs, and users. This is fundamental to containerization and process isolation.

Without arguments, unshare starts a new shell in the specified namespaces. It's commonly used for testing namespace behavior, creating lightweight containers, or isolating network and filesystem changes.

Common options

FlagWhat it does
-i, --ipcCreate a new IPC namespace (message queues, semaphores, shared memory)
-m, --mountCreate a new mount namespace (isolated filesystem view)
-n, --netCreate a new network namespace (isolated network stack)
-p, --pidCreate a new PID namespace (process IDs start at 1)
-u, --utsCreate a new UTS namespace (hostname and domain name)
-U, --userCreate a new user namespace (UID/GID mapping)
-r, --map-root-userMap current user to root (UID 0) in new user namespace
-f, --forkFork child process before executing program
--mount-procMount /proc in the new PID namespace
-c, --cgroupCreate a new cgroup namespace

Examples

Start a new shell in an isolated mount namespace; mount changes won't affect the host

unshare -m /bin/bash

Run ip in an isolated network namespace as root; shows loopback-only network

unshare -n -r ip addr

Create a highly isolated environment with separate IPC, mount, network, PID, UTS, and user namespaces

unshare -i -m -n -p -u -r /bin/bash

Mount a tmpfs in /tmp within isolated namespace; invisible on host filesystem

unshare -m mount -t tmpfs none /tmp && ls /tmp

Create a file as root in user namespace; shows as owned by UID 0 inside the namespace

unshare -U -r touch /tmp/test && ls -l /tmp/test

Start a shell with isolated PID and mount namespaces; mounts new /proc (PID 1 is the shell)

unshare -p -m --mount-proc -f /bin/bash

Related commands