Synchronize Linux Real Time Targets with Network Time Protocol (NTP) Server

Updated Jun 16, 2020

Reported In


  • CompactRIO Controller


  • NI CompactRIO

Operating System

  • NI Linux Real-Time

Issue Details

I have a Linux Real Time Device (e.g. CompactRIO) and I am experiencing time drift. I want to synchronize its clock with a Network Time Protocol (NTP) Server. How do I do this?


To use NTP on a Linux Real-Time target, you will need to install and configure the NTP software on the target using a secure shell (SSH) session to the target. These instructions should apply to all Linux Real-Time targets, but if you are using a TSN-enabled target, such as a cRIO-904x or cRIO-905x, please read the note in the Additional Information section below.
  1. Make sure that the Linux Real-Time target is connected to the internet. A simple way to do this is to connect both the host PC and the target to a network switch that is connected to the internet.
  2. Open an SSH session to the Linux Real-Time target using a terminal program, such as PuTTY.
  3. Enter the username and password when prompted to log into the target.
  4. Once the SSH session is open to the Linux Real-Time target, enter the following command lines to install the NTP software:
opkg update
opkg install ntp ntp-tickadj ntp-utils
  1. The NTP software should now be installed and running in the background. If the above commands fails to update or install, make sure that the device is connected to the internet.
  2. You now need to setup the NTP configuration file to point to the NTP server of your choice. You can use an NTP server on your local network or use a publicly available NTP server. This example will show how to connect to the server.
    1. Open a new SSH session to the target if your session is no longer open.
    2. Run the following command to open the NTP configuration file:
vi /etc/ntp.conf
  1. The ntp.conf file should now be open in the Linux vi text editor.
  2. Press i to enter edit mode.
  3. Move the cursor with keyboard arrows. Add a line with server name in the format server <server URL or IP address>. You can add multiple servers in this file by placing each on their own line. If you need additional help configuring /etc/ntp.conf, there are many guides available on the internet.
  4. The file should now look like this:
  1. Exit the edit mode of the file by pressing the ESC key.
  2. Save and exit the NTP configuration file by entering:
  1.  Reboot the Linux Real-Time target. Your target should start synchronizing to the server you specified in the configuration file. Please be aware that NTP will adjust the time slowly, so it may take some time for the skew between the target system time and the NTP server time to be minimized.
  2. You can test the connection to the NTP server by running the following command to query the server:
ntpq -p

Additional Information

  • This solution should work on Linux Real Time Targets with Real Time module 14.0 or newer.For this solution to work on Real Time module 13.1 and older, you need to configure third party installation sources as mentioned in Installing and Configuring NTP on NI Linux Real-Time Devices community post.
  • The configuration file works on the OS level, thus the NTP server setup will be included in the RT image, should it be copied with the Replication and Deployment (RAD) Utility.
  • NTP is currently incompatible with TSN-enabled Linux Real-Time targets, such as cRIO-904x or cRIO-905x. This is because the TSN functionality maintains control of the system clock and will not allow the NTP service to control it. You may be able to use NTP on these targets by uninstalling DAQmx, XNET, and any NI-TimeSync time references from the cRIO. However, this may prevent you from using some functionality of the cRIO, such as using a C Series module in DAQmx mode.