Wednesday, November 19, 2008

Time synchronization in Linux

Date and time settings in Debian Linux

Set date and time approximately (optional step):

$ sudo su
# apt-get install ntpdate
# ntpdate ntp.cesnet.cz


Install NTP for higher precission with automatic time synchronization:

# apt-get install ntp ntp-server ntp-simple ntp-doc


Configure NTP for automatic time synchronization:
Open file /etc/ntp.conf

Add lines:

server clock1.zcu.cz
server clock2.zcu.cz
server ntp.cesnet.cz

Comment out everything except following directives:

driftfile, statsdir, statistics, filegen (more lines in sequence)


Start NTP server:

# /etc/init.d/ntp-server restart


Display current time settings:

# ntpq -p
- shows table of servers accessibility and accuracy
- main server is marked by star (*), else automatic synchronization does not work


Store date and time to hardware clock:

# /usr/sbin/ntpdate -s
# /sbin/hwclock --adjust
# /sbin/hwclock --systohc

No comments: