Wiki
Home › Root servers › Hostname and time zone

Hostname and time zone

Set the server name and synchronise the time.

The hostname is the name of the server on the network. It appears in the shell prompt, in logs and as the sender of mails. The time zone determines how times are displayed. The system clock itself runs internally in UTC.

These commands are meant for root. As a normal user, put sudo in front of them.

  1. Set the hostname. Preferably choose a fully qualified name, e.g. server01.example.de. Letters, digits and hyphens are allowed.
    hostnamectl set-hostname server01

    The name is stored in /etc/hostname and remains in effect after a reboot.

  2. Add the hostname to /etc/hosts. Without this entry, sudo shows unable to resolve host at the next command. Add the line 127.0.1.1 with the new name:
    nano /etc/hosts
    127.0.1.1   server01
  3. Set the time zone. For Germany, Europe/Berlin is correct. timedatectl list-timezones shows all time zones.
    timedatectl set-timezone Europe/Berlin
  4. Check time synchronisation. The server gets the time from the network via the NTP protocol. The output should show System clock synchronized: yes and NTP service: active.
    timedatectl status

    If it shows NTP service: inactive, timedatectl set-ntp true switches the service on. If the firewall blocks outgoing UDP traffic on port 123, no synchronisation takes place. This relates to the section Firewall with ufw.

Why the time matters