How To Setup NTP Server using timedatectl on Linux

Systemd has built-in tools to manage time on Linux, which shipped in most Linux distro which uses systemd such as RHEL/CentOS, Fedora, Debian, Ubuntu, Linux Mint and Archlinux. The timedatectl command allows you to change time, date, and timezone on Linux system.

In this tutorial, we’ll manage time in Linux by setting the date, time and timezone using timedatectl command. It’s a best practice to use the correct time on your Linux server to make troubleshooting or checking file log more easiers.

Get current Timezone

Using timedatectl command is straight forward, let’s get our current time and timezone

timedatectl status

timedatectl status

To get list of known timezone, run following command

timedatectl list-timezones

list timezone supported by linux

To set timezone, use sub-command set-timezone, for example

timedatectl set-timezone "Africa/Casablanca"

the timezone will changes after that command executed, which can be verify using timedatectl status
set timezone linux

Set timedatectl NTP Server

The best way to keep time synced and updated is using NTP (Network Time Protocol). The list of public NTP server can be found on
To enable NTP run following command

timedatectl set-ntp true

To disable NTP

timedatectl set-ntp false

If you notice we haven’t set the NTP server, to check the NTP server list used execute timedatectl show-timesync –all

PollIntervalMaxUSec=34min 8s
PollIntervalUSec=34min 8s
NTPMessage={ Leap=0, Version=4, Mode=4, Stratum=3, Precision=-26, RootDelay=48.583ms, RootDispersion=671us, Reference=A230E10, OriginateTimestamp=Sat 2020-10-24 04:29:02 +01, ReceiveTimestamp=Sat 2020-10-24 04:29:02 +01, TransmitTimestamp=Sat 2020-10-24 04:29:02 +01, DestinationTimestamp=Sat 2020-10-24 04:29:02 +01, Ignored=no PacketCount=79, Jitter=322us }

NTP server used by timedatectl stored at /etc/systemd/timesyncd.conf file, change the NTP= line to

NTP server timedatectl

restart the systemd-timesyncd services to applied the changes

systemctl restart systemd-timesyncd.service

Check the NTP server timedatectl show-timesync --all

PollIntervalMaxUSec=34min 8s
PollIntervalUSec=1min 4s
NTPMessage={ Leap=0, Version=4, Mode=4, Stratum=3, Precision=-25, RootDelay=48.599ms, RootDispersion=534us, Reference=A230E10, OriginateTimestamp=Sat 2020-10-24 04:39:41 +01, ReceiveTimestamp=Sat 2020-10-24 04:39:41 +01, TransmitTimestamp=Sat 2020-10-24 04:39:41 +01, DestinationTimestamp=Sat 2020-10-24 04:39:41 +01, Ignored=no PacketCount=1, Jitter=0 }

The reason I prefer using a well-known company for NTP server because I notice some NTP server randomly disappear from internet, and the uptime under 90% in a month which unacceptable for production server.

Leave a Reply