Tuesday, 30 March 2010

Setting the correct time on Linux

Main ntp server I use: 0.uk.pool.ntp.org. Find one suitable for your location at http://www.pool.ntp.org/en/.  Internally hosts update from Brain or the Firewall.

Install ntp:
# yum install ntpd (Redhat / CentOS)
# apt-get install ntp (Debian)
Edit setup file to have server of
# vi /etc/ntp.conf
Force sync time:
# ntpdate -b <IP OF NTP SERVER>
Setup crontab to auto sync every 15 min:
# crontab -e
15 * * * * /usr/sbin/ntpd -q -u ntp:ntp
To set the timezone info edit the /etc/sysconfig/clock file and set the zone="Europe/London". Then link the localtime file to the correct zone with:
# ln -sf /usr/share/zoneinfo/Europe/London /etc/localtime
To manually set the date use this command:
# date --set HH:MM:SS