Give the child its own hostname
Create a UTS namespace and observe the difference between isolation and a global change.
Jump to code and terminal ↓A name belongs to a namespace
Changing the root filesystem did not change the hostname. Linux stores a process's hostname view in its UTS namespace. Processes that share that namespace observe the same hostname. A new UTS namespace starts as a copy and can then diverge.
Observe the kernel object
The link /proc/self/ns/uts identifies the caller's UTS namespace. Compare that identifier inside and outside your child. Seeing container-one is only half the exercise: the parent must still be named lab-host.
readlink /proc/self/ns/uts hostname
Your change
Use unshare to create the namespace before running the child shell. Inside the child, set the hostname, then keep the two observation lines so the tests can inspect the result. The test restores the parent hostname if your experiment changes it.
Your goal
Run a child in a new UTS namespace, set its hostname to container-one, and leave the parent hostname unchanged.
What the tests observe
- Child hostname is container-one
- UTS namespace IDs differ
- Parent remains lab-host
Need a nudge?
Hint 1
Run unshare --help in the guest. The UTS option is -u.
Hint 2
unshare -u COMMAND starts COMMAND after creating a new UTS namespace.
Hint 3
Put hostname container-one inside the quoted child script, before the observations.
What happens inside Linux
unshare asks Linux to attach the calling process to a new namespace. The following shell inherits it. A hostname write updates that namespace's state, so processes in the original namespace see no change.
Optional account sync. Exercises work without an account.