Difference between revisions of "CLI - NTP"

 
(5 intermediate revisions by the same user not shown)
Line 1: Line 1:
 
__FORCETOC__
 
__FORCETOC__
 
=== ntp ===
 
=== ntp ===
The Network Time Protocol (NTP) is a networking protocol for clock synchronization between computer systems over packet-switched, variable-latency data networks.<ref>https://en.wikipedia.org/wiki/Network_Time_Protocol</ref> ''Note that the system has already an NTP server that is "ntp.ubuntu.com".''
+
The Network Time Protocol (NTP) is a networking protocol for clock synchronization between computer systems over packet-switched, variable-latency data networks.<ref>https://en.wikipedia.org/wiki/Network_Time_Protocol</ref>  
 +
{{note|Note that the system has already an NTP server that is "ntp.ubuntu.com".}}
 
==== Verifying NTP ====
 
==== Verifying NTP ====
 
To verify the NTP servers, enter <code>show ntp server</code> in the user mode. If none of the servers exists, it indicates that there are no NTP servers except for the default.
 
To verify the NTP servers, enter <code>show ntp server</code> in the user mode. If none of the servers exists, it indicates that there are no NTP servers except for the default.
Line 35: Line 36:
 
<pre>
 
<pre>
 
LYSH@MyHostName# configure
 
LYSH@MyHostName# configure
configure# ntp add asia.pool.ntp.org
+
LYSH@MyHostName(config)# ntp add asia.pool.ntp.org
configure# exit
+
LYSH@MyHostName(config)# exit
 
LYSH@MyHostName# show ntp servers
 
LYSH@MyHostName# show ntp servers
 
NTP Servers                  : asia.pool.ntp.org
 
NTP Servers                  : asia.pool.ntp.org
Line 44: Line 45:
 
<pre>
 
<pre>
 
LYSH@MyHostName# show ntp status
 
LYSH@MyHostName# show ntp status
systemd-timesyncd.service - Network Time Synchronization
+
systemd-timesyncd.service - Network Time Synchronization
 
     Loaded: loaded (/lib/systemd/system/systemd-timesyncd.service; enabled; vendor preset: enabled)
 
     Loaded: loaded (/lib/systemd/system/systemd-timesyncd.service; enabled; vendor preset: enabled)
     Active: active (running) since Tue 2021-04-27 13:10:36 KST; 12s ago
+
     Active: active (running) since Tue 2021-05-18 14:01:39 KST; 18s ago
 
       Docs: man:systemd-timesyncd.service(8)
 
       Docs: man:systemd-timesyncd.service(8)
   Main PID: 18321 (systemd-timesyn)
+
   Main PID: 1050237 (systemd-timesyn)
     Status: "Initial synchronization to time server 157.119.108.165:123 (asia.pool.ntp.org)."
+
     Status: "Idle."
 
       Tasks: 2 (limit: 9387)
 
       Tasks: 2 (limit: 9387)
     Memory: 1.6M
+
     Memory: 1.3M
 
     CGroup: /system.slice/systemd-timesyncd.service
 
     CGroup: /system.slice/systemd-timesyncd.service
             └─18321 /lib/systemd/systemd-timesyncd
+
             └─1050237 /lib/systemd/systemd-timesyncd
 +
 
 
</pre>
 
</pre>
  
Line 59: Line 61:
 
<pre>
 
<pre>
 
LYSH@MyHostName# configure
 
LYSH@MyHostName# configure
configure# ntp delete asia.pool.ntp.org
+
LYSH@MyHostName(config)# ntp delete asia.pool.ntp.org
configure# exit
+
LYSH@MyHostName(config)# exit
 
</pre>
 
</pre>
  
Line 67: Line 69:
 
<pre>
 
<pre>
 
LYSH@MyHostName# configure
 
LYSH@MyHostName# configure
configure# ntp disable
+
LYSH@MyHostName(config)# ntp disable
 
Local time: Tue 2021-04-27 10:26:03 KST
 
Local time: Tue 2021-04-27 10:26:03 KST
 
           Universal time: Tue 2021-04-27 01:26:03 UTC
 
           Universal time: Tue 2021-04-27 01:26:03 UTC
Line 77: Line 79:
 
</pre>
 
</pre>
  
You can also enable it. Note that the status of the "System clock synchronized" may show "inactive" for a while after enabling the NTP and the status will be changed to "active" in few seconds.
+
You can also enable it. The status of the "System clock synchronized" may show "inactive" for a while after enabling the NTP and the status will be changed to "active" in few seconds.
 
<pre>
 
<pre>
 
LYSH@MyHostName# configure
 
LYSH@MyHostName# configure
configure# ntp enable
+
LYSH@MyHostName(config)# ntp enable
 
   Local time: Tue 2021-04-27 10:26:03 KST
 
   Local time: Tue 2021-04-27 10:26:03 KST
 
           Universal time: Tue 2021-04-27 01:26:03 UTC
 
           Universal time: Tue 2021-04-27 01:26:03 UTC
Line 90: Line 92:
 
</pre>
 
</pre>
  
=== datetime ===
 
To show the system time and date, enter the <code>show datetime</code> command.
 
<pre>
 
LYSH@MyHostName# show datetime
 
              Local time: Tue 2021-04-27 13:32:46 KST
 
          Universal time: Tue 2021-04-27 04:32:46 UTC
 
                RTC time: Tue 2021-04-27 04:32:46
 
                Time zone: Asia/Seoul (KST, +0900)
 
