Put a process in new UTS namespace
unshare -u bash
Once we put the bash process in the new UTS namespace we can set a new hostname for this process which will not affect the global hostname. In the same console:
# hostname
debian-containers
# hostname testdocker
# hostname
testdocker
# ls -l /proc/$$/ns|grep uts
lrwxrwxrwx 1 root root 0 Mar 27 19:23 uts -> uts:[4026532402]
in other shell - check the hostname and UTS id for the current host:
$ hostname
debian-containers
$ ls -l /proc/$$/ns|grep uts
lrwxrwxrwx 1 dmitritelinov dmitritelinov 0 Mar 27 19:24 uts -> uts:[4026531838]
so, we can see the global hostname has not changed and the UTS namespace is different.