Wednesday, 25 February 2015

Creating Linux NTP Server

Linux, in this example Ubuntu, does not come with a built in NTP server, however it is a nice lightweight platform than can be used as an alternative to a Windows machine that would obviously have to be licenced, and the NTP service can easily be added assuming the machine has an Internet connection (it only needs this during the configuration phase

Personally, I like to use Ubuntu Server 10.04 (http://releases.ubuntu.com/), since this isn't burdened with the updated GUI interface that seems to require additional resources, and that is just not needed.
The setup is pretty much self-explanatory, simply ensure the machine has a network connection (preferably to the Internet) before starting.

Installing the NTP Software:

Type: sudo -s and then type the appropriate password
To get and install the NTP Software (you MUST have an Internet connection), type: apt-get install ntp

Edit the NTP Configuration File:

(This uses the "vi" editor, you can obviously use one of your choice, such as Nano)

Open the file for editing: vi /etc/ntp.conf
Press the ‘Insert’ key
Insert the following lines of code after “server ntp.ubuntu.com”
     server 0.uk.pool.ntp.org iburst
     server 1.uk.pool.ntp.org
     server 2.uk.pool.ntp.org
     server 3.uk.pool.ntp.org
     server 127.127.1.0
     fudge 127.127.1.0 stratum 10
     tos orphan x (where x is a stratum level between 4 and 10)
Press the ‘Esc’ key, then enter :wq and press enter (to save the file and quit the editor)

[Note: The "tos orphan x" line is only needed if you intend to use this NTP server as a definitive time source on the network, without connecting this server to the Internet.  In fact, if this is the case, the "server 0" to "server 3" lines can be safely deleted, I leave them in case the server is connected to the Internet at a later date]

Restart the NTP Server:

     /etc/init.d/ntp restart

Check Status:

You can check the status of the various NTP servers by typing: ntpq -c lpeer
(Note: This may take a while to update after first being initialised)

Changing IP Address:

Assuming that the machine was built with a connection to the Internet, it will likely have a DHCP assigned IP address.  This can be found by typing: ifconfig eth0

To set a static IP address:

Backup the current IP details: cp /etc/network/interfaces /etc/network/interfaces.backup
Edit the interfaces file: vi /etc/network/interfaces
Press the ‘Insert’ key
Change 'iface eth0 inet dhcp' to 'iface eth0 inet static'
Enter the following lines (substituting in the desired values for the IP addresses):
     address 192.168.0.10
     netmask 255.255.255.0
     gateway 192.168.0.1 (This line can be omitted if not needed)
Press the ‘Esc’ key, then enter :wq and press enter (to save the file and quit the editor)
Type: ifdown eth0, then ifup eth0 to restart the network interface
Check that the new static IP has been assigned by once again typing: ifconfig

Reconfiguring the NTP Server after Cloning or Building from a Template:

When an virtual NTP is cloned or imported from a template, the “Ethernet 0” card is often unavailable, and the interface on the new server is named “Ethernet 1”, this can be checked by typing ifconfig eth1

If this is the case, edit the Interfaces file as follows:
Edit the interfaces file: sudo vi /etc/network/interfaces
Change the “Address”, “Netmask” and “Gateway” entries to reflect the IP addresses for the network.
Press the ‘Esc’ key, then enter :wq and press enter (to save the file and quit the editor), then type ifup eth1 to bring up the interface.
Check that the new static IP has been assigned by once again typing: ifconfig

No comments:

Post a Comment