Network Time Protocol (NTP) is an internet protocol designed for time synchronization over packet-switched networks like the Internet. NTP uses the intersection algorithm to mitigate the effects of variable network latency and keep your system clock within a few milliseconds of Coordinated Universal Time (UTC).
Linux systems keep the time in UTC, but you can set the timezone to your local timezone. This article explains how to set the timezone on an Ubuntu Linux cloud server and use NTP to synchronize the time.
To check your current timezone, log in to your server and display the date and time.
$ date Fri 01 Apr 2022 04:21:00 PM UTC
Notice the timezone is UTC. You can also verify this by viewing
$ cat /etc/timezone Etc/UTC
By default, Vultr's Ubuntu servers use UTC timezone, which is usually preferable if you manage servers in different locations. However, you can set the server to your local timezone by following these steps.
View a list of all timezones.
$ timedatectl list-timezones
Select your desired timezone and take note of the exact name and capitalization. You can use SPACE and B to page forward and backward or your arrow keys to move one line at a time through the list. When finished, type Q to exit the list.
For this example, choose Antarctica/South_Pole.
Set the timezone with
timedatectl. You must be root or use sudo.
$ sudo timedatectl set-timezone Antarctica/South_Pole
Verify the timezone by viewing
$ cat /etc/timezone Antarctica/South_Pole
Check the time to verify the changes.
$ date Sat 02 Apr 2022 04:22:00 AM NZST
Notice the timezone now shows NZST, indicating the time at the South Pole.
If you decide to return to UTC later, run
timedatectl again with the UTC timezone.
$ sudo timedatectl set-timezone Etc/UTC
Vultr's Ubuntu systems have the
timesyncd service enabled by default to synchronize their time with an NTP server. You can verify this by running
$ timedatectl status Local time: Sat 2022-04-09 04:23:00 NZST Universal time: Fri 2022-04-08 16:23:00 UTC RTC time: Fri 2022-04-08 16:23:00 Time zone: Antarctica/South_Pole (NZST, +1200) System clock synchronized: yes NTP service: active RTC in local TZ: no
The System clock synchronized: yes and NTP service: active lines confirm that the system clock has synchronized with an NTP server. If you see these, you can proceed to the next section. Otherwise, start the service with
timedatectl. Again, you need to be the root user or use sudo.
$ sudo timedatectl set-ntp on
Wait a few minutes for the timesyncd service to start, then verify the status.
$ timedatectl status
Vultr configures new Ubuntu servers with constant.com NTP servers, which are low-latency servers on our network infrastructure. You can examine the configuration by viewing
$ cat /etc/systemd/timesyncd.conf [Time] NTP=1.time.constant.com 2.time.constant.com 3.time.constant.com #FallbackNTP=ntp.ubuntu.com #RootDistanceMaxSec=5 #PollIntervalMinSec=32 #PollIntervalMaxSec=2048
If you need to use specific NTP values, see the manpage at ubuntu.com and adjust the file to your needs. When finished, restart the service.
$ sudo systemctl restart systemd-timesyncd.service