Article

Table of Contents
Theme:
Was this article helpful?
Try Vultr Today with

$50 Free on Us!

Want to contribute?

You could earn up to $600 by adding new articles.

How to Configure NTP and Timezone on an Ubuntu Cloud Server at Vultr

Last Updated: Wed, Apr 13, 2022
Best Practices Ubuntu

Introduction

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.

Set the Timezone

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 /etc/timezone.

$ 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.

  1. 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.

  2. Set the timezone with timedatectl. You must be root or use sudo.

    $ sudo timedatectl set-timezone Antarctica/South_Pole
    

    Verify the timezone by viewing /etc/timezone.

    $ cat /etc/timezone
    Antarctica/South_Pole
    
  3. 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

Use NTP to Synchronize the Time

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.

$ 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

Advanced NTP Configuration

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 timesyncd.conf.

$ 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

More Information about Time Zones and NTP

Want to contribute?

You could earn up to $600 by adding new articles.