NTP

Commands

  • Install NTP daemon: yum install ntp
  • Display the configuration file: cat /etc/ntp.conf
  • Query only (don’t set the clock): ntpdate -q pool.ntp.org
  • Set the date and time via NTP (ntpd daemon has to be stopped): ntpdate 0.centos.pool.ntp.org
  • Direct ntpdate to use an unprivileged port for outgoing packets (> 1023): ntpdate -u 0.centos.pool.ntp.org
  • Enable the debugging mode (do not adjust the local clock): ntpdate -d 0.centos.pool.ntp.org
  • Show network time synchronisation status: ntpstat
  • Print a list of the peers known to the server as well as a summary of their state (dotted-quad numeric format): ntpq -pn

Other useful commands

  • Display Hardware Clock: hwclock -r
  • Set the System Time from the Hardware Clock: hwclock -s
  • Set the Hardware Clock to the current System Time: hwclock -w
  • Set the Hardware Clock to the time given by the --date option: hwclock --set --date=”3/01/18 12:02:00”
  • How many seconds are since 1970-01-01 00:00:00 UTC: date +%s
  • Display the calendar for 2019: cal 2019

How to set Timezone

Centos / RHEL 5-6

rm /etc/localtime

ln -s /usr/share/zoneinfo/Europe/Bucharest /etc/localtime

date

Centos / RHEL 7

timedatectl list-timezones | grep Bucharest

timedatectl set-timezone Europe/Bucharest

ls -l /etc/localtime

date