Skip to content

Instantly share code, notes, and snippets.

@gotev
Last active July 26, 2017 11:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gotev/6f70904ea15632fefa220432677c7d9a to your computer and use it in GitHub Desktop.
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)
#!/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.")
@gotev
Copy link
Author

gotev commented May 27, 2016

To use this script, make sure your box has full internet access and execute:

curl -L http://bit.ly/2tCOiPn | sudo bash

To verify NTP status:

ntpstat

schermata 2016-05-27 alle 16 11 32

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:

tcpdump -AAA -vvv -i any port 123

Also check that you have opened port 123 on your firewall.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment