How to configure time synchronization in Debian 9

How to configure time synchronization in Debian 9

Introduction

Modern software deployment demands accurate timekeeping to keep all process flowing seamlessly. When time is synchronized correctly it easy to record logs appropriately and apply database updates promptly. On the other hand, poorly synchronized time leads to data corruption, log errors, and other issues that are hard to remedy. This tutorial will help you configure time synchronization in your Debian 9 server using the ntpd server. we ’ll help you understand the basic commands and show you how to enable the alternative systemd-timesyncd time service. Assuming you have Linux hosting set up and ready to go, let’s get started!

Before You Begin

Before starting the synchronization, ensure the following conditions are met:

  • A Debian 9 server

Navigating The Basic Debian 9 Time Commands

By default, time synchronization is built-in and enabled on your Debian 9 server using the ntpd time server which is a component of the NTP package. Before you configure any time settings on your Debian 9 server, you need to understand the commonly used time commands. The most widely used time command is date, which is used to find out and display the time and date on a Debian server:

$ sudo date

This will display the time and date on your server:

SunOct  28 06:52:16 UTC 2018

By default, the Debian 9 server is set to the Coordinated Universal Time (UTC) timezone, which is the time at 00 longitudes. It always wise to use the Universal Time consistently to minimize the confusion that comes with the use of numerous time zones when spanning different infrastructure. However, if you are working on a project that requires different time zones you can adjust the timezones at will. To check the list of time zones, run the command below:

 $ sudo timedatectl list-timezones

This will give you a list with over 140 time zones. Scroll up and down to locate your preferred time zone and note it down, type q to exit this list. Now, to implement any time zone, issue the command below:

$ sudo timedatectl set-timezoneAmerica/New_York

This command will set the time zone to American/New_York. Remember to substitute America/New_York with a time zone of your choice. Once the timezone is set, run the command below to confirm the changes:

$ sudo date

This will give you the following output:

SunOct 28 03:08:32 EDT 2018

That is it! You now understand how to confirm and change your time zone on Debian 9.

Checking ntpd status

The Debian 9 server is configured to synchronize time using the ntpd server and other time servers. To check the status of the ntpd server, run the command below:

$ sudo systemctl status ntp

This will give you an output similar to the one below:

● ntp.service - LSB: Start NTP daemon
   Loaded: loaded (/etc/init.d/ntp; generated; vendor preset: enabled)
   Active: active (running) since Tue 2018-10-16 06:22:45 EDT; 1 week 4 days ago
     Docs: man:systemd-sysv-generator(8)
  Process: 876 ExecStart=/etc/init.d/ntp start (code=exited, status=0/SUCCESS)
    Tasks: 2 (limit: 4915)
   CGroup: /system.slice/ntp.service
           └─711 /usr/sbin/ntpd -p /var/run/ntpd.pid -g -u 105:109
. . .

The output confirms that ntpd is running correctly. To see more details about the ntpd server, execute the command below:

$ sudo ntpq -p

This will give you the following output:

remote           refid      st t when poll reach   delay   offset  jitter
==============================================================================
 0.debian.pool.n .POOL.          16 p    -   64    0    0.000    0.000   0.000
 1.debian.pool.n .POOL.          16 p    -   64    0    0.000    0.000   0.000
 2.debian.pool.n .POOL.          16 p    -   64    0    0.000    0.000   0.000
 3.debian.pool.n .POOL.          16 p    -   64    0    0.000    0.000   0.000
*reverb.baxterit       213.251.128.249     2 u  240  256  377   35.392    0.142   0.211
+ca.schukraft. it      209.87.233.53   2 u   60  256  377   10.242    1.297   2.412
-ns512634. ip-167  192.168.10.254   3 u   99  256  377   24.042    0.128   0.250
+nuug.ca                216.218.254.202    2 u   31  256  377   11.112    0.621   0.186
-time.srv.ualber       172.30.90.10   2 u  108  256  377    1.290   -0.073   0.132
-ns522433.ip-158    18.26.4.105    2 u  473  512  377   19.930   -1.764   0.293

Your output may be different, but it should give you a list of pool servers.

Changing To The Systemd-timesyncd

