it is pretty much important to have a correct time on your system.

a lot of services might depend on it – certificates might be valid/invalid depending on your system’s time.

if cmos batteries get empty – your system will probably boot up with an incorrect date and time – which results into firefox not accepting a lot of SSL certificates.

check if your timezone is correct:

timedatectl; # show currently set timezone
timedatectl list-timezones; # list all available timezones: (works Centos7, Debian8, Suse12)

if not:

timedatectl set-timezone America/Chicago; # permanently change timezone (works Centos7, Debian8, Suse12)

more info on linux timezones and files -> http://dwaves.de/2017/06/07/linux-time-zones-change-timezone/

manual mode – no internet

if your linux system is not connected to the internet. you can still adjust your time like this:

date +%Y%m%d -s „20081128“; # set date

date +%T -s „10:13:13“; # set time

(creditz)

manual mode – with internet

ntpd is the ntp service running in the background using UDP port 123.

manually syncing with given time-server:

apt-get install ntpdate; # debian8 install the software needed
yum install ntpdate; # centos7
# suse12 has it preinstalled
service ntp stop; # debian8 stop ntp service if installed
service ntpd stop; # centos7, suse12 stop ntp service if installed
ntpdate uk.pool.ntp.org; # manually synchronise with the given timeserver
12 Jun 15:12:20 ntpdate[5510]: adjust time server 188.39.213.7 offset -0.003300 sec

(you could also use 1.pool.ntp.org or see this list of european timeservers)

update cmos-clock to internet time:

# on old debian
ntpdate && hwclock -w; # get time from servers and update hardware clock

# on new debian (very confusing for me as well)
ntpd -q -g; # update time from server
hwclock --systohc; # sync system-time to cmos-hardware-realtime-clock (BIOS)

you know should have an accurate clock set.

how to check if „time is right“:

you can fiddle around with aliases and refresh output time on your terminal every second… then compare it to:

https://www.uhrzeit.org/atomuhr.php

alias datum="date '+DATE: %Y-%m-%d TIME: %H:%M:%S'"; # set an bash-alias, you can put it at the end of /etc/bash.bashrc
datum; # should give you:
DATE: 2015-06-19 TIME: 10:36:06; # IF THIS TIME IS STILL NOT CORRECT! YOU HAVE SET THE WRONG TIME-ZONE ;)

alias loopdatum="while true ; do datum ; sleep 1 ; clear; done # display the current date and time every second, run this to compare time between two systems"

loopdatum; # will show current date and time and update every second

ntp internet time sync service

to automate this process – install and config :

apt-get update; # debian8, update software package list
apt-get install ntp; # debian8, install tools to update the time from timeservers

yum install ntp; # centos7 redhat
# suse12 has it preinstalled but not started per default?

# edit network time protocol config
vim /etc/ntp.conf

# add those if you are in Germany (de)
# if you are in China use (cn)
# check out: http://www.pool.ntp.org/en/ for more servers
server 0.de.pool.ntp.org
server 1.de.pool.ntp.org
server 2.de.pool.ntp.org
server 3.de.pool.ntp.org

ESC :wq # vim save and quit

service ntp restart; # debian8
service ntpd restart; # centos7, suse12
ntpdc -c sysinfo; # query the service
system peer: stratum2-4.ntp.techfak.net
system peer mode: client
leap indicator: 00
stratum: 3
precision: -21
root distance: 0.03188 s
root dispersion: 0.02847 s
reference ID: [129.70.132.37]
reference time: dce92737.5c99f8b6 Mon, Jun 12 2017 16:44:07.361
system flags: auth monitor ntp kernel stats
jitter: 0.001678 s
stability: 0.000 ppm
broadcastdelay: 0.000000 s
authdelay: 0.000000 s

drift

The units for the drift file are „PPM“, or „parts per million“. Your clock will drift due to fluctuations in the frequency oscillating the quartz crystal on your motherboard. A fluctuation of just 0.001% (0.00001, or 10 PPM) means losing or gaining about 1 second per day. NTP has finer grained control than that, so we look at errors of margin using 0.0001% (0.000001, or 1 PPM). Thus:

  • 1 PPM = 1 part per million = 1 microsecond per second = 3.6ms per hour = 86.4ms per day

Thus, my drift file shows the value of „2.643“ which means my clock is off by 2.643 parts per million, which means it’s currently off at 228.3552ms per day.

(creditz)

root@Debian8:~# find / -name *drift*
/var/lib/ntp/ntp.drift

# contains one number

12.249

suse12:~ # find / -name *drift*

# is actually an empty directory
/var/lib/ntp/drift/

[root@CentOS7 ~]# find / -name *drift*
/var/lib/chrony/drift

# contains two numbers

-6.192941 0.864764

ntpdc

„ntpdc is used to query the ntpd daemon about its current state and to request changes in that state.“

ntpdc.man.txt

[root@CentOS7 ~]# ntpdc
ntpdc> ?
ntpdc commands:
addpeer controlkey fudge keytype quit timeout
addrefclock ctlstats help listpeers readkeys timerstats
addserver debug host loopinfo requestkey traps
addtrap delay hostnames memstats reset trustedkey
authinfo delrestrict ifreload monlist reslist unconfig
broadcast disable ifstats passwd restrict unrestrict
clkbug dmpeers iostats peers showpeer untrustedkey
clockstat enable kerninfo preset sysinfo version
clrtrap exit keyid pstats sysstats

