>_ IzzyLab

Hands-on task

This task is step 4 of the course “Containers from the inside: namespaces and cgroups”

A hostname of its own for the test bench

easy~8 min

This server runs the billing tests, and the test bench picks its config by hostname: it needs the name billing-test. You can't rename the server itself — monitoring and logs know it by its name.

Start a long-lived process (sleep infinity will do) in a separate UTS namespace where the hostname is billing-test. Leave the process running, and hostname on the server itself must stay the same.

What you'll practise:
  • namespaces
  • unshare
  • nsenter
  • hostname

Topic breakdown

A namespace is a kernel mechanism that gives a group of processes its own separate view of some resource. There are several kinds: PID (process numbers), mount (the filesystem tree), network (interfaces, addresses, routes), UTS (the hostname), IPC, user, cgroup. Every process belongs to exactly one namespace of each kind — see /proc/<PID>/ns/: the same number for two processes means a shared namespace. The UTS namespace is the simplest one: inside it you can change the hostname without affecting anyone outside. That's exactly how every Docker container gets its own hostname. unshare creates new namespaces and runs a command in them; nsenter runs a command in the namespaces of a process that is already running.

What's checked

  1. The server's own hostname hasn't changed
  2. A process in a separate UTS namespace with the name billing-test is running

What it looks like