Keeping your clock accurate
If you want to be sure that your computer clock is accurate – always – you can configure your system to use NTP (Network Time Protocol).
NTP is one of the oldest protocols on the internet and its predecessors, going back to the early eighties. If you are interested in reading a small article about the history of NTP, I recommend this text in PDF. The official ‘home’ of NTP is www.ntp.org
You can use NTP on your Linux desktop to automatically synchronize its clock to a pool of servers around the world that are official ‘timekeepers’. Usually you configure NTP to talk to about three different servers to guarantee that at least one is available at any time. It is best to choose servers near you, so that response times are shorter, which results in a more accurate clock on your computer. There are more than 1.500 servers to choose from, but some areas on our planet are better served than others. For instance: there are almost a thousand servers in Europe, but only 19 in South America (where I live).
Your first step should be to select three servers close to you – preferably in your country, or if there aren’t enough, in your ‘zone.
Go to www.pool.ntp.org and browse through the tree of zones and servers to select which ones are best for you.
The ‘pooling’ system automatically translates the addresses to the actual domain- and server names.
For instance, I use: 0.br.pool.ntp.org, 1.br.pool.ntp.org and 2.br.pool.ntp.org and these names are usually translated to servers at local universities or government institutions.
Don’t worry about this part, the pooling system takes care of it.
Now that you have selected your servers, let’s start configuring your system. As always, I’ll use Slackware as an example, but things will be similar in other distributions.
1. Configure /etc/ntp.conf
Edit this file with your favorite text-editor (I use vi) and go to the lines that say:
and replace this line or lines with your servers. In my case, I put:
While we’re editing the configuration, let’s make NTP a bit more secure, inserting some restrictions. Find the lines (usually at the end) that start with “restrict ….” and replace them with the following:
restrict default nomodify
restrict 192.168.1.0 mask 255.255.255.0 nomodify notrap nopeer
The address 127.0.0.1 is our local IP address that has no restrictions.
The network / mask combination in the third line is my local network, so that my other desktops can use my system as a time-server, preventing all of them to send NTP queries to the internet.
On the rest of my desktops I put the line “server 192.168.1.1″ (my local IP) in their ntp.conf
2. Synchronize your clock manually
If your clock is too much behind or ahead, NTP might refuse to synchronize it, so let’s force the first synchronization with a simple command:
Of course, you should substitute the server name with one from your list.
3. Make your ntp daemon executable
In Slackware this is done with the following command:
chmod +x /etc/rc.d/rc.ntpd
This (again, in Slackware) will make it start every time you boot up your system.
4. Start NTP now without rebooting
Again, a simple command:
After a few minutes, check if NTP is communicating with the server pool by running this command:
It should show the servers it is talking to and one of them should have an ‘*’ in front of it.