Hallo,
I have written a more elegant script. I have attached it (sorry) to this
message and can be saved in the directory /etc/ppp/ip-up.d
It uses a key (and password) together with the command ntpdc to change
the configuration of the ntp daemon.
If you enter the command "ntpdc -n -p", you get in the first column the
ip-address of the peer, and in the second column the local address. I
have found out that after an initial startup, the local address is
filled with the address of your interface. If the address of the
interface is changed (after a reconnect), ntp can't send the data from
the old socket (with the old local address).
I have seen that peers added dynamicly by ntpdc have a local address of
0.0.0.0 which is any-address. They keep on working after that the local
address of the interface has changed.
My script skips local clocks (127.127.?.?) and dynamicly added peers
(0.0.0.0). Alle other peers are removed (unconfig) and added (addserver)
again. At the end are some public available peers added, so that I
always have at least 4 peers.
I hope it is usefull,
Vincent Smeets
Ricardo Yanez wrote:
my ISP disconnects me once a day, so that I won't keep a quasi-static IP
I don't pay for. Now, pppd reconnects swiftly, but ntp doesn't seem to
like this anyway. Soon after the dis-/reconnect I get this:
Feb 9 13:15:01 zwerg ntpd[4732]: sendto(192.53.103.104): Invalid argument
Feb 9 13:15:07 zwerg ntpd[4732]: sendto(130.149.17.21): Invalid argument
Feb 9 13:16:08 zwerg ntpd[4732]: sendto(195.145.119.188): Invalid argument
Feb 9 14:41:27 zwerg ntpd[4732]: synchronisation lost
As it will never recover, I resorted to restarting ntp every day. But
surely, there's a more elegant solution. Or is there?
Hi,
An elegant (I think) way of solving this is to
put scripts in /etc/ppp/ip-[up|down].d/ to stop
and start ntpd when pppd reconnects.
My /etc/ppp/ip-down.d/ntp-server simply says,
-----
#!/bin/sh
[ -x /usr/sbin/ntpd ] || exit 0
echo "Stopping NTP server"
/etc/init.d/ntp-server stop
-----
and my /etc/ppp/ip-up.d/ntp-server,
-----
#!/bin/sh
[ -x /usr/sbin/ntpd ] || exit 0
echo "Starting NTP server"
/etc/init.d/ntp-server start
-----
Just make sure these scrips are executable (755).
Ricardo
#!/bin/sh
#
keyid=1
passwd=`awk -v keyid="$keyid" '$1 == keyid { print $3 }' /etc/ntp.keys`
ntpdc -n -p | awk -v keyid="$keyid" -v passwd="$passwd" '
BEGIN {
print "keyid", keyid
print "passwd", passwd
}
NR <= 2 ||
$1 ~ /^.127\.127\./ {
next
}
$2 == "0.0.0.0" {
server_count += 1
peer = substr($1, 2)
next
}
$1 ~ /^[=*]/ {
server_count += 1
peer = substr($1, 2)
print "Updating peer", peer > "/dev/stderr"
print "unconfig", peer
print "addserver", peer
next
}
END {
for (; server_count < 4; server_count++) {
peer = "de.pool.ntp.org"
print "Adding peer", peer > "/dev/stderr"
print "addserver", peer
}
}
' | ntpdc