[Raspberry Pi] NTP time synchronization

Published on Author admin

Configure proper timezone according to your physical location by using following wizard:

sudo dpkg-reconfigure tzdata

Enable NTP:

timedatectl set-ntp true

Check time and date settings:

timedatectl status

Install ntpdate tool:

apt install ntpdate

Fix problem with ToS (Type of Service) field value in IP packet.
By default ToS is set to 0xc0 value by ntpd daemon.
For now RPi 3 is not able send IP packets via internal wlan0 interface when ToS is set to something different than 0x00.
We can change ToS field value by using iptables following command:

/sbin/iptables -t mangle -I POSTROUTING 1 -o wlan0 -p udp --dport 123 -j TOS --set-tos 0x00

Just put above in below file, before last line (containing "exit 0"):

/etc/rc.local

It will load iptables rule after every reboot of RPi device.

Synchronize time via NTP:

systemctl stop ntp
ntpdate-debian
systemctl start ntp
ntpq -pn

Reboot RPi and verify NTP time synchronization:

ntpq -pn