Linux menu

Saturday, September 20, 2014

How to Configure NTP Server and Client In Linux


The Network time Protocol (NTP) is an internet protocol which is useful to synchronize system clocks to
coordinate with Universal Time (UTC) over the network. One System can be a NTP Server or NTP client. NTP client uses the NTP protocol to synchronize its clock timing with NTP server which is sync with public internet which is widely available for NTP time synchronization purpose.

NTP Client --> Sync with NTP server --> Sync with Public Network

NTP clients can function with NTP servers in 3 ways:
  • in a client-server basis 
  • in a peer to peer mode 
  • sending the time using broadcast/multicast 
xnptd is daemon of NTP service. When xnptd starts, it will check the NTP configuration file /etc/ntp.conf to determine synchronization sources and also checks the frequency file /etc/ntp/drift which contains the latest estimate of clock frequency delay. If specified, it will also check the file /etc/ntp/keys which containing the authentication keys.

Important NTP files
Files
Descriptions
/etc/ntp.conf
Default configuration file.
/etc/ntp.drift
Default drift file which contains latest estimate of clock frequency error. (i.e difference between your clock and the data provided by NTP server)
/etc/ntp.keys
Default key file which contains authentication keys

NTP Server Configuration Steps
Let we can configure NTP server with using the pubilc network NTP time synchronization services
which are following "server 3.in.pool.ntp.org , server 3.asia.pool.ntp.org, server 2.asia.pool.ntp.org"
bash-3.00# cp /etc/inet/ntp.server /etc/inet/ntp.conf
bash-3.00# vi /etc/inet/ntp.conf
Adding the NTP time synchronization servers
# Either a peer or server.  Replace "XType" with a value from the
# table above.
server 3.in.pool.ntp.org
server 3.asia.pool.ntp.org
server 2.asia.pool.ntp.org

broadcast 224.0.1.1 ttl 4

enable auth monitor
driftfile /var/ntp/ntp.drift
statsdir /var/ntp/ntpstats/
filegen peerstats file peerstats type day enable
filegen loopstats file loopstats type day enable
filegen clockstats file clockstats type day enable
then we have to create the drift file and start the NTP services
bash-3.00# touch /var/ntp/ntp.drift
bash-3.00#
bash-3.00# svcs ntp
STATE          STIME    FMRI
disabled       Jul_25   svc:/network/ntp:default
bash-3.00# svcadm enable svc:/network/ntp:default
bash-3.00#
bash-3.00# svcs ntp
STATE          STIME    FMRI
online       23:47:06 svc:/network/ntp:default
bash-3.00#
Now we can check the NTP service status by using ntpq command.
bash-3.00# ntpq -pn
     remote           refid      st t when poll reach   delay   offset    disp
==============================================================================
 224.0.1.1       0.0.0.0         16 u    -   64    0     0.00    0.000 16000.0
*120.88.47.10    128.4.1.1        2 u  481  512  377    28.06  -40.717    9.61
+220.130.158.72  220.130.158.70   2 u  507  512  375   121.20  -32.876   14.24
+78.111.50.52    212.87.0.71      3 u   47  512  277   222.41  -58.496    9.20
bash-3.00#
"*" indicates the server to which you are currently synchronized.
"+" indicates the server which take the leading role if the current server becomes unavailable for some reason. 
FieldsDescriptions
remoteThe IP address or DNS name of the remote server
refidAn identification of the reference clock and type
stThe "stratum" or level of the server: for almost all systems, 2 is great. Your local system will have a higher number.
tThe type of service. "I" indicates your local system or "u" indicates for communicating with remote servers
whenLast sync timing which is in seconds format,
pollCurrent polling interval in seconds, Note:- "when" should be no greater than "poll".
reachindicating whether responses have been received to your local server's eight most recent requests.The value starts at 0. If your local server is receiving responses to all its requests, it will go to 1, then 3, then 7.The display is in octal, so 377 is the maximum value
delayRecent average roundtrip time in milliseconds from request to response
offsetEstimated differential between your system clock and this time server's clock, in milliseconds
dispA measure of the variability of the delays between request and receipt of a response, in milliseconds
NTP client Configuration Steps
Let we can start the configuration for NTP client, First copy the ntp.client sources file as ntp.conf and add nfs server name
bash-3.00# cp /etc/inet/ntp.client /etc/inet/ntp.conf
bash-3.00# vi /etc/inet/ntp.conf
Create a drift file and start the ntp services
bash-3.00# touch /var/ntp/ntp.drift
bash-3.00#
bash-3.00# svcs ntp
STATE          STIME    FMRI
disabled       Jul_25   svc:/network/ntp:default
bash-3.00# svcadm enable svc:/network/ntp:default
bash-3.00#
bash-3.00#
Now we can see the status by executing ntpq -p command

No comments: