Linux NTP server

Source: Internet
Author: User
Tags local time

UTC: Coordinated World Time (English: Coordinated Universal time, Law: Temps universel coordonné), also known as the World Unification Times, world standard Time, international coordination time. The abbreviations in English (CUT) and French (TUC) are different, as compromises, referred to as UTC. Coordinated world time is based on the atomic time of the second length, at the moment as close to the world as possible when a measurement system.

Ntp:network Time Protocol

Software clock, 1970/1/1 0:0:0 total number of seconds calculated

Hardware clock, BIOS time

PORT:UDP 123 Port of the server host

Select multiple time server to do NtpServer, avoid the single unit is broken, the timing can not be synchronized

NTP hierarchy concept, the current host to the upper level to get time, down to provide time


Tzdata:time Zone Data provides the appropriate display format for each city

Configuration file:

/ETC/NTP.CONF Primary Unique configuration file

/usr/share/zoneinfo/* is provided by Tzdata and corresponds to the time format of each time zone

/etc/sysconfig/clock Setting the time zone, and whether to use the UTC clock configuration file

/etc/localtime the time profile on the local side, the timezone specified in the clock will be/usr/share/zoneinfo/

Copy the time profile in the/etc/localtime

Common directives:

/bin/date for the modification and display of Linux software time

/sbin/hwclock is used to modify and display the BIOS time, usually after modifying the system time with date, and then using Hwclock to synchronize to the BIOS.

/usr/sbin/ntpdate Client Time Correction tool

/USR/SBIN/NTPD provides NTP services

Example: Migrating to the United States, how to modify time

1 Date Displays the current time, watch the time zone

2 Vim/etc/sysconfig/clock

Zone= "/america/new_york" Modify time zone to New York

3 Cp/usr/share/zoneinfo/america/new_york/etc/localtime copy New York time format pairs should be in local time profile

4 Date View time zone


Restrict [Your IP] mask [netmask_ip] [parameter]


Ignore rejects all

Nomodify client can connect calibration time, but cannot modify parameters of time server with NTPC,NTPQ

Noquery does not provide network school time

Notrap does not provide the ability to trap this remote event login

Notrust rejecting clients that are not authenticated

Special Note: If no parameters are added, no restrictions are set

server [IP or hostname] [prefer]

Set up an upper-level NTP server, prefer for priority use

Driftfile [Directories and archives that can be ntpd written]

The file needs to use the full path file name

Cannot be a link when

NTPD This daemon to have write permission

The value recorded in this file is: One out of 10,000 seconds

Keys [Keys_file]

The client can also authenticate with the key


Chkconfig ntpd on




Linux Manual school work, date, Hwclock


Date [option] [+format]

Date [-u] mmddhhmm[cc]

Hwclock [-RWS]

Network School Hours

ntpdate [-DV] [NTP Ip/hostname]

Ntpdate IP Address

Remember not to run the ntpdate command on NtpServer

The Ntpdate script is as follows:



# Chkconfig:-57 75

# Description:set the date and time via NTP


# provides:ntpdate

# Required-start: $network $local _fs $remote _fs

# Should-start: $syslog $named

# Short-description:set the date and time via NTP

# Description:ntpdate sets the local clock by polling NTP servers


# Source function library.

. /etc/init.d/functions

# Source Networking configuration.

. /etc/sysconfig/network





Start () {

["$EUID"! = "0"] && Exit 4

["$NETWORKING" = "no"] && exit 1

[-x/usr/sbin/ntpdate] | | Exit 5

[-f/etc/sysconfig/ntpdate] | | Exit 6

. /etc/sysconfig/ntpdate

[-F $ntpstep] && tickers=$ (sed ' s/#.*//' $ntpstep) | | tickers=

if! echo "$tickers" | Grep-qi ' [a-z0-9] ' && [-f $ntpconf]; Then

# step-tickers doesn ' t specify a server,

# Use servers from ntp.conf instead

tickers=$ (awk ' $1== ' Peer ' | | $1== "Server" {print $ $ntpconf | \

Egrep-v ' 127\.127\. [0-9]+\. [0-9]+ ')


if! echo "$tickers" | Grep-qi ' [a-z0-9] '; Then

echo $ "NTP server not specified in $ntpstep or $ntpconf"

Exit 6


Echo-n $ "$prog: Synchronizing with Time server:"

[-Z "$RETRIES"] && retries=2


While true; Do

/usr/sbin/ntpdate $OPTIONS $tickers &>/dev/null


[$RETVAL-eq 0] | | [$retry-ge "$RETRIES"] && break

Sleep $[10 * (1 << $retry)]

retry=$[$retry + 1]


[$RETVAL-eq 0] && Success | | Failure


If [$RETVAL-eq 0]; Then

Touch $lockfile

["$SYNC _hwclock" = "yes"] && \

Action $ "Syncing hardware clock to system time" \



Return $RETVAL


Status () {

[-F $lockfile] | | Return 3


Stop () {

["$EUID"! = "0"] && Exit 4

Rm-f $lockfile


# See how we were called.

Case "$" in















echo $ "Usage: $ {start|stop|status|restart|force-reload}"

Exit 2


This article is from the IT Network Tanuvi blog, be sure to keep this source

Linux NTP server

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.