Accurate time synchronization over the Internet is crucial for any system administrator. You can face data corruption or other issues if your server time is not synchronized with the correct time zone. NTP, which stands for Network Time Protocol, is a TCP/IP protocol for synchronizing time over a network. By default, Ubuntu 18.04 uses systemd’s timesyncd service for time synchronization.
This tutorial will show you how to check whether time synchronization works on your Ubuntu 18.04 server.
Step 1 – Update Server
Once you are logged into your Ubuntu 18.04 server, run the following command to update your base system with the latest available packages.
apt-get update -y
Step 2 – Verify Your Current Time, Date and Time Zone
The date command is the easiest way to find your server’s current date and time.
You can run the date command, as shown below, to show your server’s current time and date:
date
You should see the following output:
Thu Feb 6 04:56:55 UTC 2020
Next, you can check whether the time on your servers is activated and whether your server is synchronized with the correct time zone using the timedatectl command:
timedatectl
You should get the following output:
Local time: Thu 2020-02-06 05:04:49 UTC Universal time: Thu 2020-02-06 05:04:49 UTC RTC time: Thu 2020-02-06 05:04:50 Time zone: Etc/UTC (UTC, +0000) System clock synchronized: yes systemd-timesyncd.service active: yes RTC in local TZ: no
The above output shows that the time synchronization is activated and your configured time zone is Etc/UTC.
You can also check the status of the time synchronization service with the following command:
systemctl status systemd-timesyncd.service
You should see the following output:
• systemd-timesyncd.service - Network Time Synchronization Loaded: loaded (/lib/systemd/system/systemd-timesyncd.service; enabled; vendor preset: enabled) Active: active (running) since Thu 2020-02-06 01:25:58 AST; 2min 39s ago Docs: man:systemd-timesyncd.service(8) Main PID: 3106 (systemd-timesyn) Status: "Synchronized to time server 91.189.94.4:123 (ntp.ubuntu.com)." Tasks: 2 (limit: 2359) CGroup: /system.slice/systemd-timesyncd.service └─3106 /lib/systemd/systemd-timesyncd Feb 06 01:25:58 ubuntu1804 systemd[1]: Starting Network Time Synchronization... Feb 06 01:25:58 ubuntu1804 systemd[1]: Started Network Time Synchronization. Feb 06 01:25:58 ubuntu1804 systemd-timesyncd[3106]: Synchronized to time server 91.189.94.4:123 (ntp.ubuntu.com).
Step 3 – Change Time Zone Settings
If you want to change your server’s time zone settings, you can also set it using the timedatectl command.
If you’re not sure about your time zone, you can list the available time zones with the following command:
timedatectl list-timezones
You should see the long list of available time zones on the following screen:
Next, you can set the time zone using the timedatectl set-timezone command.
For example, set your server’s time zone to America/Antigua as shown below:
timedatectl set-timezone America/Antigua
Now, verify the time zone with the following command:
timedatectl
You should see the following output:
Local time: Thu 2020-02-06 01:08:41 AST Universal time: Thu 2020-02-06 05:08:41 UTC RTC time: Thu 2020-02-06 05:08:42 Time zone: America/Antigua (AST, -0400) System clock synchronized: yes systemd-timesyncd.service active: yes RTC in local TZ: no
Step 4 – Activate/Deactivate Time Synchronization
You can also disable and enable the time synchronization at any time using the timedatectl command.
To disable synchronization, run the following command:
timedatectl set-ntp off
Now, verify the changes with the following command:
timedatectl
You should get the following output:
Local time: Thu 2020-02-06 01:15:33 AST Universal time: Thu 2020-02-06 05:15:33 UTC RTC time: Thu 2020-02-06 05:15:34 Time zone: America/Antigua (AST, -0400) System clock synchronized: yes systemd-timesyncd.service active: no RTC in local TZ: no
You can enable time synchronization at any time with the following command:
timedatectl set-ntp on
You can run the timedatectl command again to confirm the network time status.
Conclusion
In this guide, we reviewed how to see the system time and date, change the time zone, and enable/disable time synchronization on Ubuntu 18.04. For more information, you can visit the official documentation at NTP Doc.
Learn more about our VPS hosting services and Virtual private servers.