Linux: Time synchronization with NTP server

Correctly set time in computer systems allows for the correct operation of running programs and easy search of logs between different computer systems. If the time in each system is different, any log analyzes (e.g. for post-intrusion analysis) in your infrastructure will be difficult. The following NTP server time synchronization configuration will work on any modern Linux distribution that uses systemd.
We will use the command to verify the current time settings timedatectl.
user@linux :~ $ timedatectl Local time : Tue 2020 - 07 - 14 18 : 35 : 04 UTC Universal time : Tue 2020 - 07 - 14 18 : 35 : 04 UTC RTC time : Tue 2020 - 07 - 14 18 : 35 : 04 Time zone : Etc / UTC ( UTC , + 0000 ) System clock synchronized : yes NTP service : active RTC in local TZ : no
You may notice that the current time zone is set to Etc/UTC. The following command is used to display the available time zone names.
user@linux :~ $ timedatectl list - timezones Africa / Abidjan Africa / Accra Africa / Algiers Africa / Bissau Africa / Cairo Africa / Casablanca Africa / Ceuta (…)
In the case of Poland, the appropriate time zone is Europe/Warsaw. To change the settings, elevation of privileges is required, e.g. using sudo.
user@linux :~ $ sudo timedatectl set - timezone Europe / Warsaw user@linux :~ $ timedatectl Local time : Tue 2020 - 07 - 14 20 : 36 : 18 CEST Universal time : Tue 2020 - 07 - 14 18 : 36 : 18 UTC RTC time : Tue 2020 - 07 - 14 18 : 36 : 18 Time zone : Europe / Warsaw ( CEST , + 0200 ) System clock synchronized : yes NTP service : active RTC in local TZ : no
After changing the time zone, verify the configuration again with timedatectl. In my case, time synchronization with NTP servers is enabled by default. To enable or disable synchronization with an NTP server, use the command:
user@linux :~ $ sudo timedatectl set - ntp on user@linux :~ $ sudo timedatectl set - ntp off
To change the default NTP server, edit the configuration file and enter the time server addresses.
user@linux :~ $ sudo nano / etc / systemd / timesyncd . conf [ Time ] NTP = tempus1 . gum . gov . pl tempus2 . gum . gov . pl FallbackNTP = ntp . ubuntu . com
After configuring the new NTP servers, restart the time synchronization service and verify the synchronization status again.
user@linux :~ $ sudo systemctl restart systemd - timesyncd . service user@linux :~ $timedatectl ----
