Linux Network Time Protocol (NTP)

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
in this lesson we're going to discuss synchronizing time with the network Time Protocol or NTP now NTP is currently the best option available for synchronizing network time among multiple Network hosts now you can use the net date command to do the same thing but NTP is a better option now like net date the NTP Protocol gets its time from a network time provider and then it sets this local system time to whatever time it got from that time provider however NTP is better because it manages time in a much cleaner fashion the net date does NTP will adjust the time in a very gentle manner if there's a big differential between the time providers time and the time on your local system NTP will gradually adjust the time on your local system in small increments until the time eventually becomes synchronized so in order to synchronize time using NTP we install and configure the NTP daemon notice that where you use the NTP daemon on both the time provider and on the time consumer and that's a very important thing to remember when you run the NTP daemon a given system can function as both a time provider and as a time consumer at the same time so because of this the system on the right can get its time from the system on the left but then some other system somewhere else could get its time from the system on the right because it can function both as a time consumer and as a time provider for other systems the NTP protocol operates over IP port 123 it's a really easy port to remember one two three what happens is that the NTP daemon on the time consumer sends a time synchronization request to the ntpd daemon on the time provider the time provider then sends its time to the consumer and then the system time on the consumer is adjusted according to the NTP algorithm and remember that because of the way NTP works it does not immediately set the local time to the same time as a time provider but instead it gradually adjusts it until they both come eventually into synchronization and unlike net date this does not happen with one single command instead the ntpd Damons on these two systems will communicate back and forth with each other multiple times per day to keep time and sync and that's another benefit of using ntpd over net date remember net date distant ones does one quick time change and that's it unless you run it with a cron job it never checks to see that the systems are in synchronization again using ntpd on the other hand these two systems continually talk to each other saying what time is that okay that's time I got okay I'll set my time to that and because of this it prevents drift from happening these two systems will stay fairly well synchronized with respect to their system times essentially the NTP protocol is a much more sophisticated way of synchronizing time than that provided by the net date command and the time service and because of that there are several key NTP concepts that you have to be familiar with in order to effectively implement and manage the NTP protocol on your network the first concept that you have to understand is that of stratum NTP uses the concept of stratum to define a hierarchy of NTP servers at the top of the hierarchy RR stratum one time servers stratum one time servers get their time from a reference time source such as the naval atomic clock and if you want to learn more about how the naval atomic clock works you can visit the URL shown here to learn more about it now in addition to stratum 1 time providers we also have stratum 2 time providers as you can see here stratum 2 time providers get their time from a stratum one time provider and you guessed it stratum 3 time providers get their time from a stat stratum 2 time provider not from a stratum 1 time provider and we can continue on down this ntp stratum to a depth of 256 layers now understand that stratum 1 servers are not publicly available they are on the net internet but you are not allowed to access them however there are a whole bunch of stratum to publicly-accessible ntp time providers on the Internet and you can configure your system to connect to these systems to get your time now if you have just one or two systems in your network it's no problem at all for you to configure your systems to get their time directly from an antenna stratum to NTP time provider however if you have a large network you really don't want to have all of your computers say 500 or 700 or a thousand computers all going out and beating up these stratum 2 time providers to get the exact same information instead what you should do is configure a limited number of systems on your internal network maybe 2 or 3 to go out and synchronize time with a stratum 2 time provider on the Internet and then configure the rest of your internal systems to get their time from those hosts remember that a the NTP DD daemon allows the system to be both a time consumer as would happen in this with this arrow and as a time provider to other systems as happens with this arrow there are several other ntp concepts you need to be familiar with you need to be familiar with the concepts of stepping and slowing understand the ntp protocol initially syncs time between the time consumer and the time provider about once every minute however this interval gradually increases to once every 17 minutes once the time between the two systems is more closely synced if when the times more closely synced you don't need to synchronize every minute once every 17 minutes is enough essentially this means that large adjustments occur relatively quickly but then only small adjustments are made across a longer time interval so what does this have to do with stepping and slowing the thing you need to remember is that if the time difference between the provider and the consumer is small such as less than about 128 milliseconds then the NTP protocol is going to adjust the time on the time consumer very gradually this is called slowing if on the other hand the time difference between the provider and the consumer is large then it's going to have to make time adjustments more quickly that's called steppin now another concept you have to be familiar with if you're going to work with NTP is the concept of insane time and of all the issues that cause problems when implementing and maintaining an NTP deployment this is the one that does it you need to understand that if the time difference between the provider and the consumer is more than 17 minutes in other words they are more than 17 minutes out of sync then the NTP d Damon is going to consider time to be insane and as a result it's not going to adjust it and that can cause all kinds of problems I can't tell you how many times I've seen NTP setup we're trying to synchronize two systems and they never come into synchronization and we can't figure out why well every single time that has happened it's been because of insane time the system time on the two systems was so far apart that the NTP d-damn is as huh I'm not doing anything with this this is crazy I'm not touching it and it doesn't do anything so you have to get the time on the provider and the consumer within 17 minutes of each other initially once you do that then the NTP protocol can start stepping until it gets time closed and then it can start slowing until it gets time really really close so watch for this issue you also need to be familiar with drift ntp measures and corrects for incidental clock frequency errors which is a fancy way of talking about drift where the system time on one system may not run at exactly the same frequency as the system time on another system and so over time the two get out of sync which is why we synchronize time with NTP in the first place you also need to be familiar with the concept of jitter jitter refers to the time difference between the time consumer and the time provider since the last I'm polling so with this background in mind let's discuss how you configure a system to use the NTP protocol to get time from a time provider now before you can do this you do have to install the NTP package on your Linux system some distributions install it by default others do not if yours does not have the NTP protocol installed then you need to use yung zipper or apt-get whichever is appropriate for your distribution to go out and get it then once done you need to edit this file right here to configure how NTP is going to work / at c / ntp kampf now there are a variety of different parameters within this configuration file but the key one that you need to be familiar with is this one right here server the server directive tells the NTP daemon where it's supposed to go to get time so you enter server space and then the IP address or DNS name of the time provider the time provider that you specify could be another computer on your network remember the diagram that we drew earlier where we have one system that goes out on the internet to get time and then all the systems internally get their time from just that one internal server instead of everybody going out on the internet at one time it can also point to an NTP time provider on the Internet now if you want to you can use what's called an NTP pool time server the pool the NTP org domain uses a type of DNS round-robin mechanism to make a random selection from a pool of time providers who have volunteered to be in that pool out on the inner Internet that way no one public ntp server is overloaded with a whole bunch of different time synchronization requests if you want to use this pool which is a really good idea you just add the directive that you see here to your NTP comm file server pool NTP org remember this URL does not point to a server at point to a pool of servers and you never know which one you're going to get but they are all synchronized so it doesn't really matter they all have the same time now here's an absolutely critical thing that you have to remember remember the issue of it of insane time before you actually start the NTP daemon you can prevent insane time issues by performing a one time synchronization with your NTP time provider this makes sure that your system time is not more than 17 minutes off from the NTP time provider we do this by using the NTP date command the NTP date command gets these two systems within this 17 minute window it doesn't work like net date it does not bring the two systems into direct synchronization it just gets them closed within that 17 minute window and thus eliminates insane time issues so we enter NTP date followed by the IP address or DNS name of the time provider that we want to get time from now because NTP date does not immediately synchronize your system time with the time providers time you may actually need to run this command multiple times until you get your system time within that 17 minute window and if this the farther apart the times are on the two systems the more times you're going to have to run this command to get them within that time for window an example of running the NTP date command is shown here where we synchronize the local time on the FS 5 system with the time on a server that's a member of the pool NTP org and if you look at the output you can see how far off you were over here and the time on this system was actually pretty close to the time on the time provider 0.002 four or five nine seconds off that's for all intents and purposes not synchronized already now I do need to point out that before you can run the NTP date command you need to make sure that ntpd the daemon itself is off NTP date will not work while ntpd is running basically gonna have to time synchronization mechanisms running simultaneously and they don't get along with each other so shutdown ntpd the daemon first run ntp date until you get your time fairly close and then turn ntpd back on now once the ntpd daemon has been started there are several commands you can use to monitor how well it's working how closely it's keeping time synchronized the first one is shown here you can run NTP queue space dash P the shell prompt to query the status of the NTP D Damon now the columns and the output include those shown here first of all we have the remote column which specifies the hostname or IP address of the time provider that we're getting time from we have the re F ID column which specifies the type of time reference source that we're connecting to the St column specifies the stratum of that time provider the when column specifies the number of seconds since the last time poll occurred the pol column specifies the number of seconds between two time poles the reach column displays whether or not the time server was reached the last time was pulled a successful pole increments this field by one so as you can see these servers were hit 377 times the delay specifies how much time in milliseconds that it took for the time provider to respond to the time request that was sent from the local system the offset column specifies the time difference between the local system time and the time on the time provider and this is in milliseconds not seconds this confuses a lot of folks initially they see this and think oh wow I'm 13 seconds off I'm 12 seconds off I'm 11 seconds off no you're actually 13 milliseconds off or 12 milliseconds off or whatever it shows here which for all intents and purposes is synchronized and then jitter specifies the size of the time discrepancies and again this is also measured in milliseconds you can also use the ntp trace command to monitor time synchronization the ntp trace utility traces how the time consumer is getting its time from the time provider it specifies the time provider's stratum it lists also the time offset between the local system and the time provider and so on that's it for this lesson in this lesson you learned how to use the ntpd daemon to synchronize time with other systems over a network connection we discussed how the NTP protocol works and then we discussed how to configure the ntpd daemon on a Linux system to get Network time
Info
Channel: The Linux Man
Views: 50,281
Rating: 4.9114585 out of 5
Keywords: Linux, Networking, Network, Network Time, Network Time Protocol, Network Time Protocol (NTP), NTP, Tutorial, Tutorials
Id: EkQPkQb2D3g
Channel Id: undefined
Length: 15min 6sec (906 seconds)
Published: Thu Nov 24 2016
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.