ntpdc> sysinfo
system peer: fry.celeborn.de
system peer mode: client
leap indicator: 00
stratum: 3
precision: -22
root distance: 0.02762 s
root dispersion: 0.02179 s
reference ID: [5.9.39.18]
reference time: dce927b8.1ff64375 Mon, Jun 12 2017 16:46:16.124
system flags: auth ntp kernel stats
jitter: 0.000916 s
stability: 0.000 ppm
broadcastdelay: 0.000000 s
authdelay: 0.000000 s

ntpdc> peers
remote local st poll reach delay offset disp
=======================================================================
=a.fraho.eu 172.20.0.28 2 128 377 0.01935 -0.002890 0.05922
=panel1.web2.clu 172.20.0.28 3 128 263 0.02681 -0.002592 0.26141
*fry.celeborn.de 172.20.0.28 2 128 377 0.01898 -0.001185 0.06007
=schubhart.de 172.20.0.28 2 128 377 0.01965 -0.000614 0.05923

ntpdc> monlist
***Server reports data not found
ntpdc>

root@Debian8:~# ntpdc
ntpdc> ?
ntpdc commands:
addpeer controlkey fudge keytype quit timeout
addrefclock ctlstats help listpeers readkeys timerstats
addserver debug host loopinfo requestkey traps
addtrap delay hostnames memstats reset trustedkey
authinfo delrestrict ifreload monlist reslist unconfig
broadcast disable ifstats passwd restrict unrestrict
clkbug dmpeers iostats peers showpeer untrustedkey
clockstat enable kerninfo preset sysinfo version
clrtrap exit keyid pstats sysstats

ntpdc> sysinfo
system peer: stratum2-4.ntp.techfak.net
system peer mode: client
leap indicator: 00
stratum: 3
precision: -21
root distance: 0.03188 s
root dispersion: 0.03285 s
reference ID: [129.70.132.37]
reference time: dce92737.5c99f8b6 Mon, Jun 12 2017 16:44:07.361
system flags: auth monitor ntp kernel stats
jitter: 0.000397 s
stability: 0.000 ppm
broadcastdelay: 0.000000 s
authdelay: 0.000000 s

ntpdc> peers
remote local st poll reach delay offset disp
=======================================================================
=www.kashra.com 172.20.0.12 2 64 377 0.03763 -0.010891 0.04443
*stratum2-4.ntp. 172.20.0.12 2 64 377 0.03146 -0.004789 0.06937
=beatrix.stbuehl 172.20.0.12 2 64 377 0.02075 -0.004044 0.04964
=vel.itat.io 172.20.0.12 2 64 377 0.01944 -0.004490 0.05391

ntpdc> monlist
remote address port local address count m ver rstr avgint lstint
===============================================================================
www.kashra.com 123 172.20.0.12 13 4 4 1d0 40 50
vel.itat.io 123 172.20.0.12 12 4 4 1d0 43 51
beatrix.stbuehler.de 123 172.20.0.12 13 4 4 1d0 40 55
stratum2-4.ntp.techfak 123 172.20.0.12 13 4 4 1d0 40 56
ntpdc>

 

manpages:

ntpdate.man.txt

ntpdate sets the local date and time by polling the Network Time Protocol (NTP) server(s) given as the server arguments to determine the correct time.

ntpd.man.txt

The ntpd program is an operating system daemon which sets and maintains the system time of day in synchronism with Internet standard time servers.

ntpq.man.txt

The ntpq utility program is used to monitor NTP daemon ntpd operations and determine performance

ntptrace.man.txt (debian8 and suse12, not available under centos7)

ntptrace determines where a given Network Time Protocol (NTP) server gets its time from, and follows the chain of NTP servers back to their master time source.

under centos7, redhat it needs to be installed first

yum install ntp-perl; #

example output:

suse12:~ # ntptrace
localhost: stratum 16, offset 0.000000, synch distance 0.004860

root@Debian8:# ntptrace
localhost: stratum 3, offset -0.002552, synch distance 0.022178
ntp.uni-oldenburg.de: stratum 2, offset 0.002457, synch distance 0.004666
192.53.103.108: timed out, nothing received
***Request timed out

errors:

ntptrace
ntpq: read: Connection refused

this is because ntp service is not running

service ntp start; # debian8

service ntpd start; # centos7, suse12

findings:

debian8 and centos7 pretty much got the same time… but suse12 was lagging 10 seconds behind? 😀

ntpdate also reports this but does not update the hardware clock?

suse12:/# ntpdate 0.pool.ntp.org
12 Jun 15:55:45 ntpdate[6539]: 5.45.108.27 rate limit response from server.
12 Jun 15:56:00 ntpdate[6539]: step time server 82.100.248.10 offset 10.733941 sec

Links:

http://dwaves.de/2017/06/07/linux-time-zones-change-timezone/

http://dwaves.de/2017/06/12/iconv-allows-file-conversion-between-charsets-encodings-utf-8-t-iso-8859-1/

http://wiki.hetzner.de/index.php/Uhrzeit_synchronisieren_mit_NTP/en

http://www.pool.ntp.org/en/use.html

http://www.pool.ntp.org/zone/europe

 

admin