{"id":20144,"date":"2023-07-11T10:08:24","date_gmt":"2023-07-11T10:08:24","guid":{"rendered":"https:\/\/webhostinggeeks.com\/howto\/?p=20144"},"modified":"2023-10-23T10:35:54","modified_gmt":"2023-10-23T10:35:54","slug":"how-to-synchronize-time-on-ubuntu-server","status":"publish","type":"post","link":"https:\/\/webhostinggeeks.com\/howto\/how-to-synchronize-time-on-ubuntu-server\/","title":{"rendered":"How to Synchronize Time on Ubuntu Server"},"content":{"rendered":"<p><img decoding=\"async\" data-src=\"https:\/\/webhostinggeeks.com\/howto\/wp-content\/uploads\/2023\/07\/How-to-Synchronize-Time-on-Ubuntu-Server-1024x878.jpg\" alt=\"How to Synchronize Time on Ubuntu Server\" width=\"1024\" height=\"878\" class=\"alignnone size-large wp-image-20150 lazyload\" data-srcset=\"https:\/\/webhostinggeeks.com\/howto\/wp-content\/uploads\/2023\/07\/How-to-Synchronize-Time-on-Ubuntu-Server-1024x878.jpg 1024w, https:\/\/webhostinggeeks.com\/howto\/wp-content\/uploads\/2023\/07\/How-to-Synchronize-Time-on-Ubuntu-Server-300x257.jpg 300w, https:\/\/webhostinggeeks.com\/howto\/wp-content\/uploads\/2023\/07\/How-to-Synchronize-Time-on-Ubuntu-Server-128x110.jpg 128w, https:\/\/webhostinggeeks.com\/howto\/wp-content\/uploads\/2023\/07\/How-to-Synchronize-Time-on-Ubuntu-Server-420x360.jpg 420w, https:\/\/webhostinggeeks.com\/howto\/wp-content\/uploads\/2023\/07\/How-to-Synchronize-Time-on-Ubuntu-Server-540x463.jpg 540w, https:\/\/webhostinggeeks.com\/howto\/wp-content\/uploads\/2023\/07\/How-to-Synchronize-Time-on-Ubuntu-Server-720x617.jpg 720w, https:\/\/webhostinggeeks.com\/howto\/wp-content\/uploads\/2023\/07\/How-to-Synchronize-Time-on-Ubuntu-Server-960x823.jpg 960w, https:\/\/webhostinggeeks.com\/howto\/wp-content\/uploads\/2023\/07\/How-to-Synchronize-Time-on-Ubuntu-Server-1140x977.jpg 1140w, https:\/\/webhostinggeeks.com\/howto\/wp-content\/uploads\/2023\/07\/How-to-Synchronize-Time-on-Ubuntu-Server-1166x999.jpg 1166w, https:\/\/webhostinggeeks.com\/howto\/wp-content\/uploads\/2023\/07\/How-to-Synchronize-Time-on-Ubuntu-Server-840x720.jpg 840w, https:\/\/webhostinggeeks.com\/howto\/wp-content\/uploads\/2023\/07\/How-to-Synchronize-Time-on-Ubuntu-Server-1260x1080.jpg 1260w, https:\/\/webhostinggeeks.com\/howto\/wp-content\/uploads\/2023\/07\/How-to-Synchronize-Time-on-Ubuntu-Server.jpg 1400w\" data-sizes=\"(max-width: 1024px) 100vw, 1024px\" src=\"data:image\/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==\" style=\"--smush-placeholder-width: 1024px; --smush-placeholder-aspect-ratio: 1024\/878;\" \/><\/p>\n<p>Time synchronization is a crucial aspect for many <a href=\"https:\/\/webhostinggeeks.com\/blog\/what-are-web-servers-and-why-are-they-needed\/\">server<\/a> operations and applications. Ensuring that your <a href=\"https:\/\/webhostinggeeks.com\/blog\/what-is-ubuntu-beginners-guide-ubuntu-linux-distro\/\">Ubuntu<\/a> server or desktop system is synchronized with accurate time sources prevents a myriad of potential issues, from log discrepancies to application malfunctions.<\/p>\n<p>This tutorial will guide you through the process of setting up time synchronization on an Ubuntu system using the systemd-timesyncd service, a lightweight solution that comes pre-installed with many Ubuntu distributions. If you&#8217;re running a web server or any online application, accurate timekeeping is essential.<\/p>\n<p>Let&#8217;s get started.<\/p>\n<h2>Step 1: Check the Current Time Settings<\/h2>\n<p>Before making any changes, it&#8217;s a good practice to check the current system time and the hardware clock time.<\/p>\n<pre>\r\ntimedatectl status\r\n<\/pre>\n<p>This command will display the current time, time zone, and synchronization status.<\/p>\n<p>For example:<\/p>\n<pre>\r\ndimitri@webhostinggeeks:~# timedatectl status\r\n                      Local time: Mon 2023-10-23 10:10:13 UTC\r\n                  Universal time: Mon 2023-10-23 10:10:13 UTC\r\n                        RTC time: Mon 2023-10-23 10:10:14\r\n                       Time zone: Etc\/UTC (UTC, +0000)\r\n<\/pre>\n<h2>Step 2: Install systemd-timesyncd (If Not Installed)<\/h2>\n<p>While systemd-timesyncd is pre-installed on many Ubuntu systems, if it&#8217;s not on yours, you can easily install it:<\/p>\n<pre>\r\nsudo apt update\r\nsudo apt install systemd-timesyncd\r\n<\/pre>\n<h2>Step 3: Enable and Start the Service<\/h2>\n<p>Activate the systemd-timesyncd service to start on boot and immediately start it:<\/p>\n<pre>\r\nsudo systemctl enable systemd-timesyncd\r\nsudo systemctl start systemd-timesyncd\r\n<\/pre>\n<h2>Step 4: Verify Synchronization Status<\/h2>\n<p>After starting the service, you can verify that it&#8217;s actively synchronizing:<\/p>\n<pre>\r\ntimedatectl status\r\n<\/pre>\n<p>Look for &#8220;NTP synchronized&#8221; or &#8220;System clock synchronized&#8221; to be set to &#8220;yes&#8221;.<\/p>\n<pre>\r\ndimitri@webhostinggeeks:~# timedatectl status\r\n                      Local time: Mon 2023-10-23 10:10:13 UTC\r\n                  Universal time: Mon 2023-10-23 10:10:13 UTC\r\n                        RTC time: Mon 2023-10-23 10:10:14\r\n                       Time zone: Etc\/UTC (UTC, +0000)\r\n       System clock synchronized: yes\r\nsystemd-timesyncd.service active: yes\r\n<\/pre>\n<p>When you see NTP or System clock synchronized, it means that your system is successfully synchronizing its clock with the specified NTP servers. If it says &#8220;no&#8221;, then there might be an issue with the synchronization process, and further investigation would be required.<\/p>\n<h2>Step 5: Configure Time Servers (Optional)<\/h2>\n<p>While the default NTP servers provided by Ubuntu are reliable, there might be scenarios where you&#8217;d want to use specific NTP servers, perhaps for regional accuracy or due to corporate policies. In this step, we&#8217;ll walk you through how to specify custom NTP servers for your Ubuntu system.<\/p>\n<p>Open the systemd-timesyncd configuration file using a text editor like nano:<\/p>\n<pre>\r\nsudo nano \/etc\/systemd\/timesyncd.conf\r\n<\/pre>\n<p>Modify the NTP Settings:<\/p>\n<p>In the opened file, you&#8217;ll find lines starting with #NTP= and #FallbackNTP=. These are the settings for the primary and fallback NTP servers, respectively.<\/p>\n<p>For instance, if you want to use the NTP servers provided by Google and Cloudflare, you&#8217;d modify the lines as follows:<\/p>\n<pre>\r\nNTP=time.google.com time.cloudflare.com\r\nFallbackNTP=time1.google.com time1.cloudflare.com\r\n<\/pre>\n<p>Note: The # at the beginning of a line denotes a comment, so ensure you remove it to activate the line.<\/p>\n<p>Save and Exit. After making the changes, save and close the file. If you&#8217;re using nano, press CTRL + X, then Y, and finally Enter.<\/p>\n<p>For the changes to take effect, restart the systemd-timesyncd service:<\/p>\n<pre>\r\nsudo systemctl restart systemd-timesyncd\r\n<\/pre>\n<p>To ensure your system is now using the new NTP servers, you can check the synchronization status:<\/p>\n<pre>\r\ntimedatectl status\r\n<\/pre>\n<p>Under &#8220;NTP Servers&#8221; or &#8220;Servers&#8221;, you should see the servers you&#8217;ve just specified.<\/p>\n<h2>Commands Mentioned<\/h2>\n<ul>\n<li><span class=\"fw-bold\">timedatectl status<\/span> \u2013 Displays the current time settings and synchronization status.<\/li>\n<li><span class=\"fw-bold\">sudo apt install systemd-timesyncd<\/span> \u2013 Installs the systemd-timesyncd package.<\/li>\n<li><span class=\"fw-bold\">sudo systemctl enable systemd-timesyncd<\/span> \u2013 Enables the systemd-timesyncd service to start on boot.<\/li>\n<li><span class=\"fw-bold\">sudo nano \/etc\/systemd\/timesyncd.conf<\/span> \u2013 Edits the configuration file for systemd-timesyncd.<\/li>\n<\/ul>\n<h2>FAQ<\/h2>\n<ol itemscope itemtype=\"https:\/\/schema.org\/FAQPage\">\n<li itemscope itemprop=\"mainEntity\" itemtype=\"https:\/\/schema.org\/Question\">\n<p class=\"fw-bold\" itemprop=\"name\">Why is time synchronization important?<\/p>\n<p itemprop=\"acceptedAnswer\" itemscope itemtype=\"https:\/\/schema.org\/Answer\">\n                <span itemprop=\"text\">Time synchronization ensures that server operations and applications run smoothly. Accurate timekeeping prevents issues like log discrepancies, application malfunctions, and data inconsistencies.<\/span>\n            <\/p>\n<\/li>\n<li itemscope itemprop=\"mainEntity\" itemtype=\"https:\/\/schema.org\/Question\">\n<p class=\"fw-bold\" itemprop=\"name\">What is systemd-timesyncd?<\/p>\n<p itemprop=\"acceptedAnswer\" itemscope itemtype=\"https:\/\/schema.org\/Answer\">\n                <span itemprop=\"text\">`systemd-timesyncd` is a lightweight service that synchronizes the system clock across the network. It comes pre-installed with many Ubuntu distributions and is part of the systemd suite.<\/span>\n            <\/p>\n<\/li>\n<li itemscope itemprop=\"mainEntity\" itemtype=\"https:\/\/schema.org\/Question\">\n<p class=\"fw-bold\" itemprop=\"name\">Can I specify my own NTP servers?<\/p>\n<p itemprop=\"acceptedAnswer\" itemscope itemtype=\"https:\/\/schema.org\/Answer\">\n                <span itemprop=\"text\">Yes, you can specify your preferred NTP servers in the `\/etc\/systemd\/timesyncd.conf` configuration file under the `NTP` and `FallbackNTP` settings.<\/span>\n            <\/p>\n<\/li>\n<li itemscope itemprop=\"mainEntity\" itemtype=\"https:\/\/schema.org\/Question\">\n<p class=\"fw-bold\" itemprop=\"name\">How often does systemd-timesyncd synchronize the time?<\/p>\n<p itemprop=\"acceptedAnswer\" itemscope itemtype=\"https:\/\/schema.org\/Answer\">\n                <span itemprop=\"text\">`systemd-timesyncd` uses a dynamic polling interval, which means it adjusts the frequency based on the stability of the time source. Initially, it might sync more frequently, but as the time source proves stable, the intervals become longer.<\/span>\n            <\/p>\n<\/li>\n<li itemscope itemprop=\"mainEntity\" itemtype=\"https:\/\/schema.org\/Question\">\n<p class=\"fw-bold\" itemprop=\"name\">Do I need an internet connection for time synchronization?<\/p>\n<p itemprop=\"acceptedAnswer\" itemscope itemtype=\"https:\/\/schema.org\/Answer\">\n                <span itemprop=\"text\">For NTP-based synchronization, an active internet connection is required to reach the NTP servers. However, if the system is part of a local network with an internal NTP server, it can sync with that without internet access.<\/span>\n            <\/p>\n<\/li>\n<\/ol>\n<h2>Conclusion<\/h2>\n<p>Ensuring that your Ubuntu system&#8217;s time is synchronized is a fundamental step for any server or desktop setup. By following the steps outlined in this guide, you&#8217;ve equipped your system with the tools it needs to maintain accurate timekeeping.<\/p>\n<p>Remember, accurate time synchronization is just one piece of the puzzle. If you&#8217;re looking to host applications or websites, don&#8217;t forget to explore the <a href=\"https:\/\/webhostinggeeks.com\/best\/dedicated-hosting\/\">best dedicated servers<\/a> and <a href=\"https:\/\/webhostinggeeks.com\/best\/vps-hosting\/\">best VPS hosting<\/a> options to ensure optimal performance and reliability.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Time synchronization is a crucial aspect for many server operations and applications. Ensuring that your Ubuntu server or desktop system is synchronized with accurate time sources prevents a myriad of&#8230;<\/p>\n","protected":false},"author":6,"featured_media":20150,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"wds_primary_category":0,"footnotes":""},"categories":[1073],"tags":[1610,1837,1856],"class_list":["post-20144","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-ubuntu","tag-ntp","tag-time","tag-ubuntu"],"_links":{"self":[{"href":"https:\/\/webhostinggeeks.com\/howto\/wp-json\/wp\/v2\/posts\/20144","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/webhostinggeeks.com\/howto\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/webhostinggeeks.com\/howto\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/webhostinggeeks.com\/howto\/wp-json\/wp\/v2\/users\/6"}],"replies":[{"embeddable":true,"href":"https:\/\/webhostinggeeks.com\/howto\/wp-json\/wp\/v2\/comments?post=20144"}],"version-history":[{"count":0,"href":"https:\/\/webhostinggeeks.com\/howto\/wp-json\/wp\/v2\/posts\/20144\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/webhostinggeeks.com\/howto\/wp-json\/wp\/v2\/media\/20150"}],"wp:attachment":[{"href":"https:\/\/webhostinggeeks.com\/howto\/wp-json\/wp\/v2\/media?parent=20144"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/webhostinggeeks.com\/howto\/wp-json\/wp\/v2\/categories?post=20144"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/webhostinggeeks.com\/howto\/wp-json\/wp\/v2\/tags?post=20144"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}