{"id":1021,"date":"2024-11-22T10:30:44","date_gmt":"2024-11-22T10:30:44","guid":{"rendered":"https:\/\/linuxresellerwebhosting.in\/blog\/?p=1021"},"modified":"2024-11-22T10:44:58","modified_gmt":"2024-11-22T10:44:58","slug":"time-synchronization-on-ubuntu-20","status":"publish","type":"post","link":"https:\/\/linuxresellerwebhosting.in\/blog\/time-synchronization-on-ubuntu-20\/","title":{"rendered":"Set Up Time Synchronization on Ubuntu 20.04"},"content":{"rendered":"<p id=\"introduction\">This article will explain how to set up Time Synchronization on Ubuntu 20.04 in command line.<\/p>\n<p>Accurate timekeeping is integral to modern software deployments. Without it, you may encounter data corruption, errors, and other issues that are difficult to debug. Time synchronization can help ensure your logs are being recorded in the correct order, and that database updates are appropriately applied.<\/p>\n<p>Fortunately, Ubuntu 20.04 has time synchronization built-in and activated by default using <code>systemd<\/code>\u2019s <code>timesyncd<\/code> service. In this article, you will practice some general time-related commands, verify that <code>timesyncd<\/code> is active, and install an alternate network time service.<\/p>\n<h2 id=\"prerequisites\"><span class=\"ez-toc-section\" id=\"Prerequisites\"><\/span>Prerequisites<span class=\"ez-toc-section-end\"><\/span><\/h2><div id=\"ez-toc-container\" class=\"ez-toc-v2_0_82_2 ez-toc-wrap-left counter-hierarchy ez-toc-counter ez-toc-light-blue ez-toc-container-direction\">\n<div class=\"ez-toc-title-container\">\n<span class=\"ez-toc-title-toggle\"><\/span><\/div>\n<nav><ul class='ez-toc-list ez-toc-list-level-1 ' ><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-1\" href=\"https:\/\/linuxresellerwebhosting.in\/blog\/time-synchronization-on-ubuntu-20\/#Prerequisites\" >Prerequisites<\/a><ul class='ez-toc-list-level-3' ><li class='ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-2\" href=\"https:\/\/linuxresellerwebhosting.in\/blog\/time-synchronization-on-ubuntu-20\/#Steps_to_setup_Time_Synchronization_on_Ubuntu\" >Steps to setup Time Synchronization on Ubuntu<\/a><ul class='ez-toc-list-level-4' ><li class='ez-toc-heading-level-4'><a class=\"ez-toc-link ez-toc-heading-3\" href=\"https:\/\/linuxresellerwebhosting.in\/blog\/time-synchronization-on-ubuntu-20\/#Controlling_timesyncd_with_timedatectl\" >Controlling timesyncd with timedatectl<\/a><\/li><\/ul><\/li><\/ul><\/li><\/ul><\/nav><\/div>\n\n<p>Before starting this tutorial, you will need an Ubuntu 20.04 server with a non-root, sudo-enabled user and a firewall, as described in this Ubuntu 20.04 server setup tutorial.<\/p>\n<h3><span class=\"ez-toc-section\" id=\"Steps_to_setup_Time_Synchronization_on_Ubuntu\"><\/span><a href=\"https:\/\/linuxresellerwebhosting.in\/blog\/time-synchronization-on-ubuntu-20\/\">Steps to setup Time Synchronization on Ubuntu<\/a><span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>To view the time on your server, you will use the command <code>date<\/code>. Any user can run this command to print out the date and time:<\/p>\n<pre>date<\/pre>\n<p>Typically, your server will generate an output with the default <em>UTC<\/em> time zone.<\/p>\n<pre>Fri Nov 20 13:55:20 UTC 2024<\/pre>\n<p>UTC is <em>Coordinated Universal Time<\/em>, the time at zero degrees longitude. While this may not reflect your current time zone, using Universal Time prevents confusion when your infrastructure spans multiple time zones.<\/p>\n<p>If you want to change your time zone, however, you can use the <code>timedatectl<\/code> command.<\/p>\n<p>First, run this command to generate a list of available time zones:<\/p>\n<pre>timedatectl list-timezones<\/pre>\n<p>A list of time zones will print to your screen. You can press SPACE to page down, and b to page up. Once you find the correct time zone, make note of it then type q to exit the list.<\/p>\n<p>Next, you can set the time zone with timedatectl set-timezone by replacing the highlighted portion with the time zone you found in the list. You\u2019ll need to use sudo with timedatectl to make this change:<\/p>\n<pre>sudo timedatectl set-timezone Asia\/Kolkata.<\/pre>\n<p>You can verify your changes by running <code>date<\/code> again:<\/p>\n<pre>Fri Nov 20 13:57:20 IST 2024<\/pre>\n<p>The time zone abbreviation will reflect the newly chosen value.<\/p>\n<h4 id=\"controlling-timesyncd-with-timedatectl\"><span class=\"ez-toc-section\" id=\"Controlling_timesyncd_with_timedatectl\"><\/span>Controlling timesyncd with timedatectl<span class=\"ez-toc-section-end\"><\/span><\/h4>\n<p>most network time synchronization was handled by the Network Time Protocol daemon or ntpd. This service connects to a pool of other NTP servers that provide it with constant and accurate time updates.<\/p>\n<p>But now with Ubuntu\u2019s default install, you can use timesyncd instead of ntpd. timesyncd works similarly by connecting to the same time servers, but is llightweight and more closely integrated with systemd on Ubuntu.<\/p>\n<p>You can query the status of timesyncd by running timedatectl with no arguments. You don\u2019t need to use sudo in this case:<\/p>\n<pre>timedatectl<\/pre>\n<p>This command prints out the local time, universal time (which may be the same as local time, if you didn\u2019t switch from the UTC time zone), and some network time status information. System clock synchronized: yes reflects that the time is successfully synced, and NTP service: active means that timesyncd is up and running.<\/p>\n<p>If your output shows that NTP service isn\u2019t active, turn it on with timedatectl:<\/p>\n<pre>sudo timedatectl set-ntp on<\/pre>\n<p><strong>Switching to ntpd for Time Synchronization on Ubuntu<\/strong><\/p>\n<p>timesyncd will work in most circumstances. There are instances, however, when an application may be sensitive to any disturbance with time. In this case, ntpd is an alternative network time service you can use. ntpd uses sophisticated techniques to constantly and gradually keep the system time on track.<\/p>\n<p>Before installing ntpd, you need to turn off timesyncd in order to prevent the two services from conflicting with one another. You can do this by disabling network time synchronization with the following command:<\/p>\n<pre>sudo timedatectl set-ntp no<\/pre>\n<p>Verify that time synchronization is disabled:<\/p>\n<pre>timedatectl<\/pre>\n<p>Check that your output reads NTP service: inactive.<\/p>\n<p>This means timesyncd has stopped. Now you\u2019re ready to install the ntp package with apt.<\/p>\n<p>First, run apt update to refresh your local package index:<\/p>\n<pre>sudo apt update<\/pre>\n<p>Then, run <code>apt install ntp<\/code> to install this package:<\/p>\n<pre>sudo apt install ntp<\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-1026 size-full\" src=\"https:\/\/linuxresellerwebhosting.in\/blog\/wp-content\/uploads\/2024\/11\/ntp-time-for-ubuntu-blog.png\" alt=\"Time Synchronization on Ubuntu\" width=\"1013\" height=\"667\" srcset=\"https:\/\/linuxresellerwebhosting.in\/blog\/wp-content\/uploads\/2024\/11\/ntp-time-for-ubuntu-blog.png 1013w, https:\/\/linuxresellerwebhosting.in\/blog\/wp-content\/uploads\/2024\/11\/ntp-time-for-ubuntu-blog-300x198.png 300w, https:\/\/linuxresellerwebhosting.in\/blog\/wp-content\/uploads\/2024\/11\/ntp-time-for-ubuntu-blog-768x506.png 768w\" sizes=\"auto, (max-width: 1013px) 100vw, 1013px\" \/><\/p>\n<p>&nbsp;<\/p>\n<p><code>ntpd<\/code> will begin automatically after your installation completes. You can verify that everything is working correctly by querying <code>ntpd<\/code> for status information:<\/p>\n<pre>ntpq -p<\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-1025 size-full\" src=\"https:\/\/linuxresellerwebhosting.in\/blog\/wp-content\/uploads\/2024\/11\/ntp-blog.png\" alt=\"Time Synchronization on Ubuntu\" width=\"685\" height=\"161\" srcset=\"https:\/\/linuxresellerwebhosting.in\/blog\/wp-content\/uploads\/2024\/11\/ntp-blog.png 685w, https:\/\/linuxresellerwebhosting.in\/blog\/wp-content\/uploads\/2024\/11\/ntp-blog-300x71.png 300w\" sizes=\"auto, (max-width: 685px) 100vw, 685px\" \/><\/p>\n<p><code>ntpq<\/code> is a query tool for <code>ntpd<\/code>. The <code>-p<\/code> flag requests information about the NTP servers (or <strong>p<\/strong>eers) <code>ntpd<\/code> is connected to. Your output will be slightly different but will list the default <a href=\"https:\/\/ubuntu.com\/\" target=\"_blank\" rel=\"noopener\">Ubuntu<\/a> pool servers plus a few others. Remember, it can take a few minutes for <code>ntpd<\/code> to establish connections.<\/p>\n<p><strong>Conclusion<\/strong><\/p>\n<p>In this article, you\u2019ve successfully viewed Time Synchronization on Ubuntu .The system time, changed time zones, worked with Ubuntu\u2019s default timesyncd service, and installed ntpd. If you have advanced timekeeping needs, you can reference the official NTP documentation, and also take a look at the NTP Pool Project, a global group of volunteers providing much of the world\u2019s NTP infrastructure.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>This article will explain how to set up Time Synchronization on Ubuntu 20.04 in command line. Accurate timekeeping is integral<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"colormag_page_container_layout":"default_layout","colormag_page_sidebar_layout":"default_layout","footnotes":""},"categories":[2,21],"tags":[],"class_list":["post-1021","post","type-post","status-publish","format-standard","hentry","category-linux","category-troubleshoot"],"_links":{"self":[{"href":"https:\/\/linuxresellerwebhosting.in\/blog\/wp-json\/wp\/v2\/posts\/1021","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/linuxresellerwebhosting.in\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/linuxresellerwebhosting.in\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/linuxresellerwebhosting.in\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/linuxresellerwebhosting.in\/blog\/wp-json\/wp\/v2\/comments?post=1021"}],"version-history":[{"count":10,"href":"https:\/\/linuxresellerwebhosting.in\/blog\/wp-json\/wp\/v2\/posts\/1021\/revisions"}],"predecessor-version":[{"id":1033,"href":"https:\/\/linuxresellerwebhosting.in\/blog\/wp-json\/wp\/v2\/posts\/1021\/revisions\/1033"}],"wp:attachment":[{"href":"https:\/\/linuxresellerwebhosting.in\/blog\/wp-json\/wp\/v2\/media?parent=1021"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/linuxresellerwebhosting.in\/blog\/wp-json\/wp\/v2\/categories?post=1021"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/linuxresellerwebhosting.in\/blog\/wp-json\/wp\/v2\/tags?post=1021"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}