Ubuntu to sync with NTP Server

To configure your Ubuntu 20.04 system to synchronize its date and time using an NTP (Network Time Protocol) server, follow the steps below. Ubuntu 20.04 uses systemd-timesyncd for time synchronization by default, but you can also install and use chrony or ntp if necessary.

Here are the steps to set the time using NTP:

1. Verify systemd-timesyncd is active

By default, Ubuntu 20.04 uses systemd-timesyncd for time synchronization. First, make sure it is running:

timedatectl status

You should see output indicating that time synchronization is enabled and the NTP server being used:

Local time: Wed 2024-09-18 10:32:54 UTC Universal time: Wed 2024-09-18 10:32:54 UTC RTC time: Wed 2024-09-18 10:32:54 Time zone: Etc/UTC (UTC, +0000) System clock synchronized: yes NTP service: active RTC in local TZ: no

If NTP service is active, you don't need to install anything further.


2. Configure NTP Servers

To configure the NTP servers used by systemd-timesyncd, edit the configuration file:

sudo nano /etc/systemd/timesyncd.conf

In the [Time] section, specify the NTP servers:

[Time] NTP=ntp.ubuntu.com 0.pool.ntp.org 1.pool.ntp.org FallbackNTP=2.pool.ntp.org 3.pool.ntp.org

Save the file and exit (Ctrl+X, then Y, and Enter).

3. Restart systemd-timesyncd

After modifying the NTP configuration, restart the systemd-timesyncd service to apply the changes:

sudo systemctl restart systemd-timesyncd

4. Check Time Synchronization Status

To verify that the time is being synchronized with the NTP server, run:

timedatectl status

You should see that the system clock is synchronized and the NTP service is active.






5. Optional: Install chrony or ntp (alternative to systemd-timesyncd)

If you prefer to use chrony or ntp for NTP synchronization instead of systemd-timesyncd, you can install and configure them:

Install and configure chrony:

sudo apt update sudo apt install chrony

Edit the chrony configuration file to specify the NTP servers:

sudo nano /etc/chrony/chrony.conf

Look for the lines starting with pool or server and modify them as needed:

pool 0.pool.ntp.org iburst pool 1.pool.ntp.org iburst

Restart chrony:

sudo systemctl restart chrony

Check its status:

chronyc tracking

Install and configure ntp (if needed):

sudo apt update sudo apt install ntp

Modify the NTP server list in the configuration file:

sudo nano /etc/ntp.conf

Look for the lines starting with server and update them to use the desired NTP servers:

server 0.pool.ntp.org iburst server 1.pool.ntp.org iburst

Restart the ntp service:

sudo systemctl restart ntp

6. Verify NTP Sync

Run the following command to check the status of NTP synchronization:

ntpq -p

This will list the NTP peers your system is synchronizing with and show their statuses.

Now, your Ubuntu 20.04 system will follow the NTP server for date and time synchronization.

Ulasan

Catatan popular daripada blog ini

SISTEM PENGOPERASIAN KOMPUTER (OS)

JENIS-JENIS SISTEM PENGOPERASIAN KOMPUTER

JENIS - JENIS ARAHAN SQL