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.
- Set the hostname. Preferably choose a fully qualified name, e.g.
server01.example.de. Letters, digits and hyphens are allowed.hostnamectl set-hostname server01The name is stored in
/etc/hostnameand remains in effect after a reboot. - Add the hostname to
/etc/hosts. Without this entry, sudo showsunable to resolve hostat the next command. Add the line127.0.1.1with the new name:nano /etc/hosts127.0.1.1 server01 - Set the time zone. For Germany,
Europe/Berlinis correct.timedatectl list-timezonesshows all time zones.timedatectl set-timezone Europe/Berlin - Check time synchronisation. The server gets the time from the network via the NTP protocol. The output should show
System clock synchronized: yesandNTP service: active.timedatectl statusIf it shows
NTP service: inactive,timedatectl set-ntp trueswitches 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
- Certificates: HTTPS certificates have an expiry date. If the clock is wrong, the browser reports an error or the certificate is rejected.
- Logs: Only with the correct time can events across several services be matched to the same moment.
- fail2ban: The time windows
findtimeandbantimeare calculated with the system time (see fail2ban). - Login and encryption: Many procedures check timestamps. A deviation often only shows up as TLS or login errors.