Skip to content

Instantly share code, notes, and snippets.

@berndverst
Forked from jessfraz/cheatsheet.md
Created September 12, 2018 21:26
Show Gist options
  • Save berndverst/990aba205eaf9f61275f55c07054f4a7 to your computer and use it in GitHub Desktop.
Save berndverst/990aba205eaf9f61275f55c07054f4a7 to your computer and use it in GitHub Desktop.

Setup

curl -sSL -o clone.c goo.gl/G45N5X

Net Namespace

# on host
ip a

# add CLONE_NEWNET
gcc -o net -w clone.c

./net ip a

unshare --net ip a

UTS Namespace

# no flags
gcc -o uts -w clone.c

./uts hostname

# add CLONE_NEWUTS
# uncomment hostname code
gcc -o uts -w clone.c

./uts hostname

unshare --uts -- /bin/bash -c 'hostname thing && hostname'

IPC Namespace

# host, create a message
ipcmk -Q

# no flags
gcc -o ipc -w clone.c

./ipc ipcs -q

# add CLONE_NEWIPC
gcc -o ipc -w clone.c

./ipc ipcs -q

unshare --ipc -- ipcs -q

User Namespace

# no flags
gcc -o user -w clone.c

./user ls -la

# add CLONE_NEWUSER
gcc -o user -w clone.c

./user ls -la

unshare --user -- ls -la

PID Namespace

# add CLONE_NEWPID
gcc -o pid -w clone.c

# run binary
./pid ps aux

# shows all processes
# add CLONE_NEWNS
# uncomment mounting of proc
gcc -o pid -w clone.c

# run binary
./pid ps aux
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment