# Using a local Network Time server (NTP)

{% hint style="success" %}
Please note that ArdexaLinux is configured, by default, to use NTP. This page is provided to provide some reference to using and troubleshooting NTP.
{% endhint %}

## General Concepts

**How does it works:** An NTP server receives time data from a reliable source (such as atomic clocks, GPS satellites, or other higher-level NTP servers) and distributes this time information to clients on a network. The protocol adjusts the clocks on the client devices to account for network delays and other factors.

**Importance:** NTP servers are critical in data acquisition systems because they ensure accurate time synchronization across all networked devices, enabling reliable and coherent data collection and analysis. This precision is essential for maintaining data integrity, coordinating distributed systems, and meeting regulatory requirements.

## Implementation

We can find the following 2 scenarios:

### With Internet Access

In this case, an NTP Server on the internet can be used.

Ardexa Linux uses by default `systemctl-timesyncd` for clock synchronization. So, as long as the plant has an internet connection, the synchronization will be automatically done and no further steps are required.

See the section "Troubleshooting" to check the internet access if needed.

### Without Internet Access

In this case, a local NTP Server will be required.&#x20;

{% hint style="info" %}
If there is no internet access nor a local NTP Server available, escalate the issue.
{% endhint %}

To configure the local server, its IP Address will be needed. If it cannot be obtained directly, scan the local network for port `123/udp`(your IP subnet will most likely be different) with the following command:

```
nmap -sU -p 123 192.168.1.0/24
```

Once the IP is found:

1. **Confirm the NTP Server responds** (see troubleshooting section *Check the UDP port*)
2. **Configure the NTP Server IP**&#x20;

The NTP Configuration is in the file `/etc/systemd/timesyncd.conf`

To edit it, use the following command (with the appropriate IP):

```
printf '[Time]\nNTP=\nFallbackNTP=192.168.1.1' > /etc/systemd/timesyncd.conf
```

3. **Restart the service**

Run `systemctl restart systemd-timesyncd`

4. **Review the status** (see Troubleshooting section *Check clock synchronization status***)**

If the time zone is changed on the edge device, make sure to call "Refresh metadata" on the device.

## Troubleshooting

* **Check internet access**

Go to DEVICE > NETWORK SETTINGS > ACCESS and click on *Check Access*

If the services return Green, internet access is enable.

* **Check the UDP port**

Run (with the required IP) `nmap -sU -p 123 --script ntp-info 192.168.1.1`

Routers are most likely to have the port open and active.

* **Check clock synchronization status**

Run the command: `timedatectl status`

\
If the *NTP service* is active and *System clock synchronized* indicate *yes*, then the NTP Server is running properly.

<figure><img src="https://1981611109-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LthAmlGL8PG1hh-vzkV-1703796690%2Fuploads%2FXFEAQS1ohMzswYvJvlG6%2Fimage.png?alt=media&#x26;token=1343b86b-c755-4623-be54-662338c58352" alt="" width="354"><figcaption></figcaption></figure>

The command `date` can also be run to check the current date and time.

Finally, the following commands can also be used to obtain more information:

```
systemctl status systemd-timesyncd
timedatectl timesync-status
timedatectl show-timesync
```

* **Review configuration file**

Run the command: `cat /etc/systemd/timesyncd.conf`

If the local NTP Server has been configured, the file should look like:

{% tabs %}
{% tab title="timesyncd.conf" %}

```
[Time]
NTP=
FallbackNTP=192.168.1.1
```

{% endtab %}
{% endtabs %}

The use of FallbackNTP is taken from here <https://developers.google.com/time/guides#systemd-timesyncd>
