Archive for the ‘ntp’ tag
Netgear DG834G and NAT loopback
Yesterday I made the decision (read: mistake) to update my Netgear DG834G router (hardware v4, firmware v5.01.09) to firmware v5.01.14 – and, as is the way with these things, it brought trouble. After the upgrade I couldn’t reach www.nikrivers.com from the LAN side of the router.
The problem is caused by the way the router handles traffic coming from an internal IP address and destined for the WAN (i.e. external) IP address. In this situation it requires that the router first transfers the traffic from the internal network to the external network, and then immediately passes it back whilst applying any firewall or routing rules that are relevant to incoming external traffic.
Linksys NSLU2: time server with NTP
If you’re running an email server on your Slug, where accurate server time is vital, or you simply want the Slug’s system time to be accurate, you need to make a few changes.
When it comes out of the factory the Slug has an inherrent bug which causes the internal clock to lose time; apparently Linksys tried to fix this problem by adjusting the time regularly (using cron) but it seems the time is adjusted in the wrong direction – thus, the error is doubled. This problem is fixed in Unslung 2.6 and higher anyway (Unslung 2.10 is the latest release as at Jan 2009), so we can remove the relevant crontab entry.
Edit the crontab file:
vi /etc/crontab
Comment out the call to hwclock (the Linksys ‘fix’). The hash (#) symbol is used to denote a comment:
#1 * * * * root /usr/sbin/hwclock -s &>/dev/null
Now install ntpd, and edit the config file to contain time servers that are geographically close to you – you can find out what these are by visiting http://www.pool.ntp.org/. Editing the config file is quite self-explanatory.
install ntp
vi /opt/etc/ntp/ntp.conf
Now edit the ntp startup script; there are a few things we need to do to make sure the time is set and maintained correctly.
vi /opt/etc/init.d/S77ntp
Add the following lines just before the existing call to ntp:
/opt/bin/tickadj 10000 > /dev/null
/opt/bin/ntpd -q -c /opt/etc/ntp/ntp.conf > /dev/null
The first line corrects the Slug’s tick value, and the second line makes ntp quickly (-q) set the time using the specified time servers, and exits. It is important to note that when ntp is running, it does not just simply set the correct time regularly; it constantly checks the time against that of the time servers, and gradually brings the system time in line. The call we just added, with the -q flag, ensures that the Slug has pretty accurate time before ntp starts properly.
Speaking of which, you will need to make sure the Slug has accurate time now. This can be done using the web interface, for example. It only needs to be as accurate as you can get it, and ntp will take care of the rest.
Now simply restart ntp:
/opt/etc/init.d/S77ntp restart
It will take a while for ntp to synchronise with the time servers you specified in the config file, sometimes upwards of 15 minutes – so don’t be too concerned if nothing seems to be happening straight away. You can check what’s going on with the ntpq tool:
ntpq -p
The command will list information about the time servers. If ntp has decided on a server’s suitability for synchronisation, the time server’s name will be preceeded by * (the chosen server), + (server is suitable), or - (server is unsuitable).
Note: if you are running Dovecot on your Slug, and ntp adjusts the time backwards after you initially set the Slug’s time (using the web interface), Dovecot will complain about time going backwards, and die. You will need to restart Dovecot; but this only happens while you’re configuring ntp, and won’t happen during normal operation once ntp is running.
If this information was useful, please leave a comment to let me know!