Ubuntu Linux how to set the date and time via Network Time Protocol (NTP)

by Vivek Gite · 6 comments

Q. How do I setup Ubuntu Linux system time using Network Time Protocol (NTP)? Do I need to install ntp server?

A. No you don't have to install NTP server. All you have to do is install simple client called ntpdate. ntpdate sets the local date and time by polling the Network Time Protocol (NTP) server(s) given as the server arguments to determine the correct time. It must be run as root on the local host.

A number of samples are obtained from each of the servers specified and a subset of the NTP clock filter and selection algorithms are applied to select the best of these. Note that the accuracy and reliability of ntpdate depends on the number of servers, the number of polls each time it is run and the interval between runs.

Please note that ntpdate will decline to set the date if an NTP server daemon (ntpd) is running on the same host. When running ntpdate on a regular basis from cron as an alternative to running a daemon, doing so once every hour or two will result in precise enough timekeeping to avoid stepping the clock.

Install ntpdate client

$ sudo apt-get install ntpdate

ntpdate will automatically run when your network interface get activated by system (i.e. while booting Ubuntu Linux sever/desktop system) . Ubuntu Linux stores script at /etc/network/if-up.d/ntpdate location.

If you wish to just run script again just type command:
$ sudo /etc/network/if-up.d/ntpdate
OR
$ sudo ntpdate pool.ntp.org

Install as cronjob

To avoid stepping the clock you must run ntpdate every 1 or 2 hours using cronjob:
crontab -e
Now add hourly job:
#Setup NTPDATE
@hourly /etc/network/if-up.d/ntpdate

Save and close the file.

Featured Articles:

Want to read Linux tips and tricks, but don't have time to check our blog everyday? Subscribe to our daily email newsletter to make sure you don't miss a single tip/tricks. Subscribe to our weekly newsletter here!

{ 6 comments… read them below or add one }

1 Ashok.S 03.05.07 at 11:44 am

i want java script for Disk space and disk memory and disk usage

2 Rupert 11.20.07 at 10:43 pm

Do I need to restart the cron service after editing the crontab to add ntpdate ?

3 vivek 11.21.07 at 5:53 am

Noop, if crond is already running it will pickup new changes.

4 James 05.09.09 at 2:14 pm

DO NOT DO THIS! You will put too much load on the ntp servers, BE NICE!

If you RIGHT CLICK on your desktop clock and select “set date / time” there’s an option to automatically set the time, and select the ntp.ubuntu.com servers so you don’t load the pub servers, be nice and these services will continue.

WHY? Because using ntp – NOT ntpdate every hour, will figure out what the drift of your clock is and set it on a regular basis and prevent too much load on the ntp server.

Just set it by the feature provided.

5 steppa 07.01.09 at 5:24 pm

Using ntpdate daily or every few hours is just fine regarding load on ntp servers. The ntp daemon synchronizes every few seconds!

6 Vole 01.13.10 at 3:52 pm

Instead of ntpdate install ntpd.

https://help.ubuntu.com/9.10/serverguide/C/NTP.html

Leave a Comment

You can use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Previous FAQ:

Next FAQ:

nixCraft FAQ PDF Collection Now Available To All