System clock synchronized: yes
 
              NTP service: active
 
          RTC in local TZ: no
 
</pre>
 
 
 
To change the system time and date, enter the <code>datetime {format}</code>. The format must be 'yyyy-mm-dd hh24:mi:ss'.<br>
 
Note that if you manually change the system time and date while the NTP is enabled, you encounter the "''Failed to set time: Automatic time synchronization is enabled''" error. Therefore you need to disable the NTP before configuring the system time and date manually.
 
LYSH@MyHostName# configure
 
configure# datetime 2021-04-27 13:00:00
 
              Local time: Tue 2021-04-27 13:00:00:49 KST
 
          Universal time: Tue 2021-04-27 04:00:00 UTC
 
                RTC time: Tue 2021-04-27 04:00:00
 
                Time zone: Asia/Seoul (KST, +0900)
 
System clock synchronized: yes
 
              NTP service: active
 
          RTC in local TZ: no
 
  
 
=== References ===
 
=== References ===

Latest revision as of 10:48, 28 January 2022

ntp

The Network Time Protocol (NTP) is a networking protocol for clock synchronization between computer systems over packet-switched, variable-latency data networks.[1]

Note that the system has already an NTP server that is "ntp.ubuntu.com".

Verifying NTP

To verify the NTP servers, enter show ntp server in the user mode. If none of the servers exists, it indicates that there are no NTP servers except for the default.

LYSH@MyHostName# show ntp servers

To show the status of the Time synchronization, show ntp status in the user mode. It shows the status of, when, and where the time was synchronized.

LYSH@MyHostName# show ntp status
● systemd-timesyncd.service - Network Time Synchronization
     Loaded: loaded (/lib/systemd/system/systemd-timesyncd.service; enabled; vendor preset: enabled)
     Active: active (running) since Tue 2021-04-27 13:12:30 KST; 10s ago
       Docs: man:systemd-timesyncd.service(8)
   Main PID: 18992 (systemd-timesyn)
     Status: "Connecting to time server [2001:67c:1560:8003::c8]:123 (ntp.ubuntu.com)."
      Tasks: 2 (limit: 9387)
     Memory: 1.6M
     CGroup: /system.slice/systemd-timesyncd.service
             └─18992 /lib/systemd/systemd-timesyncd

You can also verify the Time synchronization by using the show datetime commmand.

LYSH@MyHostName# show datetime
               Local time: Tue 2021-04-27 13:32:46 KST
           Universal time: Tue 2021-04-27 04:32:46 UTC
                 RTC time: Tue 2021-04-27 04:32:46
                Time zone: Asia/Seoul (KST, +0900)
System clock synchronized: yes
              NTP service: active
          RTC in local TZ: no

add / delete

You can configure the NTP servers. If you add an NTP server, the system synchronizes the time using added NTP server. If the Time synchronization failed from a server, the system tries to the next server.

LYSH@MyHostName# configure
LYSH@MyHostName(config)# ntp add asia.pool.ntp.org
LYSH@MyHostName(config)# exit
LYSH@MyHostName# show ntp servers
NTP Servers                   : asia.pool.ntp.org

You can see the status of the time synchronization to a time server by the show ntp status command. If the "Status" shows "Idle", it indicates the system couldn't synchronize to one of the NTP servers.

LYSH@MyHostName# show ntp status
 systemd-timesyncd.service - Network Time Synchronization
     Loaded: loaded (/lib/systemd/system/systemd-timesyncd.service; enabled; vendor preset: enabled)
     Active: active (running) since Tue 2021-05-18 14:01:39 KST; 18s ago
       Docs: man:systemd-timesyncd.service(8)
   Main PID: 1050237 (systemd-timesyn)
     Status: "Idle."
      Tasks: 2 (limit: 9387)
     Memory: 1.3M
     CGroup: /system.slice/systemd-timesyncd.service
             └─1050237 /lib/systemd/systemd-timesyncd

To remove one of the NTP servers, enter the ntp delete {ntp-server-name} in the configuration mode.

LYSH@MyHostName# configure
LYSH@MyHostName(config)# ntp delete asia.pool.ntp.org
LYSH@MyHostName(config)# exit

enable / disable

You can disable the System clock synchronizing using the NTP server.

LYSH@MyHostName# configure
LYSH@MyHostName(config)# ntp disable
Local time: Tue 2021-04-27 10:26:03 KST
           Universal time: Tue 2021-04-27 01:26:03 UTC
                 RTC time: Tue 2021-04-27 01:26:03
                Time zone: Asia/Seoul (KST, +0900)
System clock synchronized: no
              NTP service: inactive
          RTC in local TZ: no

You can also enable it. The status of the "System clock synchronized" may show "inactive" for a while after enabling the NTP and the status will be changed to "active" in few seconds.

LYSH@MyHostName# configure
LYSH@MyHostName(config)# ntp enable
  Local time: Tue 2021-04-27 10:26:03 KST
           Universal time: Tue 2021-04-27 01:26:03 UTC
                 RTC time: Tue 2021-04-27 01:26:03
                Time zone: Asia/Seoul (KST, +0900)
  System clock synchronized: active
              NTP service: active
          RTC in local TZ: no


References