{"id":3826,"date":"2019-08-03T10:45:39","date_gmt":"2019-08-03T07:45:39","guid":{"rendered":"https:\/\/kifarunix.com\/?p=3826"},"modified":"2024-03-12T07:46:36","modified_gmt":"2024-03-12T04:46:36","slug":"setup-ntp-server-using-ntpd-on-debian-10-buster","status":"publish","type":"post","link":"https:\/\/kifarunix.com\/setup-ntp-server-using-ntpd-on-debian-10-buster\/","title":{"rendered":"Setup NTP server Using NTPd on Debian 10 Buster"},"content":{"rendered":"\n<p>Follow through this guide to learn how to setup NTP server using NTPd on Debian 10 Buster.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Configure NTP server Using NTPd on Debian 10 Buster<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\">Run System Update<\/h3>\n\n\n\n<p>Before you can proceed, run the command below to update your system packages.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>apt update -y<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Install NTP on Debian 10 Buster<\/h3>\n\n\n\n<p>The <strong>ntp<\/strong> package provides the<strong> NTPd<\/strong> deamon that is responsible for setting and maintaining the system time of day in synchronism with Internet standard time servers. The <strong>ntp<\/strong> package is available on the default Debian 10 Buster repositories. Hence, you can install be executing the command below;<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>apt install ntp -y<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Running NTP Service<\/h3>\n\n\n\n<p>NTP is started and enabled to run on system boot after the installation. To check the status;<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>systemctl status ntp<\/code><\/pre>\n\n\n\n<pre class=\"scroll-box\"><code>\n\u25cf ntp.service - Network Time Service\n   Loaded: loaded (\/lib\/systemd\/system\/ntp.service; enabled; vendor preset: enabled)\n   Active: active (running) since Wed 2019-07-31 15:36:19 EDT; 4min 17s ago\n     Docs: man:ntpd(8)\n Main PID: 6163 (ntpd)\n    Tasks: 2 (limit: 4701)\n   Memory: 1.4M\n   CGroup: \/system.slice\/ntp.service\n           \u2514\u25006163 \/usr\/sbin\/ntpd -p \/var\/run\/ntpd.pid -g -u 107:115\n<\/code><\/pre>\n\n\n\n<p>To check if it is enabled to run on system reboot;<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>systemctl is-enabled ntp<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>enabled<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Configure NTP Pool<\/h3>\n\n\n\n<p>NTP is configured to use time servers from the Debian pool by default for time synchronization. You can configure your NTP server to use time servers close to your timezone.<\/p>\n\n\n\n<p>The obtain a list of the servers on your timezone (or your Continent) from&nbsp;<a rel=\"noreferrer noopener\" href=\"http:\/\/www.pool.ntp.org\/en\/\" target=\"_blank\">NTP Public Pool Time Servers<\/a>. Next, open NTP configuration file and comment the Debian pool servers and add your timezone NTP pool time servers. For example, to use NTP time pool servers from Europe, you would add the lines below to NTP configuration.<\/p>\n\n\n\n<pre class=\"scroll-box\"><code>\nserver 0.europe.pool.ntp.org\nserver 1.europe.pool.ntp.org\nserver 2.europe.pool.ntp.org\nserver 3.europe.pool.ntp.org\n<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>vim \/etc\/ntp.conf<\/code><\/pre>\n\n\n\n<pre class=\"scroll-box\"><code>\n...\n#pool 0.debian.pool.ntp.org iburst\n#pool 1.debian.pool.ntp.org iburst\n#pool 2.debian.pool.ntp.org iburst\n#pool 3.debian.pool.ntp.org iburst\n<strong>server 0.europe.pool.ntp.org\nserver 1.europe.pool.ntp.org\nserver 2.europe.pool.ntp.org\nserver 3.europe.pool.ntp.org<\/strong>\n...\n<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Configure NTP Server Access Control<\/h3>\n\n\n\n<p>To allow only specific NTP clients to query time services from your NTP server for time synchronization, you need to set the access control to define which clients to allow. This can be done using the NTP <strong>restrict<\/strong> parameter which takes the syntax;<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>restrict address [mask mask] [other options]<\/code><\/pre>\n\n\n\n<p>For example, to allow hosts on 192.168.1.0\/24 network to query the just time and statistics from your NTP server;<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>restrict 192.168.1.0 mask 255.255.255.0 nomodify notrap nopeer<\/code><\/pre>\n\n\n\n<pre class=\"scroll-box\"><code>\n...\n# Local users may interrogate the ntp server more closely.\nrestrict 127.0.0.1\nrestrict ::1\n\n# Allow hosts from 192.168.1.0\/24 network to query time and statistics\nrestrict 192.168.1.0 mask 255.255.255.0 nomodify notrap nopeer\n...\n<\/code><\/pre>\n\n\n\n<p>Where:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>nomodify<\/code>&nbsp;options prevents any changes to the configuration<\/li>\n\n\n\n<li><code>notrap<\/code>&nbsp;option prevents&nbsp;<code>ntpdc<\/code>&nbsp;control message protocol traps.<\/li>\n\n\n\n<li><code>nopeer<\/code>&nbsp;option prevents a peer association being formed<\/li>\n<\/ul>\n\n\n\n<p>For a basic NTP server setup, that is just about the configuration. Save the configuration and restart the NTP service.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>systemctl restart ntp<\/code><\/pre>\n\n\n\n<p>Check NTP server connection to NTP peers and the summary of their state by running the command;<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>ntpq -p<\/code><\/pre>\n\n\n\n<pre class=\"scroll-box\"><code>\n     remote           refid      st t when poll reach   delay   offset  jitter\n==============================================================================\n+dbn-ntp.mweb.co 194.58.204.148   2 u    8   64  377   91.919   14.732  36.071\n*ntp4.inx.net.za 0.60.139.194     2 u    5   64  377  108.066   -0.762  30.303\n+ns2.botsnet.bw  209.51.161.238   2 u   11   64  377   79.363   14.837  44.564\n+ns1.botsnet.bw  209.51.161.238   2 u    4   64  377  123.420  -12.651  10.062\n<\/code><\/pre>\n\n\n\n<p>As you can see, our NTP server is now peered to <strong>ntp4.inx.net.za<\/strong>. The <strong>asterisk (*)<\/strong> shows preferred time source.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Open NTP on Firewall<\/h3>\n\n\n\n<p>If UFW is running, you can simply allow NTP incoming queries from the specific network.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>ufw allow from 192.168.1.0\/24 to any port 123 proto udp<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Configure NTP Client<\/h2>\n\n\n\n<p>To verify that the configured server is actually working, you need to setup an NTP client to query time from our NTP server. This guide similarly uses Debian 10 Buster as an NTP client.<\/p>\n\n\n\n<p>Well, if you need to just run time synchronization once, you can simply use the <strong>ntpdate<\/strong> command. To install <strong>ntpdate<\/strong>;<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>apt install ntpdate<\/code><\/pre>\n\n\n\n<p>Once the installation is done, you can query time services from the server using <strong>ntpdate<\/strong> by running the command;<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>ntpdate 192.168.1.107<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code> 3 Aug 09:02:15 ntpdate&#91;1261]: adjust time server 192.168.1.107 offset 0.006268 sec<\/code><\/pre>\n\n\n\n<p>If you need to automatically set your client to query time from the NTP server all the time, you can use NTP daemon itself. Hence, install NTP package and configure it to query time services from your NTP server.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>apt install ntp<\/code><\/pre>\n\n\n\n<p>Once the installation is done, configure your NTP client to query the NTP server. This can be done by using the <strong>server<\/strong> command which takes the form;<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code><code>server<\/code> <em>address<\/em><\/code><\/pre>\n\n\n\n<p>For example;<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>server 192.168.1.107 <code>iburst<\/code><\/pre>\n\n\n\n<p>The <strong>iburst<\/strong> option improve the time taken for initial synchronization.<\/p>\n\n\n\n<p>You can as comment out the default Debian NTP time pool servers so you can just use your own NTP server.<\/p>\n\n\n\n<p>Hence, open the NTP configuration file<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>vim \/etc\/ntp.conf<\/code><\/pre>\n\n\n\n<pre class=\"scroll-box\"><code>\n...\n# You do need to talk to an NTP server or two (or three).\n#server ntp.your-provider.example\nserver 192.168.1.107 iburst\n\n# pool.ntp.org maps to about 1000 low-stratum NTP servers.  Your server will\n# pick a different set every time it starts up.  Please consider joining the\n# pool: &lt;http:\/\/www.pool.ntp.org\/join.html&gt;\n#pool 0.debian.pool.ntp.org iburst\n#pool 1.debian.pool.ntp.org iburst\n#pool 2.debian.pool.ntp.org iburst\n#pool 3.debian.pool.ntp.org iburst\n<\/code><\/pre>\n\n\n\n<p>Save and quit the configuration file.<\/p>\n\n\n\n<p>Next, disable Systemd timesyncd ntp.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>timedatectl set-ntp off<\/code><\/pre>\n\n\n\n<p>Restart NTP service<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>systemctl restart ntp<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Verify time synchronization<\/h3>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>ntpq -p<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>     remote           refid      st t when poll reach   delay   offset  jitter\n==============================================================================\n 192.168.1.107   196.10.52.58     3 u    2   64    1    0.080  1102276   0.000<\/code><\/pre>\n\n\n\n<p>Great. You have successfully installed and configured NTP server using NTPd on Debian 10 Buster. You have also setup the client and tested the working of your NTP server. Enjoy.<\/p>\n\n\n\n<p>Related Guides;<\/p>\n\n\n\n<p><a href=\"https:\/\/kifarunix.com\/configure-ntp-server-using-ntpd-on-fedora-30\/\" target=\"_blank\" rel=\"noreferrer noopener\" aria-label=\" (opens in a new tab)\">Configure NTP Server using NTPd on Fedora 30<\/a><\/p>\n\n\n\n<p><a href=\"https:\/\/kifarunix.com\/how-to-install-and-configure-ntp-server-using-ntpd-on-fedora-29-fedora-28\/\" target=\"_blank\" rel=\"noreferrer noopener\" aria-label=\" (opens in a new tab)\">How to Install and Configure NTP Server Using NTPd on Fedora 29\/Fedora 28<\/a><\/p>\n\n\n\n<p><a href=\"https:\/\/kifarunix.com\/how-to-install-and-configure-ntp-server-using-chrony-on-fedora-29\/\" target=\"_blank\" rel=\"noreferrer noopener\" aria-label=\" (opens in a new tab)\">How to Install and Configure NTP Server Using Chrony on Fedora 29\/Fedora 28<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Follow through this guide to learn how to setup NTP server using NTPd on Debian 10 Buster. Configure NTP server Using NTPd on Debian 10<\/p>\n","protected":false},"author":1,"featured_media":12718,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"rank_math_lock_modified_date":false,"footnotes":""},"categories":[121,236,930],"tags":[1025,997,5139,238,1059,243,245,5140],"class_list":["post-3826","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-howtos","category-ntp","category-ntpd","tag-buster","tag-debian-10","tag-install-ntp-server-debian","tag-ntp","tag-ntp-server","tag-ntpd","tag-ntpdate","tag-setup-ntp-server-debain","generate-columns","tablet-grid-50","mobile-grid-100","grid-parent","grid-50","resize-featured-image"],"_links":{"self":[{"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/posts\/3826"}],"collection":[{"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/comments?post=3826"}],"version-history":[{"count":5,"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/posts\/3826\/revisions"}],"predecessor-version":[{"id":21188,"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/posts\/3826\/revisions\/21188"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/media\/12718"}],"wp:attachment":[{"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/media?parent=3826"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/categories?post=3826"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/tags?post=3826"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}