How to Change the Hostname and Timezone on Ubuntu Server Print

  • 0

Two small settings, three big payoffs: a proper hostname makes multi-server work far less error-prone (no more running a destructive command on the wrong box), and the right timezone plus NTP sync makes logs, cron jobs and TLS certificates behave. Both take one command on Ubuntu 24.04.

Changing the hostname

hostnamectl                                  # current state
sudo hostnamectl set-hostname web01.example.com
Changing the hostname on Ubuntu server with hostnamectl set-hostname

Convention: use a fully qualified name (web01.example.com) as static hostname, and keep names short, lowercase and descriptive — web01, db01, mail. Then update /etc/hosts so sudo and local lookups stay fast:

sudo nano /etc/hosts
127.0.0.1 localhost
127.0.1.1 web01.example.com web01

The new name shows in your prompt at the next login. If a cloud image resets the hostname at reboot, set preserve_hostname: true in /etc/cloud/cloud.cfg.

Setting the timezone

timedatectl                       # current time, zone and NTP status
timedatectl list-timezones | grep -i beirut
sudo timedatectl set-timezone Asia/Beirut
Setting the timezone with timedatectl set-timezone on Ubuntu server

Everything that timestamps — logs, cron, databases — now uses local time. Restart long-running services (cron in particular) so they pick up the change:

sudo systemctl restart cron
Tip: Many teams deliberately keep servers on UTC and convert in the application layer — it removes daylight-saving surprises and makes cross-region log correlation trivial. Whichever you choose, make it consistent across your fleet.

Keeping the clock accurate (NTP)

Ubuntu syncs time with systemd-timesyncd out of the box — verify with:

timedatectl timesync-status

If System clock synchronized says no, enable it:

sudo timedatectl set-ntp true

Accurate time is not cosmetic: TLS handshakes fail with skewed clocks, two-factor codes stop working, and database replication gets confused. If your server drifts, fix NTP before debugging anything else.

Where these settings live

The hostname is stored in /etc/hostname, the timezone is a symlink at /etc/localtime pointing into /usr/share/zoneinfo/hostnamectl and timedatectl simply manage these safely, so prefer them over editing files by hand.

Related Ubuntu guides

Prefer to have experts handle it?

LFA IT provides fully managed Ubuntu VPS and dedicated servers — initial setup, security hardening, monitoring and 24/7 support, so you can focus on your business. Explore our hosting and server management services or open a support ticket and our engineers will take it from there.


Was this answer helpful?

« Back