Previous Section  < Day Day Up >  Next Section

Recipe 19.6. Connecting to a Time Server from an Intermittent Connection

19.6.1 Problem

You do not have a full-time Internet connection; you're still on a dialup account, you have a limited DSL account, or you travel. How can you synchronize to an ntp server?

19.6.2 Solution

ntp will still work for you. Install ntp and ntpdate. Make sure the ntp daemon is not running. Configure /etc/ntp.conf, and create the driftfile and logfile if they do not already exist:

#  /etc/ntp.conf

driftfile  /etc/ntp.drift

logfile  /var/log/ntp.log

   

server pool.ntp.org

server pool.ntp.org

server pool.ntp.org

root should own the driftfile and logfile (chmod 644).

Debian users (or users of any system that puts PPP scripts in the /etc/ppp/ip-up.d/ directory) can copy this script:

#!/bin/bash

# ntp-dialup script for Debian

# put this in /etc/ppp/ip-up.d/

# set the correct time immediately

# and run /etc/init.d/ntp-server every time PPP starts

   

/usr/sbin/ntpdate pool.ntp.org

  if [ -x /etc/init.d/ntp-server ]; then

   /etc/init.d/ntp-server restart

  fi

root should own this script (chmod 744). The script will run every time you start PPP.

On Red Hat and Fedora, you'll need to edit or create the /etc/ppp/ip-up.local script, adding these lines:

#!/bin/bash

# add these lines to /etc/ppp/ip-up.local

# on Red Hat and Fedora

# set the correct time immediately

# and run /etc/init.d/ntpd every time PPP starts

   

/usr/sbin/ntpdate pool.ntp.org

  if [ -x /etc/init.d/ntpd]; then

   /etc/init.d/ntpd restart

  fi

When you connect, ntpdate will run and correct the time within the first minute or two. Then the ntp daemon will continue running in the background:

11 Feb 11:38:18 ntpdate[6796]: adjust time server 163.1.87.28 offset -0.018303 sec

ntpdate is updating the time

Starting NTP server: ntpd.

If this is a dialup server serving an Ethernet LAN, you can now configure the client machines as per Recipe Recipe 19.3.

19.6.3 Discussion

These scripts contain a bit of a kludge, by using restart instead of start. ntpd binds itself to whatever IP address is assigned when ntpd starts up. When a PC has a dynamically assigned IP address, ntpd does not track when the lease expires and the address changes. So, if you leave your PC running all the time and need to dial up periodically, ntpd will lose the connection. restart ensures that ntpd will shut down completely and then restart, and thus will pick up the current IP address with each new dialup connection.

These scripts can easily be adapted for a PC that is dialing into a private network that has a local time server. In your PPP scripts, simply point ntpdate to the local server, and edit /etc/ntp.conf to point to the local server.

19.6.4 See Also

    Previous Section  < Day Day Up >  Next Section