{"id":12733,"date":"2022-05-14T08:12:02","date_gmt":"2022-05-14T05:12:02","guid":{"rendered":"https:\/\/kifarunix.com\/?p=12733"},"modified":"2024-03-09T13:40:00","modified_gmt":"2024-03-09T10:40:00","slug":"install-and-setup-ntp-server-on-ubuntu-22-04-debian-11","status":"publish","type":"post","link":"https:\/\/kifarunix.com\/install-and-setup-ntp-server-on-ubuntu-22-04-debian-11\/","title":{"rendered":"Install and Setup NTP Server on Ubuntu 22.04\/Debian 11"},"content":{"rendered":"\n<p>In this tutorial, you will learn how to install and setup NTP server on Ubuntu 22.04\/Debian 11. <a aria-label=\"Network Time Protocol (opens in a new tab)\" class=\"rank-math-link\" href=\"http:\/\/www.ntp.org\/\" target=\"_blank\" rel=\"noreferrer noopener\">Network Time Protocol<\/a> is a networking protocol that is used to synchronize system clocks on a network. NTP client employs a server-client architecture where NTP clients synchronize time from NTP server(s). NTP daemon ( ntpd ) is an NTP client program.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Install and Setup NTP Server on Ubuntu 22.04\/Debian 11<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\">Install NTPd on Ubuntu 22.04\/Debian 11<\/h3>\n\n\n\n<p>Once the update is done, proceed to install NTP daemon on Ubuntu 22.04\/Debian 11. The ntpd daemon is provided by the <em>ntp<\/em> package.<\/p>\n\n\n\n<p>To check if <em>ntp<\/em> package is installed on Ubuntu 22.04\/Debian 11 run the command:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo apt update -y<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code> dpkg -l ntp<\/code><\/pre>\n\n\n\n<p>If the package is not installed you will get output similar to:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>dpkg-query: no packages found matching ntp<\/code><\/pre>\n\n\n\n<p>The <em>ntp<\/em> package is available on the default Ubuntu 22.04 and Debian 11 repositories.<\/p>\n\n\n\n<p>Install <em>ntp<\/em> on Ubuntu 22.04\/Debian 11 by running the command:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo apt install ntp ntpdate ntpstat -y<\/code><\/pre>\n\n\n\n<p>Verify that that <em>ntp<\/em> package has been installed successfully by checking the version number:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sntp --version<\/code><\/pre>\n\n\n\n<p>Output:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sntp 4.2.8p15@1.3728-o Wed Feb 16 17:13:02 UTC 2022 (1)<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Running NTPd on Ubuntu 22.04\/Debian 11<\/h3>\n\n\n\n<p>After installation NTP is started and enabled to start at boot time:<\/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 Sat 2022-05-14 09:01:38 UTC; 4min 51s ago\n       Docs: man:ntpd(8)\n    Process: 109951 ExecStart=\/usr\/lib\/ntp\/ntp-systemd-wrapper (code=exited, status=0\/SUCCESS)\n   Main PID: 109957 (ntpd)\n      Tasks: 2 (limit: 2241)\n     Memory: 1.4M\n        CPU: 138ms\n     CGroup: \/system.slice\/ntp.service\n             \u2514\u2500109957 \/usr\/sbin\/ntpd -p \/var\/run\/ntpd.pid -g -u 114:120\n\nMay 14 09:01:40 jellyfish ntpd[109957]: Soliciting pool server 160.119.216.206\nMay 14 09:01:40 jellyfish ntpd[109957]: Soliciting pool server 160.119.216.197\nMay 14 09:01:41 jellyfish ntpd[109957]: Soliciting pool server 2001:19f0:5401:16b:5400:3ff:fef6:2691\nMay 14 09:01:41 jellyfish ntpd[109957]: Soliciting pool server 64:ff9b::a077:d8ca\nMay 14 09:01:42 jellyfish ntpd[109957]: Soliciting pool server 64:ff9b::a077:d8ca\nMay 14 09:01:42 jellyfish ntpd[109957]: Soliciting pool server 91.189.94.4\nMay 14 09:01:43 jellyfish ntpd[109957]: Soliciting pool server 91.189.89.199\nMay 14 09:01:44 jellyfish ntpd[109957]: Soliciting pool server 91.189.91.157\n...\n<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Setup NTP Server on Ubuntu 22.04\/Debian 11<\/h3>\n\n\n\n<p>NTP daemon <em>(ntpd)<\/em> main configuration file is <code>\/etc\/ntp.conf<\/code>. The file is configured to enable NTP server to fetch the correct time from NTP servers of higher stratum such as <strong><em>pool.ntp.org<\/em><\/strong>.<\/p>\n\n\n\n<p>The <strong><em>pool<\/em><\/strong> directive in the file enables setting of NTP time servers (pool) to use.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>sudo vim \/etc\/ntp.conf<\/code><\/pre>\n\n\n\n<p>By default NTP on Ubuntu 22.04\/Debian 11 uses <em>ubuntu<\/em> pool time servers from the NTP servers <strong><em>pool.ntp.org<\/em><\/strong>;<\/p>\n\n\n\n<pre class=\"scroll-box\"><code>\n# Specify one or more NTP servers.\n\n# Use servers from the NTP Pool Project. Approved by Ubuntu Technical Board\n# on 2011-02-08 (LP: #104525). See http:\/\/www.pool.ntp.org\/join.html for\n# more information.\n<strong>pool 0.ubuntu.pool.ntp.org iburst\npool 1.ubuntu.pool.ntp.org iburst\npool 2.ubuntu.pool.ntp.org iburst\npool 3.ubuntu.pool.ntp.org iburst<\/strong>\n\n# Use Ubuntu's ntp server as a fallback.\n<strong>pool ntp.ubuntu.com<\/strong>\n<\/code><\/pre>\n\n\n\n<p>A list of time servers can be found at <a aria-label=\" (opens in a new tab)\" class=\"rank-math-link\" href=\"http:\/\/www.pool.ntp.org\/en\/\" target=\"_blank\" rel=\"noreferrer noopener\">NTP Public Pool Time Servers<\/a> where one can choose which timeserver to use according to their timezone.<\/p>\n\n\n\n<p>First comment out the default ubuntu pool timeservers:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>...\n# more information.\n#pool 0.ubuntu.pool.ntp.org iburst\n#pool 1.ubuntu.pool.ntp.org iburst\n#pool 2.ubuntu.pool.ntp.org iburst\n#pool 3.ubuntu.pool.ntp.org iburst\n\n# Use Ubuntu's ntp server as a fallback.\n#pool ntp.ubuntu.com\n...<\/code><\/pre>\n\n\n\n<p>To add up servers from the <em>ke.pool.ntp.org<\/em> pool add the following entry on the configuration file:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>...\n#US\nserver 0.us.pool.ntp.org iburst\nserver 1.us.pool.ntp.org iburst\nserver 2.us.pool.ntp.org iburst\nserver 3.us.pool.ntp.org iburst\n...<\/code><\/pre>\n\n\n\n<p><strong><em>TIP:<\/em><\/strong> <em>Setting the pool as pool.ntp.org allows the system to determine the nearest time servers to use.<\/em><\/p>\n\n\n\n<p><strong><em>iburst<\/em><\/strong> option in the configuration file changes the initial interval of polls to a NTP server in order to speed up the initial synchronization.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">Configure Access Control for NTP Server (Optional)<\/h4>\n\n\n\n<p>NTP server can optionally be configured to only allow specific NTP client connections to query them using the <strong><em>restrict<\/em><\/strong> directive in the <code>\/etc\/ntp.conf<\/code> configuration file which uses the syntax:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>restrict address &#91;mask mask] &#91;other options]<\/code><\/pre>\n\n\n\n<p>This access control can be used to limit access to NTP service to particular LAN. For instance to only allow connections from the network 192.168.56.0\/24, define the network address by appending the line:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>restrict 192.168.56.0 mask 255.255.255.0 nomodify notrap<\/code><\/pre>\n\n\n\n<p>Where:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong><em>nomodify<\/em><\/strong> options prevents any changes to the configuration.<\/li>\n\n\n\n<li><strong><em>notrap<\/em><\/strong> option prevents ntpdc control message protocol traps.<\/li>\n<\/ul>\n\n\n\n<p>More about restrict and other command options can be read on <strong><code>man ntp.conf<\/code><\/strong>.<\/p>\n\n\n\n<p>Save the configuration file and restart NTP server for the changes to take effect.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code> sudo systemctl restart ntp<\/code><\/pre>\n\n\n\n<p>Confirm NTP service is set to start at boot time:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo systemctl is-enabled ntp<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>enabled<\/code><\/pre>\n\n\n\n<p>If disabled, enable it by running the command below;<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>sudo systemctl enable ntpd<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Configure Firewall to Allow NTP Services<\/h3>\n\n\n\n<p>If Ubuntu UFW is enabled allow UDP port 123. NTP clients connect to NTP server on that particular port.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo ufw allow from any to any port 123 proto udp<\/code><\/pre>\n\n\n\n<p>You can as well allow NTP queries from specific Network;<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo ufw allow from 192.168.56.0\/24 to any port 123 proto udp<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Verify NTP Time Service<\/h3>\n\n\n\n<p>Verify NTP server by checking the NTP server connection to NTP peers 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 ntp.ubuntu.com  .POOL.          16 p    -   64    0    0.000   +0.000   0.000\n+time.cloudflare 10.5.8.4         3 u   30   64  177   11.899   +0.609   7.783\n*time.walb.tech  163.237.218.18   2 u   30   64  175  245.101   -1.475  26.302\n+167-248-49-102. 129.6.15.27      2 u   28   64  177  285.856   -0.663  12.947\n-50-205-244-112- 50.205.244.27    2 u   25   64  177  315.383  -25.764  20.901\n-chilipepper.can 17.253.34.123    2 u   48   64  177  275.317  -52.046  39.830\n-alphyn.canonica 142.3.100.2      2 u   40   64  177  274.640   -9.207  13.777\n+pugot.canonical 17.253.108.125   2 u   44   64  177  179.313   -3.865  10.417\n-golem.canonical 17.253.108.253   2 u   40   64  127  274.772  -51.738  50.008\n<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Synchronizing Client&#8217;s System Time with NTP Server<\/h3>\n\n\n\n<p>Now that the NTP server is configured, it is high time to configure clients to synchronize their clocks with the NTP server.<\/p>\n\n\n\n<p><a href=\"https:\/\/kifarunix.com\/install-and-configure-ntp-client-on-ubuntu-debian-systems\/\">Install and Configure NTP Client on Ubuntu\/Debian systems<\/a><\/p>\n\n\n\n<p>That concludes our guide on how to install and setup NTP server on Ubuntu\/Debian.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Related Tutorials<\/h3>\n\n\n\n<p><a href=\"https:\/\/kifarunix.com\/how-to-configure-ntp-server-on-pfsense\/\" target=\"_blank\" rel=\"noreferrer noopener\">How to Configure NTP Server on pfSense<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>In this tutorial, you will learn how to install and setup NTP server on Ubuntu 22.04\/Debian 11. Network Time Protocol is a networking protocol that<\/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],"tags":[5161,5160,5159,5158,238,243,245,5162],"class_list":["post-12733","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-howtos","tag-configure-ntp-server-debian-11-2","tag-configure-ntp-server-debian-11","tag-configure-ntp-server-ubuntu-22-04","tag-install-and-setup-ntp-server-on-ubuntu-22-04-debian-11","tag-ntp","tag-ntpd","tag-ntpdate","tag-ntptime","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\/12733"}],"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=12733"}],"version-history":[{"count":4,"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/posts\/12733\/revisions"}],"predecessor-version":[{"id":20518,"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/posts\/12733\/revisions\/20518"}],"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=12733"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/categories?post=12733"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/tags?post=12733"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}