Difference between revisions of "Linux ntp"
Line 3: | Line 3: | ||
= Time manipulation and troubleshooting = | = Time manipulation and troubleshooting = | ||
'''timedatectl''' - In recent Ubuntu releases timedatectl replaces ntpdate. By default timedatectl syncs the time once on boot and later on uses socket activation to recheck once network connections become active. | |||
'''timesyncd''' - In recent Ubuntu releases timesyncd replaces the client portion of ntpd. By default timesyncd regularly checks and keeps the time in sync. It also stores time updates locally, so that after reboots monotonically advances if applicable. | |||
New NTP packages | New NTP packages | ||
Line 29: | Line 20: | ||
Sync hardware clock -> system clock | Sync hardware clock -> system clock | ||
hwclock --hctosys | hwclock --hctosys | ||
Display time details (Ubuntu 16.04) | |||
$ timedatectl | |||
Local time: Tue 2017-08-08 09:31:14 UTC | |||
Universal time: Tue 2017-08-08 09:31:14 UTC | |||
RTC time: Tue 2017-08-08 09:31:14 | |||
Time zone: Etc/UTC (UTC, +0000) | |||
Network time on: yes | |||
NTP synchronized: no | |||
RTC in local TZ: no | |||
Set timezone (Ubuntu 16.04) | |||
sudo timedatectl set-timezone Europe/London | |||
Force ntpd to sync time | |||
sudo systemctl stop ntp.service | |||
sudo ntpd -gq #-gq tells the ntp daemon to correct the time regardless of the offset (g) and exit immediately (q) after setting the time; it can take 5-10 sec | |||
sudo systemctl start ntp.service #you should notice in timedatectl output ''NTP synchronized: yes'' | |||
Troubleshooting NTP server | Troubleshooting NTP server |
Revision as of 13:44, 3 September 2017
Declaimer
Most these commands have been used on Ubuntu systems.
Time manipulation and troubleshooting
timedatectl - In recent Ubuntu releases timedatectl replaces ntpdate. By default timedatectl syncs the time once on boot and later on uses socket activation to recheck once network connections become active.
timesyncd - In recent Ubuntu releases timesyncd replaces the client portion of ntpd. By default timesyncd regularly checks and keeps the time in sync. It also stores time updates locally, so that after reboots monotonically advances if applicable.
New NTP packages
sudo update-rc.d -f ntpdate remove -remove deprecated ntpdate service sudo apt-get install ntp
Show ntp logs
cat /var/log/messages | grep ntp
Show RTC (Real Time Clock) hardware clock
sudo hwclock --show hwclock -r hwclock --show --utc
Sync system clock -> hardware clock
sudo hwclock --systohc
Sync hardware clock -> system clock
hwclock --hctosys
Display time details (Ubuntu 16.04)
$ timedatectl Local time: Tue 2017-08-08 09:31:14 UTC Universal time: Tue 2017-08-08 09:31:14 UTC RTC time: Tue 2017-08-08 09:31:14 Time zone: Etc/UTC (UTC, +0000) Network time on: yes NTP synchronized: no RTC in local TZ: no
Set timezone (Ubuntu 16.04)
sudo timedatectl set-timezone Europe/London
Force ntpd to sync time
sudo systemctl stop ntp.service sudo ntpd -gq #-gq tells the ntp daemon to correct the time regardless of the offset (g) and exit immediately (q) after setting the time; it can take 5-10 sec sudo systemctl start ntp.service #you should notice in timedatectl output NTP synchronized: yes
Troubleshooting NTP server
sudo tcpdump port 123 #enable ntp packet logging timedatectl status ntpdc -p #offset in seconds ntpq -p #offset in milliseconds
ntpq --numeric --peers #show peers (time providers) ntpq -c lpeer #show peers (time providers) ntpq -d <time_server> #debugging mode (not sure if will update local clock) ntpdate -d <time_server> #debugging mode, in which ntpdate will go through all the steps, but doesn't adjust the local clock ntpstats ntpdate -s a_stratum_1_server_address
ntpdc -c loopinfo #will display the combined offset in seconds, as seen at the last poll ntpdc -c kerninfo #will display the current remaining correction, just as ntptime does
Show difference/offset between local and remote time server
ntpdate -q <time_server> #just query NTP server and it will display time difference/offset
References
Ntp Ubuntu wiki