Wednesday, January 22, 2014

NTP server and client configuration On Linux

## Set timezone using /etc/localtime configuration file [any Linux distro]

Often /etc/localtime is a symlink to the file localtime or to the correct time zone file in the system time zone directory.
Generic procedure to change timezone

Change directory to /etc
# cd /etc

Create a symlink to file localtime:
# ln -sf /usr/share/zoneinfo/EST localtime

OR some distro use /usr/share/zoneinfo/dirname/zonefile format (Red hat and friends)
# ln -sf /usr/share/zoneinfo/EST localtime

OR if you want to set up it to IST (Asia/Calcutta):
# ln -sf /usr/share/zoneinfo/Asia/Calcutta localtime

Please mote that in above example you need to use directory structure i.e. if you want to set the timezone to Calcutta (India) which is located in the Asia directory you will then have to setup using as above.

Use date command to verify that your timezone is changed:
$ date

How to set date/time permanently on Centos/RH/Fedora

First you need to ssh to the server and be root and then do these step by step:

1. Set the date/time following instructions at http://www.cyberciti.biz/faq/howto-set-date-time-from-linux-command-prompt/
# date -s "2 OCT 2006 18:00:00"

2. Set the proper Timezone for your area, see http://www.cyberciti.biz/faq/howto-linux-unix-change-setup-timezone-tz-variable/
# cd /etc
# ln -sf /usr/share/zoneinfo/EST localtime

3. Set it to the BIOS for permanent stamp, see http://linux.about.com/library/cmd/blcmdl8_hwclock.htm
# /sbin/hwclock --systohc


# Minute   Hour   Day of Month       Month          Day of Week        Command   
# (0-59)  (0-23)     (1-31)    (1-12 or Jan-Dec)  (0-6 or Sun-Sat)               
    0        2          12             *               0,6           /usr/bin/find

NTP Sync:
=========
On Server:
==========

service ntpd stop

/etc/ntp.conf
#server 0.pool.ntp.org
#server 1.pool.ntp.org
#server 2.pool.ntp.org
#server 3.pool.ntp.org

server  127.127.1.0     # local clock
fudge   127.127.1.0 stratum 10

service ntpd start

On Client:
==========
ntpdate -du <ServerIP>

ntpq -p <ServerIP>

echo '30 * * * * root /usr/sbin/ntpd -q -u ntp:ntp' > /etc/cron.d/ntpdntos

No comments:

Post a Comment