LINUXOR.SK ... open source notes ...

Namespaces 03 - UTS namespace

category: learnz/namespaces · date: 2016-11-01 · updated: 2017-01-16 · theme: github

Linux Namespaces Learning · Previous: MNT namespace · Next: PID namespace

The Slovak original of this document: Namespaces 03 - UTS namespace (slovensky).

UTS (UNIX time-sharing system) namespaces in Linux

1 Introduction

The UTS namespace (UNIX time-sharing system) isolates two system identifiers: the node name (host name) and the domain name, both returned by the "uname()" system call.

UTS namespace
UTS namespace

2 Working with UTS namespaces

2.1 Checking the host name in the default namespace

In terminal 1 (TERM1), check the host name.

asciiart
TERM1# uname -n
----------------------------------------------------------------------------------------------------------------
server1.domena.sk

2.2 Creating a new UTS namespace

In terminal 2 (TERM2), create a new UTS namespace.

asciiart
[1]TERM2# unshare -u /bin/bash
[2]TERM2# echo $$
----------------------------------------------------------------------------------------------------------------
6012
[3]TERM2# hostname uts1.domena.sk
[4]TERM2# uname -n
----------------------------------------------------------------------------------------------------------------
uts1.domena.sk

2.3 Checking that the new UTS namespace exists

In terminal 1 (TERM1), check that the new UTS namespace exists with "namespaces-info.sh", printing only the non-default namespaces (the -n switch).

asciiart
TERM1# ./namespaces-info.sh -n
----------------------------------------------------------------------------------------------------------------
---------- + ---------- + -------------------- + ----------------------------------------
PID        | PPID       | NAMESPACE            | COMMAND
---------- + ---------- + -------------------- + ----------------------------------------
18         | 2          | mnt:[4026531856]     | [kdevtmpfs]
---------- + ---------- + -------------------- + ----------------------------------------
585        | 1          | mnt:[4026532423]     | /usr/lib/systemd/systemd-udevd
---------- + ---------- + -------------------- + ----------------------------------------
720        | 1          | mnt:[4026532450]     | /usr/bin/vmtoolsd
---------- + ---------- + -------------------- + ----------------------------------------
755        | 1          | mnt:[4026532451]     | /usr/sbin/NetworkManager
---------- + ---------- + -------------------- + ----------------------------------------
854        | 755        | mnt:[4026532451]     | /sbin/dhclient
---------- + ---------- + -------------------- + ----------------------------------------
6012       | 5995       | uts:[4026532424]     | /bin/bash
---------- + ---------- + -------------------- + ----------------------------------------

Current practice (checked 2026-10)

noteThe article above is kept as it was written in 2016. This section lists what has changed since and what to do instead today.

The unprivileged variant of section 2.2 (the second command shows that the host keeps its name):

bash
$ unshare --user --map-root-user --uts sh -c 'hostname uts1.domena.sk; uname -n'
$ uname -n

Sources:

← learnz/namespaces(EN | SK)