How to configure NTP servers in Linux?



  • To configure two ntp servers:

    On each of the two ntp servers, add "server 127.127.1.0 # local clock" to the file /etc/ntp.conf:

    # vi /etc/ntp.conf
    

    server 127.127.1.0 # local clock

    Set the date/time on both servers (replace xxxxxx with the appropriate value):

    # date xxxxxx
    

    Switch ntp ON for init levels 3 & 5

    # chkconfig --level 35 ntpd on
    

    Manually start ntp:

    # service ntpd start
    

    On all clients:
    Create a cron job to make the clients synchronise with the ntp servers every hour:

    # crontab -e
    

    00 0-23 * * * /usr/sbin/ntpupdate <ip_address1> <ip_address2>

    Where <ip_address1> <ip_address2> are the IP addresses of the two ntp servers you have just configured.

    It is also possible to use the hostname of the two ntp servers as opposed to their IP addresses as above, in case IP addresses change. For example:

    # crontab -e
    

    00 0-23 * * * /usr/sbin/ntpupdate <hostname1> <hostname2>

    To check status of ntp:

    # ntpq -p
    

    Many other ntpq options are available:

    # ntpq
    ntpq> help
    Commands available:
    addvars        associations   authenticate   cl             clearvars
    clocklist      clockvar       cooked         cv             debug
    delay          exit           help           host           hostnames
    keyid          keytype        lassociations  lopeers        lpassociations
    lpeers         mreadlist      mreadvar       mrl            mrv
    ntpversion     opeers         passociations  passwd         peers
    poll           pstatus        quit           raw            readlist
    readvar        rl             rmvars         rv             showv
    
    
    # ntpq -p -n
         remote           refid      st t when poll reach   delay   offset  jitter
    ==============================================================================
    *127.127.1.0     LOCAL         10 l    3   64  377    0.000    0.000   0.001
    

Log in to reply
 

© Lightnetics 2024