Enjoy Slackware 15.0!
Differences
This shows you the differences between two versions of the page.
Both sides previous revision Previous revision Next revision | Previous revision | ||
howtos:network_services:ntp [2013/03/01 16:36 (UTC)] kikinovak Added a short explanation about problems with NFS and NIS when clients are out of sync |
howtos:network_services:ntp [2022/09/20 19:46 (UTC)] (current) metaed [Sources] tag to Slackware 15.0 and additional author |
||
---|---|---|---|
Line 2: | Line 2: | ||
====== Synchronize your network with NTP ====== | ====== Synchronize your network with NTP ====== | ||
- | NTP (//Network Time Protocol//) allows clock synchronization between computer systems. The following HOWTO describes: | + | NTP is the //Network Time Protocol//, used to synchronize host clocks to one |
+ | another. Your Slackware distribution comes with NTP preinstalled. | ||
- | * configuring an NTP server on Slackware Linux; | + | Your reasons for running |
- | * synchronizing client PCs with your local NTP server. | + | |
- | ===== Introduction ===== | + | * make timestamps in system logs agree with one other, to make sense of events recorded in multiple system logs |
+ | * enable software protocols and encryption that depend on accurate time, e.g., Kerberos or PCI | ||
+ | * prevent software build issues caused when your remote filesystem says your source file was modified in the future | ||
+ | * prevent issues with database software that cannot tolerate setting the host clock back in time | ||
+ | * know when to stop hacking and turn on the new //Star Trek: Picard// | ||
- | When several users manipulate shared data on different client PCs on a network, it's important that these machines are all synchronized. This is especially true if you share files over NFS, or if you use NIS for centralized authentication. You'll get all sorts of weird errors if your clocks are out of sync. Unfortunately, | + | Using NTP, your Slackware host can become any of the following: |
- | That's where NTP (//Network Time Protocol//) comes in handy. It allows networked machines | + | * An NTP //client//, that corrects its own host clock to match that of another host |
+ | * A // | ||
+ | * An NTP //server//, that shares its system time with other hosts | ||
+ | * A // | ||
- | * The '' | + | It is very common to operate NTP as both a server |
- | * This one-time-adjustment isn't sufficient for a server | + | words, your Slackware host can get accurate |
- | * The '' | + | Internet and then serve that time to hosts on your local network. |
- | It's considered good practice to use '' | + | <note important> |
+ | This HOWTO is based on Slackware version 15.0 and the NTP reference | ||
+ | implementation version 4.2.8 that comes with it. To check your Slackware | ||
+ | version see: " | ||
+ | Version]]" | ||
- | ===== Firewall considerations ===== | + | $ ntpd --version |
+ | ntpd 4.2.8p15@1.3728-o Fri May 21 19:02:16 UTC 2021 (1) | ||
+ | </ | ||
- | The NTP services uses UDP port 123. Open this port if you want to allow remote machines to connect to your NTP server. | + | ===== Access control ===== |
- | ===== Synchronize a LAN server or a public root server with an NTP server on the Internet | + | NTP uses UDP port 123. Open port 123 in your host firewall if you want to |
+ | allow other hosts to connect to your host. Open port 123 in your Internet | ||
+ | firewall if you want access to Internet time. | ||
- | Create | + | NTP uses the '' |
+ | restrictions by creating | ||
+ | a mini-firewall within NTP itself that drops inbound packets based on options | ||
+ | you choose. | ||
- | < | + | Please turn your attention to the ACL pre-supplied by Slackware in |
- | # touch /var/log/ntp.log | + | '' |
- | </ | + | |
- | Visit [[http:// | + | restrict default limited kod nomodify notrap nopeer noquery |
+ | restrict -6 default limited kod nomodify notrap nopeer noquery | ||
+ | restrict 127.0.0.1 | ||
+ | restrict | ||
- | Configure the NTP service by editing ''/ | + | This ACL prevents |
+ | (noquery). It drops all packets except requests for basic information (first | ||
+ | two lines). It makes an exception for packets that originate from your | ||
+ | Slackware host itself (last two lines). This exception is what lets you | ||
+ | control your own NTP service using the '' | ||
- | In the example below, the list of four servers | + | The second line is redundant and should be deleted. |
- | < | + | If you want to use the public NTP server pool, you must add a line to relax |
- | # /etc/ntp.conf | + | the ACL restrictions enough to allow peering with associations. Add a |
+ | '' | ||
- | driftfile / | + | restrict source limited kod nomodify notrap noquery |
- | logfile / | + | |
- | server 0.fr.pool.ntp.org | + | If you want to allow devices on your network (or anywhere you like) to get |
- | server 1.fr.pool.ntp.org | + | time from this host, you must add a line to relax these restrictions to permit |
- | server 2.fr.pool.ntp.org | + | clients. Add a '' |
- | server 3.fr.pool.ntp.org | + | and/or network(s) that are allowed to get time. If your local network is |
+ | '' | ||
- | server 127.127.1.0 | + | restrict 172.16.0.0 mask 255.255.0.0 limited kod nomodify notrap nopeer |
- | fudge 127.127.1.0 stratum 10 | + | |
- | restrict default nomodify nopeer notrap | + | To let you control your NTP service from your maintenance VLAN and not just |
- | restrict 127.0.0.1 mask 255.0.0.0 | + | the host itself, you might want to add the VLAN with no restrictions. |
- | </code> | + | Supposing the maintenance VLAN is '' |
- | Here's a little explanation for some options: | + | restrict 172.16.1.0 mask 255.255.255.0 |
- | * The ''fudge 127.127.1.10 stratum 10'' | + | If you want more sophisticated access control than what's described here, for |
- | * NTP has its own arsenal of rules to limit access to the service, which can be used independently from a firewall. The '' | + | example to encrypt traffic or let you authenticate for administration tasks |
- | * A '' | + | from any host, look into the secure authentication features of NTP. See: |
+ | " | ||
+ | Support]]" | ||
- | ==== Manage the NTP service | + | ===== Diagnostic logging ===== |
- | Before starting the service, proceed | + | NTP prefers |
+ | in NTP itself that can be used instead. Looking again at the preinstalled | ||
+ | Slackware ''/ | ||
+ | turned on: | ||
- | <code> | + | <note important> |
- | # ntpdate pool.ntp.org | + | |
- | </code> | + | Not recommended. If you use the alternate logging feature, you are also |
+ | responsible for managing the logfile so that it does not eventually consume | ||
+ | all the available space in the filesystem. Not having to do this is one of the | ||
+ | big advantages of using SYSLOG. | ||
+ | </note> | ||
- | < | + | It is simpler to delete the '' |
+ | SYSLOG package. Using SYSLOG, NTP logs warnings and errors | ||
+ | '' | ||
- | Activate | + | If you still want to use the alternate logging feature, be sure to create the |
+ | empty file and make it writable by the NTP daemon: | ||
- | < | + | |
- | # chmod +x /etc/rc.d/rc.ntpd | + | # chown ntp: |
- | </code> | + | |
- | Manage | + | ==== Filtering |
- | < | + | NTP lets you filter certain messages out of the log, based on the message' |
- | # /etc/rc.d/rc.ntpd start|stop|restart|status | + | '' |
- | </ | + | |
- | Now display the list of servers your machine is actually connected to: | + | clock peer sync sys |
- | < | + | and four types defined: |
- | # ntpq -p | + | |
- | remote | + | |
- | ============================================================================== | + | |
- | *panopea.unstabl 213.251.128.249 | + | |
- | +88-190-17-126.r 145.238.203.14 | + | |
- | +62.210.255.117 | + | |
- | -ntp.univ-poitie 145.238.203.10 | + | |
- | LOCAL(0) | + | |
- | </ | + | |
- | The little '' | + | info events status statistics |
- | <note tip>The first synchronization can take a few minutes, sometimes up to half an hour.</ | + | Because the preinstalled Slackware ''/ |
+ | filter, you get out-of-box behavior. NTP will pass messages that are tagged | ||
+ | with the '' | ||
+ | class. | ||
- | ===== Synchronize your client PC(s) with your local NTP server ===== | + | <note important> |
+ | The out-of-box behavior unfortunately filters the message associated with at | ||
+ | least one common fatal condition | ||
+ | clock offset exceeds its panic threshold). | ||
+ | </ | ||
- | In a LAN, it is considered good practice to synchronize only one machine - the server - with a public NTP server, and the client PCs with the local server. This saves bandwidth and takes some load off the public NTP servers. | + | If you want all available diagnostic messages logged, you should disable all |
+ | filtering by class or type in ''/ | ||
- | As above, proceed to an initial adjustment of the system clock: | + | logconfig =allall |
- | < | + | ===== Statistics gathering ===== |
- | # ntpdate pool.ntp.org | + | |
- | </ | + | |
- | Create an empty logfile: | + | NTP can keep a statistical record of its performance, |
+ | check the health of your NTP-managed clock. The preinstalled Slackware | ||
+ | ''/ | ||
- | < | + | statsdir |
- | # touch /var/log/ntp.log | + | |
- | </code> | + | |
- | Now configure NTP to synchronize with the LAN server. Replace | + | But to actually collect statistics, you must create |
+ | make it writable by the NTP daemon: | ||
- | < | + | # mkdir / |
- | # /etc/ntp.conf | + | # chown ntp: |
- | driftfile | + | and add a command to '' |
- | logfile / | + | collected. The most commonly analyzed record is NTP's system clock updates in |
+ | the '' | ||
- | server 192.168.2.1 | + | statistics loopstats |
- | server 127.127.1.0 | + | There are a total of eight recordtypes that NTP will keep. For information, |
- | fudge 127.127.1.0 stratum 10 | + | see: |
+ | " | ||
+ | Options]]" | ||
- | restrict default ignore | + | At the end of this HOWTO, there is an example of charting the loopstats using |
- | restrict 127.0.0.1 mask 255.0.0.0 | + | the preinstalled Slackware **gnuplot** package. |
- | restrict 192.168.2.1 mask 255.255.255.255 | + | |
- | </ | + | |
- | * The three '' | + | <note important> |
+ | As with the logfile, if you collect statistics, you are responsible | ||
+ | managing the statistics files so that they do not eventually consume all the | ||
+ | available space in the filesystem. | ||
+ | </ | ||
- | Activate and start the NTP service: | + | ===== Operating |
- | < | + | The preinstalled Slackware '' |
- | # chmod +x /etc/rc.d/rc.ntpd | + | would make NTP a client of the public NTP server pool, just commented out. |
- | # /etc/rc.d/rc.ntpd start | + | Here are the relevant lines: |
- | </ | + | |
- | As above, use the '' | + | <note important> |
+ | #server 0.pool.ntp.org iburst | ||
+ | #server 1.pool.ntp.org iburst | ||
+ | #server 2.pool.ntp.org iburst | ||
+ | #server 3.pool.ntp.org iburst | ||
+ | As of NTP 4, this is no longer the recommended way to use the public NTP pool. | ||
+ | </ | ||
+ | |||
+ | You should replace the multiple server commands with a single '' | ||
+ | command. The command that is equivalent to the lines above is: | ||
+ | |||
+ | pool pool.ntp.org | ||
+ | |||
+ | Remember that you must also add the '' | ||
+ | described in an earlier section for this to work. | ||
+ | |||
+ | <note important> | ||
+ | The NTP Pool Project formerly recommended using country-specific pools in the | ||
+ | '' | ||
+ | zones ... and even better time if you use the country zone". This is no longer | ||
+ | true. They now recommend looking up the global pool '' | ||
+ | that the global pool "will usually return IP addresses for servers in or close | ||
+ | to your country ... for most users this will give the best results" | ||
+ | </ | ||
+ | |||
+ | It's not safe to trust specific individual clocks in the public NTP pool. This | ||
+ | is why NTP looks at multiple clocks and compares them before it selects a | ||
+ | clock to synchronize with. It's important to configure the clock selection | ||
+ | process. Current best practice is to wait until at 3 of 4 public clocks | ||
+ | contacted agree about what time it is. Add the command: | ||
+ | |||
+ | tos minclock 4 minsane 3 | ||
+ | |||
+ | It's recommended to set NTP to associate with an odd number of pool clocks, | ||
+ | equal to at least // | ||
+ | calculate your target number of pool clocks as: | ||
+ | |||
+ | | // | ||
+ | |||
+ | (You can use a larger odd number if you wish, but 7 is adequate). | ||
+ | |||
+ | NTP counts every clock you declare explicitly in ''/ | ||
+ | pool clocks it discovers, against its // | ||
+ | with the right limit, take the number you just calculated, and add 1 for each | ||
+ | explicit clock declaration you have in '' | ||
+ | '' | ||
+ | just have the one '' | ||
+ | |||
+ | | // | ||
+ | |||
+ | and you should add the command: | ||
+ | |||
+ | tos maxclock 8 | ||
+ | |||
+ | You can easily double-check your clock associations using the command | ||
+ | |||
+ | # ntpq -n -p | ||
+ | |||
+ | and verify that the number of pool clocks is what you expected. | ||
+ | |||
+ | <note important> | ||
+ | The risk that you run if you don't set // | ||
+ | // | ||
+ | wrong at boot time and give you inaccurate time, or even panic and exit. | ||
+ | </ | ||
+ | |||
+ | ===== Correcting for a fast or slow hardware clock ===== | ||
+ | |||
+ | Any hardware clock runs a few parts per million too fast or too slow. Over | ||
+ | time, NTP automatically calculates what this error is and compensates for it. | ||
+ | It can also store its calculation in a file that it re-reads when restarted. | ||
+ | |||
+ | The preinstalled Slackware | ||
+ | command | ||
+ | |||
+ | driftfile / | ||
+ | |||
+ | ===== Operating NTP as a server ===== | ||
+ | |||
+ | Beyond access control, there is no configuration needed to let your NTP host | ||
+ | operate as a server and supply time to your other devices. | ||
+ | |||
+ | In fact, it is a good idea to make one host on your network the primary time | ||
+ | server, and configure your other devices to get time from it. This reduces | ||
+ | bandwidth on your uplink. Plus it reduces the load on the public NTP pool if | ||
+ | you are using it. | ||
+ | |||
+ | If you have client devices that are Slackware hosts, they should not use the | ||
+ | '' | ||
+ | primary local time host by IP address. Otherwise, they are configured much | ||
+ | like your primary time host. | ||
+ | |||
+ | You might want your other devices to stay synchronized with your primary time | ||
+ | host even when your uplink goes down. The way this used to work was by adding | ||
+ | your own hardware clock as a sort of " | ||
+ | keep your devices in synch with one another even without an uplink. This is | ||
+ | the approach taken by the preinstalled Slackware ''/ | ||
+ | |||
+ | <note important> | ||
+ | server 127.127.1.0 | ||
+ | fudge 127.127.1.0 stratum 10 | ||
+ | Use of this clock driver is no longer recommended. | ||
+ | </ | ||
+ | |||
+ | The local clock driver has been replaced by //Orphan Mode//. The commands | ||
+ | above should be changed to: | ||
+ | |||
+ | tos orphan 10 | ||
+ | |||
+ | Orphan mode is also useful in a closed environment, | ||
+ | installation, | ||
+ | clock and only want the devices on a network to agree on the time. It's less | ||
+ | less helpful when you want a timely reminder to watch //Star Trek: Picard//. | ||
+ | |||
+ | If you do run in a closed environment, | ||
+ | of your hardware clock against a true clock. You can make your own | ||
+ | observations of how fast or slow your hardware clock tends to drift, and | ||
+ | manually compensate using the command: | ||
+ | |||
+ | tinker freq NNN | ||
+ | |||
+ | where //NNN// is the observed frequency error of your hardware clock in parts | ||
+ | per million. This is mutually exclusive with the '' | ||
+ | will also have to take that command out. | ||
+ | |||
+ | ===== Startup ===== | ||
+ | |||
+ | At one time it was standard practice to use the '' | ||
+ | quick rough adjustment to the system clock and then start '' | ||
+ | this version of NTP that's no longer recommended. It is recommended instead to | ||
+ | start '' | ||
+ | option to set the time. | ||
+ | |||
+ | This is already what Slackware 15.0 is preconfigured to do. To have NTP run at | ||
+ | startup, make ''/ | ||
+ | |||
+ | # chmod 755 / | ||
+ | |||
+ | and then either reboot or start it manually: | ||
+ | |||
+ | # / | ||
+ | |||
+ | The script ''/ | ||
+ | is passed the '' | ||
+ | is already present in ''/ | ||
+ | |||
+ | pidfile / | ||
+ | |||
+ | You may have noticed that the pathnames disagree, and that's mildly | ||
+ | infuriating but makes no actual difference because ''/ | ||
+ | link to ''/ | ||
+ | |||
+ | System services that should wait to start until the clock is stable can be | ||
+ | preceded by the '' | ||
+ | you could conceivably edit the MariaDB section of ''/ | ||
+ | |||
+ | # Start the MariaDB database: | ||
+ | if [ -x / | ||
+ | / | ||
+ | / | ||
+ | fi | ||
+ | |||
+ | ===== Monitoring NTP ===== | ||
+ | |||
+ | You can review how the pool discovery process is working with the command | ||
+ | |||
+ | # ntpq -n -p | ||
+ | |||
+ | Here is some sample output: | ||
< | < | ||
- | # ntpq -p | ||
| | ||
============================================================================== | ============================================================================== | ||
- | *192.168.2.1 81.19.16.225 3 u | + | pool.ntp.org .POOL. |
- | LOCAL(0) | + | -50.205.244.37 |
+ | -65.100.46.166 | ||
+ | +162.159.200.123 10.15.13.87 | ||
+ | *108.61.73.243 | ||
+ | -216.229.0.50 129.7.1.66 | ||
+ | +162.159.200.1 | ||
+ | +69.164.203.231 | ||
</ | </ | ||
- | <note tip> | + | In a nutshell, this tells us we have 1 master pool source (type=" |
+ | peers (type " | ||
+ | |||
+ | * Our system peer (that we are getting our time from) is 108.61.73.243 (" | ||
+ | * We have three more peer candidates (" | ||
+ | * NTP is considering pruning three outliers (" | ||
+ | |||
+ | The '' | ||
+ | " | ||
+ | Options]]" | ||
+ | a brief explanation: | ||
+ | |||
+ | < | ||
+ | 59760 66558.710 0.000038135 4.882 0.000265925 0.027674 10 | ||
+ | 59760 68002.750 0.000538317 4.885 0.000305204 0.025906 10 | ||
+ | 59760 69002.727 0.000199760 4.885 0.000309570 0.024235 10 | ||
+ | 59760 69437.711 0.000656689 4.886 0.000331590 0.022673 10 | ||
+ | 59760 71213.750 0.000522794 4.890 0.000313766 0.021244 10 | ||
+ | 59760 73341.750 0.000484582 4.951 0.000293812 0.029264 10 | ||
+ | 59760 75485.750 0.000486984 5.011 0.000274837 0.034780 10 | ||
+ | 59760 76374.727 -0.000069057 5.011 0.000323638 0.032534 10 | ||
+ | 59760 77579.750 0.000202697 5.012 0.000317617 0.030434 10 | ||
+ | 59760 79162.710 -0.000183575 5.011 0.000326988 0.028471 10 | ||
+ | </ | ||
+ | |||
+ | ^ Column 1 | Modified Julian Date of the observation | | ||
+ | ^ Column 2 | Time since midnight (seconds) | | ||
+ | |||
+ | You can combine and convert these to a UNIX | ||
+ | system value for plotting, as shown below. | ||
+ | |||
+ | ^ Column 3 | Difference observed between your system clock and your time source (seconds) | | ||
+ | ^ Column 5 | Column 3's jitter | | ||
+ | |||
+ | ^ Column 4 | Difference between your system clock frequency and the time source frequency (parts per million) | | ||
+ | ^ Column 6 | Column 4's jitter | | ||
+ | |||
+ | Here is a sample **gnuplot** program that charts recent loop statistics. | ||
+ | |||
+ | <file gnuplot> | ||
+ | #! / | ||
+ | |||
+ | # Input - four most recent loopstats files | ||
+ | filelist=system(" | ||
+ | |||
+ | # Output - X server | ||
+ | set terminal x11 | ||
+ | |||
+ | # Multiplot layout | ||
+ | set multiplot layout 2,1 | ||
+ | |||
+ | # Settings common to both graphs | ||
+ | set xlabel " | ||
+ | set xdata time | ||
+ | set xtics format " | ||
+ | set xzeroaxis linetype 1 | ||
+ | set grid | ||
+ | set errorbars small linecolor " | ||
+ | set key left bottom box | ||
+ | |||
+ | # Time Offset graph | ||
+ | set title 'local NTP clock: Time Offset' | ||
+ | set ylabel "Time Offset +/- RMS Jitter (ms)" | ||
+ | plot [] [] for [filename in filelist] filename \ | ||
+ | using (86400.0*($1-40587)+$2): | ||
+ | title filename \ | ||
+ | with yerrorbars pointtype 1 | ||
- | === Synchronizing at boot time === | + | # Frequency Offset graph |
+ | set title 'local NTP clock: Frequency Offset' | ||
+ | set ylabel " | ||
+ | plot [] [] for [filename in filelist] filename \ | ||
+ | using (86400.0*($1-40587)+$2): | ||
+ | title filename \ | ||
+ | with yerrorbars pointtype 1 | ||
+ | </ | ||
- | If instead of using a daemon, all you want to do is to synchronize time once per boot, it is possible to add the command '' | + | Sample output: |
- | + | {{ :howtos: | |
- | ~# cat / | + | |
- | #!/bin/sh | + | |
- | # | + | |
- | # / | + | |
- | # | + | |
- | # Put any local startup commands in here. Also, if you have | + | |
- | # anything that needs to be run at shutdown time you can | + | |
- | # make an / | + | |
- | # commands in there. | + | |
- | . | + | |
- | . | + | |
- | . | + | |
- | ntpd -qg & | + | |
====== Sources ====== | ====== Sources ====== | ||
* Originally written by [[wiki: | * Originally written by [[wiki: | ||
+ | * Performance monitoring section contributed by Dominik Drobek | ||
+ | * Rewritten and updated to current best practice by [[wiki: | ||
<!-- Please do not modify anything below, except adding new tags.--> | <!-- Please do not modify anything below, except adding new tags.--> | ||
<!-- You must remove the tag-word " | <!-- You must remove the tag-word " | ||
- | {{tag> | + | {{tag> |