Category: advanced NTP

Keeping accurate time on Linux

  |   By

If you want to be sure that your computer clock is accurate you can configure your system to use NTP (Network Time Protocol), one of the oldest Internet protocols and the industry standard for time synchronisation.

NTP on will synchronise your computer’s clock to a pool of time servers around the world that are official ‘timekeepers’. It is best to choose the closest to you so response time is minimized and to use more than one in case one goes down. There are more than 1.500 servers to choose from, but some areas are better served than others. Many servers on the internet are extremely inaccurate and Internet time references should not be used as a replacement for a dedicated time server.

However, for basic time synchronisation purposes, Internet providers will suffice. The 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 ntp home and browse through the tree of zones and servers to select which ones are best for you. The follow these commands to configure:

1. Configure /etc/ntp.conf
Edit this file with a text-editor. Replace
server <example-server-name>
with your servers, such as:

server 0.br.pool.ntp.org
server 1.br.pool.ntp.org
server 2.br.pool.ntp.org

2. Synchronise your clock manually
If your clock is drifting too NTP might refuse to synchronise it, but it can be done manually:

ntpdate 0.br.pool.ntp.org (server name that you choose)

3. Make your ntp daemon executable

chmod +x /etc/rc.d/rc.ntpd

4. Start NTP now without rebooting
Again, a simple command:

/etc/rc.d/rc.ntpd start

The Atomic Clock and the NTP Time Server

  |   By

Most people have heard of atomic clocks, their accuracy and precision are well known. An ato0mic clock has the potential to keep time for several hundred million years and not lose a second in drift. Drift is the process where clocks lose or gain time because of the inaccuracies in the mechanisms that make them work.

Mechanical clocks, for instance, have been around for hundreds of years but even the most expensive and well engineered will drift at least a second a day. Whilst electronic clocks are more accurate they also will drift by about a second a week.

Atomic clocks have no comparison when it comes to time keeping. Because an atomic clock is based on the oscillation of an atom (in most cases the caesium 133 atom) which has an exact and finite resonance (caesium is 9,192,631,770 every second) this makes them accurate to within a billionth of a second (a nanosecond).

While this type of accuracy is unparalleled it has made possible technologies and innovations that have changed the world. Satellite communication is only possible thanks to the time keeping of atomic clocks, so is satellite navigation. As the speed of light (and therefore radio waves) travel at over 300,000km a second an inaccuracy of a second could see a navigation system be hundreds of thousands of miles out.

Precise accuracy is also essential in many modern computer applications. Global communication, particularly financial transactions have to be done precisely. In Wall Street or the London stock exchange a second can see the value of stock rise or fall by millions. Online reservation also requires the accuracy and perfect synchronisation only atomic clocks can provide otherwise tickets could be sold more than once and cash machines could end up paying out your wages twice if you found a cash machine with a slow clock.

Whilst this may sound desirable to the more dishonest of us, it doesn’t take much imagination to understand what problems a lack of accuracy and synchronisation could cause. For this reason an International timescale based on the time told by atomic clocks has been developed.

UTC (Coordinated Universal Time) is the same everywhere and can account for the slowing of the Earth’s rotation by adding leap seconds to keep UTC inline with GMT (Greenwich Meantime). All computer networks that participate in global communication need to be synchronised to UTC. Because UTC is based on the time told by atomic clocks it is the most precise timescale possible. For a computer network to receive and keep synchronised to UTC  it first needs access to an atomic clock. These are expensive and large pieces of equipment and are generally only to be found in large scale physics laboratories.

Fortunately the time told by these clocks can still be received by a network time server wither by utilising time and frequency long wave broadcasts transmitted by national physics laboratories or from the GPS (Global Positioning system). NTP (network time protocol) can then distribute this UTC time to the network and use the time signal to keep all devices on the network perfectly synchronised to UTC.

Understanding Computer Timestamps with NTP

  |   By

The way a computer deals with time is totally different to the ways humans perceive it. We arrange time into seconds, minutes, hours, days, weeks, months and years, while computers on the other hand arrange time as a single number representing the seconds that have passed from a single point in time, known as the prime epoch.

Most computers use NTP (Network Time Protocol) to deal with time and on networks many are synchronised using a dedicated NTP time server.  NTP knows nothing about days, years or centuries, only the seconds from the prime epoch.  This prime epoch is set (for most systems) at midnight at the turn of the century twentieth century that for a human would be recorded as something like: 00:00 – 01,01,1900.