As aforementioned, the Debian 9 server is configured to manage time synchronization using the ntpd server. However, you are not entirely limited to using the ntpd server, you can replace it with systemd’s timesyncd utility. The timesyncd utility is an ideal replacement of the ntpd which is lightweight and well-connected to the systemd. Besides, it utilizes less intricate methods to synchronize time and doesn’t run as a time server.  For this reason, if you are working with real-time systems, consider using the ntpd server. To use the timesyncd, first run the command below to uninstall ntpd.

$ sudo apt purge ntp

Then issue the following command to start your timesyncd service:

$ sudo systemctl start systemd-timesyncd

Now, run the command below to check timesyncd’s status:

$ sudo systemctl status systemd-timesyncd

This will give you the following output:

● systemd-timesyncd.service - Network Time Synchronization
   Loaded: loaded (/lib/systemd/system/systemd-timesyncd.service; enabled; vendor preset: enabled)
  Drop-In: /lib/systemd/system/systemd-timesyncd.service.d
           └─disable-with-time-daemon.conf
   Active: active (running) since Sun 2018-10-2803:44:00 EDT; 12s ago
     Docs:man:systemd-timesyncd.service(8)
 Main PID:4719 (systemd-timesyn)
   Status:"Synchronized to time server 198.60.22.240:123 (0.debian.pool.ntp.org)."
    Tasks:2 (limit:4915)
   CGroup: /system.slice/systemd-timesyncd.service
           └─4719 /lib/systemd/systemd-timesyncd
....

You can use the timedatectl to check the current time:

$ sudo timedatectl

This will give you an output similar to:

  Local time: Sun 2018-10-28 03:46:36 EDT
  Universal time: Sun 2018-10-28 07:46:36 UTC
          RTC time: Sun 2018-10-28 07:46:36
         Time zone: America/New_York (EDT, -0400)
Network time on: yes
NTP synchronized: yes
    RTC in local TZ: no

This will display the local time, the universal time, and other details regarding the status of the network time. The value YES of the Network time on shows that the timesyncd is activated. On the other hand, YES of the NTP synchronized means that time was synced successfully.

Conclusion

That is it!  You have learned how to use with ntpd server, timesyncd service, and change your time zones on your Debian 9 System. If you have complex timekeeping requirements, visit the NTP documentation page to get in-depth details

Check out these top 3 Best web hosting services

Hostinger
$2.99 /mo
Starting price
Visit Hostinger
Rating based on expert review
  • User Friendly
    4.7
  • Support
    4.7
  • Features
    4.8
  • Reliability
    4.8
  • Pricing
    4.7
IONOS
$1.00 /mo
Starting price
Visit IONOS
Rating based on expert review
  • User Friendly
    4.5
  • Support
    4.0
  • Features
    4.5
  • Reliability
    4.5
  • Pricing
    4.3
Ultahost
$2.50 /mo
Starting price
Visit Ultahost
Rating based on expert review
  • User Friendly
    4.3
  • Support
    4.8
  • Features
    4.5
  • Reliability
    4.0
  • Pricing
    4.8

How to install MariaDB on Debian 9

This tutorial will show you how to install and configure MariaDB on Debian 9.
less than a minute
David Malcom
David Malcom
Author

How to install ownCloud on Debain 9

This tutorial will help you install and set up ownCloud; a powerful collaboratio
less than a minute
David Malcom
David Malcom
Author

How to install and configure Node.js on Debian 9

This tutorial will help you install and configure Node.j and Node.js Package Man
less than a minute
David Malcom
David Malcom
Author

How To Install PostgreSQL on a Debian 9 VPS or Dedicated Server

This tutorial will help you install and set up PostgreSQL on Debian 9 server:
less than a minute
Vladimir Rakov
Vladimir Rakov
Hosting Expert
HostAdvice.com provides professional web hosting reviews fully independent of any other entity. Our reviews are unbiased, honest, and apply the same evaluation standards to all those reviewed. While monetary compensation is received from a few of the companies listed on this site, compensation of services and products have no influence on the direction or conclusions of our reviews. Nor does the compensation influence our rankings for certain host companies. This compensation covers account purchasing costs, testing costs and royalties paid to reviewers.
Click to go to the top of the page
Go To Top