In the previous part of this series, I walked you though setting up the client portion of the NTP configuration. From having worked with various network gear over the years, I have enjoyed the ability to use a piece of network gear (such as the Cisco 6509) as a network time source so that every device on the network wasn’t trying to get it’s own time reference. There is enough traffic on the internet now, I was trying to be a good user of the Internet and reducing redundant traffic where I could.
In this installment, I show how to use a Raspberry Pi as a network time server for your network. There are two ways that you can do this. If you have internet access on your RPi, you can use the client portion of NTP that you configured in the first installment in this series, add a couple of lines to /etc/ntp.conf and you have your own local NTP server for less than $50.
Where this post adds to the previous installment is that you can use it two different ways. The first is a failsafe option for when the situation occurs that your link to the Internet goes down and you arent able to access the public NTP servers that you are configured for, this configures your RPi so that it’s internal clock can serve as the clock of last resort. The other option is for when you want to have a NTP server available but don’t want to have it accessing the outside world or don’t want it to for whatever reason. In either case, the next few lines give you a choice of either option. If the later option is the way you will go, you will need to use the date command in order to manually set the RPi clock to the proper date/time so that the devices on your network will be give the proper date/time when it is requested by them.
Using sudo nano /etc/ntp.conf, add the following lines to your config –
fudge 127.127.1.0 stratum 10
The stratum commands sets the priority level of the clock. Stratum 0 normally refers to a device such as an atomic or GPS clock. Normally they are not directly connected to the network. Stratum 1 devices are connected to Stratum 0 devices. A Stratum 1 device are also referred to as a time server. There is a whole discussion that can be had on what level of Stratum that should be connected to. Since you probably won’t have more than one time server on your network, setting the level shouldn’t be a big concern but one worth noting.
Since you are now exposing your RPi to providing a network service, you will probably want to do two things. The first is to add a rule to the UFW firewall service that I have written about previously. The next is to prevent one or more of the hosts from accidentally or deliberately changing the time on your RPi that is is giving out to the network. You can do this by adding the following line to /etc/ntp.conf –
restrict 192.168.15.0 mask 255.255.255.0 nomodify
You will want to change the ip address and/or subnet mask to the network range(s) that your RPi will be providing the NTP service for. As with any changes to the NTP service, you will need to restart the NTP service so that it knows about the changes you have made. As with Linux, there is more than one way to do it. I normally do it using sudo service ntp restart. When I make any changes to the NTP service (or any service on Linux), I usually watch the resulting network traffic coming from the RPi to verify that the change(s) I have made are working as expected.
In the next post in this series, I will show how to configure the GPS Receiver from the good folks at AdaFruit, which will put you one step away from having your own GPS based Time Server for less than $200.
To see more of my posts about the Raspberry Pi, please go to http://www.ronnutter.com/category/raspberry-pi/