Computers, however, count time as the number of seconds past this point. If a computer was around in 1900 its timestamp on midnight January 1 would be 0 while in 1972 at the same date the timestamp would be 2,272,060,800, which represents the number of seconds since 1900.

The timestamps restart every 136 years with the next wrap around due in 2036, this has caused uneasiness amongst some who fear a Millennium Bug type scenario, although most doubt such events would occur, however, when a wrap-around of the timestamp does happen an era integer will be added (+1), to allow computers to deal with time spans that cover more than one wrap-around.  If computers and NTP need to deal with time that spans before the prime epoch a negative integer is used (for the year 1500 a -3 will be used to represent three cycles of 136 years).

Timestamps are used in virtually every transaction that modern computers are tasked to do such as sending emails, debugging and programming. Because time is linear, a computer knows that each timestamp is always greater than the previous one and therefore computers and NTP find it difficult to deal with inaccuracies in time, particularly when time suddenly appears to go backwards.

This can happen if computers are not synchronised to the same time. If an email is sent to a machine with a slower clock, it appears to the computer to have been received before it has been sent.  Lack of synchronisation can serious problems and can even leave a system vulnerable to malicious attacks and even fraud.

Because of this, most computer networks are synchronised to UTC (Coordinated Universal Time). UTC is a global timescale and the same for everybody worldwide it is based on the time told by atomic clocks which are highly accurate, neither gaining nor losing a second in millions of years.

Most computer networks use a dedicated NTP time server to receive a UTC time to synchronise their computers too.  UTC is available from across the Internet (although unsecured), via the GPS network (Global Positioning System), or by receiving national time and frequency broadcasts via long wave.

NTP synchronises a computer by checking the received UTC time and adding to or holding a computer’s timestamp until it perfectly matches UTC. By using a dedicated NTP time server UTC can be maintained on a network to a few milliseconds of UTC time.

Understanding Computer Timestamps with NTP

  |   By

The way a computer deals with time is totally different to the ways humans perceive it. We arrange time into seconds, minutes, hours, days, weeks, months and years, while computers on the other hand arrange time as a single number representing the seconds that have passed from a single point in time, known as the prime epoch.

Most computers use NTP (Network Time Protocol) to deal with time and on networks many are synchronised using a dedicated NTP time server.  NTP knows nothing about days, years or centuries, only the seconds from the prime epoch.  This prime epoch is set (for most systems) at midnight at the turn of the century twentieth century that for a human would be recorded as something like: 00:00 – 01,01,1900.

Computers, however, count time as the number of seconds past this point. If a computer was around in 1900 its timestamp on midnight January 1 would be 0 while in 1972 at the same date the timestamp would be 2,272,060,800, which represents the number of seconds since 1900.

The timestamps restart every 136 years with the next wrap around due in 2036, this has caused uneasiness amongst some who fear a Millennium Bug type scenario, although most doubt such events would occur, however, when a wrap-around of the timestamp does happen an era integer will be added (+1), to allow computers to deal with time spans that cover more than one wrap-around.  If computers and NTP need to deal with time that spans before the prime epoch a negative integer is used (for the year 1500 a -3 will be used to represent three cycles of 136 years).

Timestamps are used in virtually every transaction that modern computers are tasked to do such as sending emails, debugging and programming. Because time is linear, a computer knows that each timestamp is always greater than the previous one and therefore computers and NTP find it difficult to deal with inaccuracies in time, particularly when time suddenly appears to go backwards.

This can happen if computers are not synchronised to the same time. If an email is sent to a machine with a slower clock, it appears to the computer to have been received before it has been sent.  Lack of synchronisation can serious problems and can even leave a system vulnerable to malicious attacks and even fraud.

Because of this, most computer networks are synchronised to UTC (Coordinated Universal Time). UTC is a global timescale and the same for everybody worldwide it is based on the time told by atomic clocks which are highly accurate, neither gaining nor losing a second in millions of years.

Most computer networks use a dedicated NTP time server to receive a UTC time to synchronise their computers too.  UTC is available from across the Internet (although unsecured), via the GPS network (Global Positioning System), or by receiving national time and frequency broadcasts via long wave.

NTP synchronises a computer by checking the received UTC time and adding to or holding a computer’s timestamp until it perfectly matches UTC. By using a dedicated NTP time server UTC can be maintained on a network to a few milliseconds of UTC time.