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 potential issues, from log discrepancies to application malfunctions.
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’re running a web server or any online application, accurate timekeeping is essential.
Let’s get started.
Step 1: Check the Current Time Settings
Before making any changes, it’s a good practice to check the current system time and the hardware clock time.
timedatectl status
This command will display the current time, time zone, and synchronization status.
For example:
dimitri@webhostinggeeks:~# timedatectl status Local time: Mon 2023-10-23 10:10:13 UTC Universal time: Mon 2023-10-23 10:10:13 UTC RTC time: Mon 2023-10-23 10:10:14 Time zone: Etc/UTC (UTC, +0000)
Step 2: Install systemd-timesyncd (If Not Installed)
While systemd-timesyncd is pre-installed on many Ubuntu systems, if it’s not on yours, you can easily install it:
sudo apt update sudo apt install systemd-timesyncd
Step 3: Enable and Start the Service
Activate the systemd-timesyncd service to start on boot and immediately start it:
sudo systemctl enable systemd-timesyncd sudo systemctl start systemd-timesyncd
Step 4: Verify Synchronization Status
After starting the service, you can verify that it’s actively synchronizing:
timedatectl status
Look for “NTP synchronized” or “System clock synchronized” to be set to “yes”.
dimitri@webhostinggeeks:~# timedatectl status Local time: Mon 2023-10-23 10:10:13 UTC Universal time: Mon 2023-10-23 10:10:13 UTC RTC time: Mon 2023-10-23 10:10:14 Time zone: Etc/UTC (UTC, +0000) System clock synchronized: yes systemd-timesyncd.service active: yes
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 “no”, then there might be an issue with the synchronization process, and further investigation would be required.
Step 5: Configure Time Servers (Optional)
While the default NTP servers provided by Ubuntu are reliable, there might be scenarios where you’d want to use specific NTP servers, perhaps for regional accuracy or due to corporate policies. In this step, we’ll walk you through how to specify custom NTP servers for your Ubuntu system.
Open the systemd-timesyncd configuration file using a text editor like nano:
sudo nano /etc/systemd/timesyncd.conf
Modify the NTP Settings:
In the opened file, you’ll find lines starting with #NTP= and #FallbackNTP=. These are the settings for the primary and fallback NTP servers, respectively.
For instance, if you want to use the NTP servers provided by Google and Cloudflare, you’d modify the lines as follows:
NTP=time.google.com time.cloudflare.com FallbackNTP=time1.google.com time1.cloudflare.com
Note: The # at the beginning of a line denotes a comment, so ensure you remove it to activate the line.
Save and Exit. After making the changes, save and close the file. If you’re using nano, press CTRL + X, then Y, and finally Enter.
For the changes to take effect, restart the systemd-timesyncd service:
sudo systemctl restart systemd-timesyncd
To ensure your system is now using the new NTP servers, you can check the synchronization status:
timedatectl status
Under “NTP Servers” or “Servers”, you should see the servers you’ve just specified.
Commands Mentioned
- timedatectl status – Displays the current time settings and synchronization status.
- sudo apt install systemd-timesyncd – Installs the systemd-timesyncd package.
- sudo systemctl enable systemd-timesyncd – Enables the systemd-timesyncd service to start on boot.
- sudo nano /etc/systemd/timesyncd.conf – Edits the configuration file for systemd-timesyncd.
FAQ
-
Why is time synchronization important?
Time synchronization ensures that server operations and applications run smoothly. Accurate timekeeping prevents issues like log discrepancies, application malfunctions, and data inconsistencies.
-
What is systemd-timesyncd?
`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.
-
Can I specify my own NTP servers?
Yes, you can specify your preferred NTP servers in the `/etc/systemd/timesyncd.conf` configuration file under the `NTP` and `FallbackNTP` settings.
-
How often does systemd-timesyncd synchronize the time?
`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.
-
Do I need an internet connection for time synchronization?
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.
Conclusion
Ensuring that your Ubuntu system’s time is synchronized is a fundamental step for any server or desktop setup. By following the steps outlined in this guide, you’ve equipped your system with the tools it needs to maintain accurate timekeeping.
Remember, accurate time synchronization is just one piece of the puzzle. If you’re looking to host applications or websites, don’t forget to explore the best dedicated servers and best VPS hosting options to ensure optimal performance and reliability.