Difference between revisions of "Linux ntp"
Jump to navigation
Jump to search
Line 68: | Line 68: | ||
Fri 4 Sep 14:50:26 UTC 2020 | Fri 4 Sep 14:50:26 UTC 2020 | ||
</source> | </source> | ||
= <code>chrony</code> = | = <code>chrony</code> = |
Revision as of 17:45, 4 September 2020
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.
Update NTP managment system
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
hwclock --show hwclock -r hwclock --show --utc hwclock --systohc #sync system clock -> hardware clock hwclock --hctosys #sync hardware clock -> system clock
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 time zone
- Set timezone (Ubuntu 16.04)
sudo timedatectl set-timezone Europe/London
- Set time zone on Amazon Linux, to UTC
cat /etc/*rel* NAME="Amazon Linux AMI" VERSION="2014.09" $ date Fri 4 Sep 15:32:12 BST 2020 # Do not change the 'UTC=true' entry to another value. This entry is for the hardware clock, # and does not need to be adjusted when you're setting a different time zone on your instance. sudo vi /etc/sysconfig/clock # edit if needed ZONE="UTC" UTC=true # List available time zones ls -l /etc/localtime # Symlink (cp) 'localtime' file with content of desired TZ sudo mv /etc/localtime /etc/localtime.original sudo ln -s /usr/share/zoneinfo/UTC /etc/localtime date # no reboot required Fri 4 Sep 14:50:26 UTC 2020
chrony
Every pre-RHEL8 uses ntpd
but recently chrony
becomes a standard time client.
# RHEL8 sudo yum -y install chrony sudo systemctl start chronyd && sudo systemctl enable chronyd sudo vi /etc/chrony.conf # add NTP server, service restart is required to apply changes
Show time sources
chronyc sources -v .-- Source mode '^' = server, '=' = peer, '#' = local clock. / .- Source state '*' = current synced, '+' = combined , '-' = not combined, | / '?' = unreachable, 'x' = time may be in error, '~' = time too variable. || .- xxxx [ yyyy ] +/- zzzz || Reachability register (octal) -. | xxxx = adjusted offset, || Log2(Polling interval) --. | | yyyy = measured offset, || \ | | zzzz = estimated error. || | | \ MS Name/IP address Stratum Poll Reach LastRx Last sample =============================================================================== ^* 169.254.169.123 3 6 17 12 +15us[ +57us] +/- 320us ^- tbag.heanet.ie 1 6 17 13 -3488us[-3446us] +/- 1779us ^- ec2-12-34-231-12.eu-west- 2 6 17 13 +893us[ +935us] +/- 7710us ^? 2a05:d018:c43:e312:ce77:6 0 6 0 10y +0ns[ +0ns] +/- 0ns ^? 2a05:d018:d34:9000:d8c6:5 0 6 0 10y +0ns[ +0ns] +/- 0ns ^? tshirt.heanet.ie 0 6 0 10y +0ns[ +0ns] +/- 0ns ^? bray.walcz.net 0 6 0 10y +0ns[ +0ns] +/- 0ns
References
Ntp Ubuntu wiki