Last active
July 26, 2017 11:56
-
-
Save gotev/6f70904ea15632fefa220432677c7d9a to your computer and use it in GitHub Desktop.
Enable NTP on Ubuntu (with recommended settings for Italy: http://www.inrim.it/ntp/index_i.shtml)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash -e | |
if [[ $EUID -ne 0 ]]; then | |
echo "This script has to be executed as root" 1>&2 | |
exit 1 | |
fi | |
echo "Installing NTP client..." | |
rm -rf /var/lib/apt/lists/* | |
apt-get -y clean | |
apt-get -y autoclean | |
apt-get -y update | |
touch /var/run/utmp | |
chmod 664 /var/run/utmp | |
apt-get install -y ntp ntpdate fake-hwclock && \ | |
(sed -i 's/server 0.ubuntu.pool.ntp.org/server ntp1.inrim.it iburst/g' /etc/ntp.conf | |
sed -i 's/server 1.ubuntu.pool.ntp.org/server ntp2.inrim.it iburst/g' /etc/ntp.conf | |
sed -i 's/server 2.ubuntu.pool.ntp.org//g' /etc/ntp.conf | |
sed -i 's/server 3.ubuntu.pool.ntp.org//g' /etc/ntp.conf | |
sed -i 's/server ntp.ubuntu.com//g' /etc/ntp.conf | |
timedatectl set-ntp true | |
/etc/init.d/ntp stop | |
ntpd -gq | |
/etc/init.d/ntp start | |
update-rc.d ntp enable | |
hwclock -s | |
ARCH=$(uname -m) | |
if [ "$ARCH" == "i686" ]; then ARCH="i386"; fi | |
curl -# -L "http://de.archive.ubuntu.com/ubuntu/pool/universe/n/ntpstat/ntpstat_0.0.0.1-1_$ARCH.deb" -o /tmp/ntpstat.deb | |
dpkg -i /tmp/ntpstat.deb | |
echo | |
echo | |
echo "NTP client installed! Reboot now to apply the changes.") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
To use this script, make sure your box has full internet access and execute:
To verify NTP status:
For more information about NTP and how to solve issues, search on Google :)
If the sync is not working, it may be useful to perform a
tcpdump
:Also check that you have opened port 123 on your firewall.