{"id":2525,"date":"2020-12-13T21:25:03","date_gmt":"2020-12-13T21:25:03","guid":{"rendered":"https:\/\/linuxways.net\/?p=2525"},"modified":"2020-12-13T22:27:15","modified_gmt":"2020-12-13T22:27:15","slug":"how-to-configure-an-ntp-server-and-client-on-debian-10","status":"publish","type":"post","link":"https:\/\/linuxways.net\/de\/debian\/how-to-configure-an-ntp-server-and-client-on-debian-10\/","title":{"rendered":"How to Configure NTP Server and Client on Debian 10"},"content":{"rendered":"<p>NTP is a networking protocol used to synchronize all system clocks in a network. This enables all the systems in a network to have the same time. NTP does so by contacting a number of other time servers on the internet. NTP uses UDP port 123 to communicate with clients and other NTP servers. In this post, we are going to show you how to configure the NTP server and client on the Debian system.<\/p>\n<p>For demonstration, we have used two Debian machines with the following details:<\/p>\n<p><strong>NTP host<\/strong> &#8211; Hostname: ntp-host, <a href=\"https:\/\/linuxways.net\/de\/debian\/how-to-configure-static-ip-in-debian-10\/\">Static IP address<\/a>: 192.168.72.158<\/p>\n<p><strong>NTP Client<\/strong> &#8211; Hostname: client, IP address: 192.168.72.159<\/p>\n<p><strong>Note<\/strong>: The steps shown here have been tested on Debian 10 (Buster).<\/p>\n<h2>Install and Configure NTP Server on Debian Host Machine<\/h2>\n<p>For installing and configuring the NTP server on Debian 10, you will need to perform all the steps that are listed below:<\/p>\n<h3>Step 1: Run Apt Update<\/h3>\n<p>First, you will have to update the packages list in order to download the latest version of the NTP package. Open the Terminal and run the following command to do so:<\/p>\n<pre>$ sudo apt update<\/pre>\n<h3>Step 2: Installing NTP on Host Server<\/h3>\n<p>To install the NTP server on the host machine, run this command:<\/p>\n<pre>$ sudo apt install ntp<\/pre>\n<p>After running the above command, you may be asked if you want to continue the installation by providing you with the <strong>y\/n<\/strong> (yes\/no) option. Enter <strong>y<\/strong> to continue the installation process.<\/p>\n<p>To verify if the NTP is installed and to view the version information, run the following command:<\/p>\n<pre>$ sntp --version<\/pre>\n<p><strong><img loading=\"lazy\" decoding=\"async\" width=\"457\" height=\"66\" class=\"wp-image-2539\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2020\/12\/word-image-206.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2020\/12\/word-image-206.png 457w, https:\/\/linuxways.net\/wp-content\/uploads\/2020\/12\/word-image-206-300x43.png 300w\" sizes=\"auto, (max-width: 457px) 100vw, 457px\" \/><\/strong><\/p>\n<h3>Step 3: Configuring NTP Server<\/h3>\n<p>To configure the NTP server, you are required to have two elements on your host machine: one is <strong>\/etc\/ntp.conf<\/strong> file and the other is <strong>ntpd<\/strong> daemon. First, we will configure the <strong>ntp.conf<\/strong> file and then we will restart the <strong>ntpd<\/strong> daemon.<\/p>\n<p>Edit the <strong>\/etc\/ntp.conf <\/strong>file using the following command:<\/p>\n<pre>$ sudo nano \/etc\/ntp.conf<\/pre>\n<p>When the NTP server is installed, it is by default configured to fetch the time from the following servers:<\/p>\n<pre>pool 0.debian.pool.ntp.org iburst<\/pre>\n<pre>pool 1.debian.pool.ntp.org iburst\n\npool 2.debian.pool.ntp.org iburst\n\npool 3.debian.pool.ntp.org iburst<\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"769\" height=\"281\" class=\"wp-image-2541\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2020\/12\/word-image-207.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2020\/12\/word-image-207.png 769w, https:\/\/linuxways.net\/wp-content\/uploads\/2020\/12\/word-image-207-300x110.png 300w\" sizes=\"auto, (max-width: 769px) 100vw, 769px\" \/><\/p>\n<p>You can replace them with the time servers nearest to your location. Visit the <a href=\"https:\/\/support.ntp.org\/bin\/view\/Servers\/NTPPoolServers\">ntp.org<\/a> website to find the NTP pool servers nearest to your location.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"914\" height=\"420\" class=\"wp-image-2542\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2020\/12\/word-image-208.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2020\/12\/word-image-208.png 914w, https:\/\/linuxways.net\/wp-content\/uploads\/2020\/12\/word-image-208-300x138.png 300w, https:\/\/linuxways.net\/wp-content\/uploads\/2020\/12\/word-image-208-768x353.png 768w\" sizes=\"auto, (max-width: 914px) 100vw, 914px\" \/><\/p>\n<p>To use any specific NTP pool server, you will need to add them to your <strong>ntp.conf<\/strong> file. We are going to add pools servers for the Asia region which is shown as follows:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"882\" height=\"400\" class=\"wp-image-2543\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2020\/12\/word-image-209.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2020\/12\/word-image-209.png 882w, https:\/\/linuxways.net\/wp-content\/uploads\/2020\/12\/word-image-209-300x136.png 300w, https:\/\/linuxways.net\/wp-content\/uploads\/2020\/12\/word-image-209-768x348.png 768w\" sizes=\"auto, (max-width: 882px) 100vw, 882px\" \/><\/p>\n<p>In the <strong>ntp.conf<\/strong> file, replace the default pool list with the following lines:<\/p>\n<pre>server 0.asia.pool.ntp.org\n\nserver 1.asia.pool.ntp.org\n\nserver 2.asia.pool.ntp.org\n\nserver 3.asia.pool.ntp.org<\/pre>\n<h3><img loading=\"lazy\" decoding=\"async\" width=\"731\" height=\"295\" class=\"wp-image-2544\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2020\/12\/word-image-210.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2020\/12\/word-image-210.png 731w, https:\/\/linuxways.net\/wp-content\/uploads\/2020\/12\/word-image-210-300x121.png 300w\" sizes=\"auto, (max-width: 731px) 100vw, 731px\" \/><\/h3>\n<p>Then save and close the <strong>ntp.conf<\/strong> file.<\/p>\n<h3>Step 4: Restart NTP Daemon<\/h3>\n<p>Now you should restart the NTP daemon. Use the following command to do this:<\/p>\n<pre>$ sudo service ntp restart<\/pre>\n<p>Now, run the following command to check if the NTP server is running without any issues:<\/p>\n<pre>$ sudo service ntp status<\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"903\" height=\"135\" class=\"wp-image-2545\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2020\/12\/word-image-211.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2020\/12\/word-image-211.png 903w, https:\/\/linuxways.net\/wp-content\/uploads\/2020\/12\/word-image-211-300x45.png 300w, https:\/\/linuxways.net\/wp-content\/uploads\/2020\/12\/word-image-211-768x115.png 768w\" sizes=\"auto, (max-width: 903px) 100vw, 903px\" \/><\/p>\n<h3>Step 5: Allow NTP through Firewall<\/h3>\n<p>If you are using a firewall, then you will need to configure it to allow UDP connections to NTP port 123. Run the following command to allow clients access to NTP server:<\/p>\n<pre>$ sudo ufw allow 123\/udp<\/pre>\n<p>Now run the following command to verify if the rule has been successfully added:<\/p>\n<pre>$ sudo ufw status<\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"588\" height=\"205\" class=\"wp-image-2546\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2020\/12\/word-image-212.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2020\/12\/word-image-212.png 588w, https:\/\/linuxways.net\/wp-content\/uploads\/2020\/12\/word-image-212-300x105.png 300w\" sizes=\"auto, (max-width: 588px) 100vw, 588px\" \/><\/p>\n<h2>Install and Configure NTP Client on Debian Client Machine<\/h2>\n<p>To configure a machine as an NTP client, you will need to ensure that the offset (time difference between the local clock and NTP server) is not more than 1024 seconds. If the offset is greater than this value, the time source will be considered inaccurate. For this reason, we will first try to manually synchronize the NTP client with the NTP server using the ntpdate. If the offset value comes less than 1024 seconds, we will then configure ntpd.conf file for automatic synchronization.<\/p>\n<h3>Step 1: Sync NTP Client with NTP Server Manually Using ntpdate<\/h3>\n<p>Ntpdate is used to synchronize the time of the NTP client with the NTP server for once only. To install it on the client machine, use the following command:<\/p>\n<pre>$ sudo apt install ntpdate<\/pre>\n<p>After running the above command, you may be asked if you want to continue the installation by providing you with the <strong>y\/n<\/strong> (yes\/no) option. Enter <strong>y<\/strong> to continue the installation process.<\/p>\n<p>Now use the following command to manually sync the NTP client with the NTP server:<\/p>\n<pre>$ sudo ntpdate &lt;ntp-server-hostname\/ip&gt;<\/pre>\n<p>In our scenario, it would be:<\/p>\n<pre>$ sudo ntpdate 192.168.72.158<\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"873\" height=\"66\" class=\"wp-image-2547\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2020\/12\/word-image-213.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2020\/12\/word-image-213.png 873w, https:\/\/linuxways.net\/wp-content\/uploads\/2020\/12\/word-image-213-300x23.png 300w, https:\/\/linuxways.net\/wp-content\/uploads\/2020\/12\/word-image-213-768x58.png 768w\" sizes=\"auto, (max-width: 873px) 100vw, 873px\" \/><\/p>\n<p>The output of the<strong> ntpdate<\/strong> command will show offset value (time difference between the local clock and NTP server). In our example, the offset value is 0.054776 sec which is very less. Therefore, we can now configure <strong>ntp.conf<\/strong> to automatically synchronize the time with our NTP server.<\/p>\n<h3>Step 2: Hosts File Configuration<\/h3>\n<p>Add the following hostname entry in the <strong>\/etc\/hosts<\/strong> file of the client machine. This step is required to resolve the NTP server through the hostname.<\/p>\n<pre>&lt;ntp-server-hostname&gt; &lt;ntp-server-ip&gt;<\/pre>\n<p>Make sure to replace <strong>ntp-server-hostname<\/strong> and <strong>ntp-server-ip<\/strong> with the hostname and IP address of your NTP respectively. In our scenario, it would be:<\/p>\n<pre>192.168.72.158 ntp-host<\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"575\" height=\"153\" class=\"wp-image-2548\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2020\/12\/word-image-214.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2020\/12\/word-image-214.png 575w, https:\/\/linuxways.net\/wp-content\/uploads\/2020\/12\/word-image-214-300x80.png 300w\" sizes=\"auto, (max-width: 575px) 100vw, 575px\" \/><\/p>\n<h3>Step 3: Disable systemd timesyncd Daemon<\/h3>\n<p>As we are going to setup NTP, therefore disable the <strong>systemd timesyncd<\/strong> daemon. Use the following command to do so:<\/p>\n<pre>$ sudo timedatectl set-ntp off<\/pre>\n<h3>Step 4: Sync NTP Client with NTP Server automatically Using NTP Configuration File<\/h3>\n<p>Now we will configure our client machine to sync with the NTP server automatically. For this reason, we will install NTP using the following command on the client system:<\/p>\n<pre>$ sudo apt install ntp<\/pre>\n<p>After running the above command, you may be asked if you want to continue the installation by providing you with the <strong>y\/n<\/strong> (yes\/no) option. Enter <strong>y<\/strong> to continue the installation process. Once the installation is finished, configure <strong>ntp.conf<\/strong> file.<\/p>\n<p>Run the following command to edit the ntp.conf file:<\/p>\n<pre>$ sudo nano \/etc\/ntp.conf<\/pre>\n<p>Insert the following line in the file:<\/p>\n<pre>server &lt;ntp-server-hostname\/ip&gt; prefer iburst<\/pre>\n<p>In our scenario, it would be:<\/p>\n<pre>server 192.168.72.158 prefer iburst<\/pre>\n<p>In the above line, <strong>prefer<\/strong> is used to mark the specified server as the preferred server for NTP synchronization. Where the <strong>iburst<\/strong> is used to send six packets for synchronization instead of the usual one (in case the NTP server is unreachable).<\/p>\n<h2><img loading=\"lazy\" decoding=\"async\" width=\"705\" height=\"247\" class=\"wp-image-2549\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2020\/12\/word-image-215.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2020\/12\/word-image-215.png 705w, https:\/\/linuxways.net\/wp-content\/uploads\/2020\/12\/word-image-215-300x105.png 300w\" sizes=\"auto, (max-width: 705px) 100vw, 705px\" \/><\/h2>\n<p>Now restart the NTP daemon to apply the configuration changes:<\/p>\n<pre>$ sudo service ntp restart<\/pre>\n<h2>Check NTP Synchronization Status<\/h2>\n<p>Now to check if NTP is working correctly, run the following command:<\/p>\n<pre>$ ntpq -p<\/pre>\n<p>Here is the output of the above command where <strong>remote<\/strong> is the NTP server hostname and <strong>refid<\/strong> is the top-level server to which our NTP server has itself connected for synchronization.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"798\" height=\"218\" class=\"wp-image-2550\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2020\/12\/word-image-216.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2020\/12\/word-image-216.png 798w, https:\/\/linuxways.net\/wp-content\/uploads\/2020\/12\/word-image-216-300x82.png 300w, https:\/\/linuxways.net\/wp-content\/uploads\/2020\/12\/word-image-216-768x210.png 768w\" sizes=\"auto, (max-width: 798px) 100vw, 798px\" \/><\/p>\n<p>That is all there is to it! In today\u2019s post, we have shown you how to configure the NTP server on Debian 10. Then we have explained how to configure the NTP client on another Debian machine and synchronize it with the NTP server. By following all the simple steps explained above, you can easily synchronize all system clocks in a network.<\/p>\n<p>You may like to visit our post on <a href=\"https:\/\/linuxways.net\/de\/ubuntu\/how-to-configure-an-ntp-server-on-ubuntu-20-04-lts-and-sync-a-clock\/\">How to configure an NTP server and client on Ubuntu 20.04 LTS<\/a>.<\/p>","protected":false},"excerpt":{"rendered":"<p>NTP is a networking protocol used to synchronize all system clocks in a network. This enables all the systems in a network to have the same time. NTP&hellip;<\/p>","protected":false},"author":4,"featured_media":2537,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4],"tags":[17,107],"class_list":["post-2525","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-debian","tag-debian-10","tag-ntp"],"_links":{"self":[{"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/posts\/2525","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/users\/4"}],"replies":[{"embeddable":true,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/comments?post=2525"}],"version-history":[{"count":0,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/posts\/2525\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/media\/2537"}],"wp:attachment":[{"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/media?parent=2525"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/categories?post=2525"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/tags?post=2525"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}