NTP Server Setup: Time synchronization
Network Time Protocol (NTP) is a networking protocol for clock synchronisation between computer systems over packet-switched, variable-latency data networks. In operation since before 1985, NTP is one of the oldest Internet protocols in use. NTP was originally designed by David L. Mills of the University of Delaware, who still develops and maintains it with a team of volunteers.
Time Servers and NTP serve are widely used to synchronize the time on computer networks. NTP provides the ability to access time servers, organize the time synchronization subnetNTP Time Servers and adjust the local clock in each participating subnet computer. Typically, NTP provides accuracies of between 1 and 50 milliseconds depending on the time source and network paths.
FreeBSD:
Network Time Protocol (NTP) by default comes inbox of the OS.
The configuration file locates in /etc/ntp.conf
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
server 0.europe.pool.ntp.org server 2.europe.pool.ntp.org server ntp0.fau.de server ntp.time.in.ua server ntp.nasa.gov # default is to ignore everything restrict default ignore # allow localhost restrict 127.0.0.1 # allow servers from whom get the information restrict 0.europe.pool.ntp.org noquery notrap restrict 2.europe.pool.ntp.org noquery notrap restrict ntp0.fau.de noquery notrap restrict ntp.time.in.ua noquery notrap restrict ntp.nasa.gov noquery notrap # allow localnetwork to get time, no modifications and traps restrict 10.10.1.0 mask 255.255.0.0 nomodify notrap nopeer restrict 192.168.1.1 mask 255.255.0.0 nomodify notrap nopeer # in case of no internet shows stratum 5 by default server 127.127.1.1 fudge 127.127.1.1 stratum 5 # logs and drift files driftfile /var/db/ntp.drift logfile /var/log/ntp.log |
CentOS:
Network Time Protocol (NTP) by default comes inbox of the OS.
The configuration file locates in /etc/ntp.conf
The configuration file is the same to Debian and Ubuntu, see below.
Debian, Ubuntu:
Network Time Protocol (NTP) by default doesn’t comes inbox of the OS. So we need to install it:
1 2 |
# apt-get update # apt-get install ntp |
As far as you machine is to become server there is no need to left ntpdate, as it may run on the same port as ntpd and make mess.
1 |
# apt-get remove ntpdate |
After you ntpd has been installed configuration file must be edited. By default config locates in /etc/ntp.conf
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
statistics loopstats peerstats clockstats filegen loopstats file loopstats type day enable filegen peerstats file peerstats type day enable filegen clockstats file clockstats type day enable # drift file driftfile /var/lib/ntp/ntp.drift logfile /var/log/ntp.log # server list server 0.debian.pool.ntp.org server 1.debian.pool.ntp.org server 2.debian.pool.ntp.org server 3.debian.pool.ntp.org server 0.europe.pool.ntp.org server 2.europe.pool.ntp.org server ntp0.fau.de server ntp.time.in.ua server ntp.nasa.gov # Use Ubuntu's ntp server as a fallback. server ntp.ubuntu.com # allow localhost restrict 127.0.0.1 # default is to ignore everything restrict default ignore # allow servers to sync with restrict 0.europe.pool.ntp.org noquery notrap restrict 2.europe.pool.ntp.org noquery notrap restrict ntp0.fau.denoquery notrap restrict ntp.time.in.ua noquery notrap restrict ntp.nasa.gov noquery notrap restrict 0.debian.pool.ntp.org noquery notrap restrict 1.debian.pool.ntp.org noquery notrap restrict 2.debian.pool.ntp.org noquery notrap restrict 3.debian.pool.ntp.org noquery notrap # allow localnetwork to get time, no modifications and traps restrict 10.135.0.0 mask 255.255.0.0 nomodify notrap # in case of no internet shows stratum 5 by default server 127.127.1.1 fudge 127.127.1.1 stratum 5 |
Useful commands to check your NTP server:
shows status without dns resolv:
1 |
# ntpq -pn |
shows peers:
1 |
# ntpq -c lpeer |
shows connected computers to your server:
1 |
# ntpdc -c monlist |
NTP runs on UPD port 123; to check availability:
Debian, Ubuntu, CentOS:
1 |
# netstat -nlpu | grep 123 |
FreeBSD:
1 |
# sockstat | grep 123 |