# How to synchronize time between two devices on a local network using NTPD, with one device serving as both client and server on separate interfaces?

**URL:** <https://community.ntppool.org/t/how-to-synchronize-time-between-two-devices-on-a-local-network-using-ntpd-with-one-device-serving-as-both-client-and-server-on-separate-interfaces/3228>\
**Category:** Pool Development\
**Created:** [February 8, 2024, 9:44am UTC](https://community.ntppool.org/t/how-to-synchronize-time-between-two-devices-on-a-local-network-using-ntpd-with-one-device-serving-as-both-client-and-server-on-separate-interfaces/3228 "2024-02-08T09:44:12Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![BalajiG](https://avatars.discourse-cdn.com/v4/letter/b/3da27b/32.png) [@BalajiG](https://community.ntppool.org/u/BalajiG)\
**Post date:** [February 8, 2024, 9:44am UTC](https://community.ntppool.org/t/how-to-synchronize-time-between-two-devices-on-a-local-network-using-ntpd-with-one-device-serving-as-both-client-and-server-on-separate-interfaces/3228/1 "2024-02-08T09:44:12Z")

</div>

I am using STM32MP1 based two devices which runs on Yocto platform(Kernel version 4.19.9). Among them one has two network interfaces (wlan0, wlan1) where wlan0 is used for connecting with internet servers & wlan1 will be acting as host network for another device to connect with this. I am using `ntpd` (version: ntpd 4.2.8p13@1.3847) for Time Synchronization. I had a common `ntp.conf` for both devices.

```auto
driftfile /var/lib/ntp/drift
server 127.127.1.0
fudge 127.127.1.0 stratum 14
restrict default

```

Also DHCP client configuration also same for both devices.

```auto
request subnet-mask, broadcast-address, time-offset, routers,
        domain-name, domain-name-servers, host-name,
        netbios-name-servers, netbios-scope;

```

I neither had the specific servers mentioned in the `ntp.conf` file nor did my device’s DHCP client explicitly request `ntp-servers`. However, my primary device (which has two network interfaces) can still synchronize with the time servers provided by my Wi-Fi router.

But my secondary device can’t get time sync understandably it can’t reach time servers directly. The issue is the primary device is not acting as NTP server (on wlan1) for the secondary device to get timesync. I have used `udhcpd` on primary device for the secondary device to connect, below is the `udhcpd.conf` used,

```auto
start 192.168.10.100
end 192.168.10.200
interface wlan1
option subnet 255.255.255.0
option router 192.168.10.1
option lease 43200
option dns 192.168.10.1
option domain local

```

So I changed the `ntp.conf` files as below  
#Primary device should act as an NTP client on wlan0 and as an NTP server on wlan1.

```auto
driftfile /var/lib/ntp/drift
server 127.127.1.0
fudge 127.127.1.0 stratum 14
interface listen all
restrict 192.168.10.0 mask 255.255.255.0 nomodify notrap

```

#Secondary device should act as NTP client only listen to primary device

```auto
driftfile /var/lib/ntp/drift
server 192.168.10.1 iburst minpoll 3 maxpoll 6
server 127.127.1.0
fudge 127.127.1.0 stratum 14
restrict 192.168.10.1

```

**But still my secondary device’s time is not getting synced? what is the problem how to overcome this?**

And I captured netstat output for both devices which seems to be Ok.  
**Primary device**

```auto
root@stm32mp1-disco:~# netstat -tuln | grep 123
udp 0 0 192.168.10.1:123 0.0.0.0:*
udp 0 0 192.168.0.127:123 0.0.0.0:*
udp 0 0 127.0.0.1:123 0.0.0.0:*
udp 0 0 0.0.0.0:123 0.0.0.0:*
udp 0 0 fe80::a2cd:f3ff:fe38:2d7b:123 :::*
udp 0 0 fe80::a2cd:f3ff:fe38:2d7b:123 :::*
udp 0 0 ::1:123 :::*
udp 0 0 :::123 :::*

```

**Secondary device**

```auto
root@stm32mp1-disco:~# netstat -tuln | grep 123
udp 0 0 192.168.10.100:123 0.0.0.0:*
udp 0 0 127.0.0.1:123 0.0.0.0:*
udp 0 0 0.0.0.0:123 0.0.0.0:*
udp 0 0 fe80::a2cd:f3ff:fe35:a045:123 :::*
udp 0 0 ::1:123 :::*
udp 0 0 :::123 :::*

```

Please help me to overcome this.

---

<div class="post-metadata">

**Author:** ![NTPman](https://sea2.discourse-cdn.com/flex016/user_avatar/community.ntppool.org/ntpman/32/450_2.png) [@NTPman](https://community.ntppool.org/u/NTPman)\
**Post date:** [February 8, 2024, 1:33pm UTC](https://community.ntppool.org/t/how-to-synchronize-time-between-two-devices-on-a-local-network-using-ntpd-with-one-device-serving-as-both-client-and-server-on-separate-interfaces/3228/2 "2024-02-08T13:33:42Z")

</div>

@BalajiG , welcome to the community!

Did you check on the primary device, is there host firewall configuration blocking inbound NTP access?

---

<div class="post-metadata">

**Author:** ![Bas](https://sea2.discourse-cdn.com/flex016/user_avatar/community.ntppool.org/bas/32/465_2.png) [@Bas](https://community.ntppool.org/u/Bas)\
**Post date:** [February 8, 2024, 1:43pm UTC](https://community.ntppool.org/t/how-to-synchronize-time-between-two-devices-on-a-local-network-using-ntpd-with-one-device-serving-as-both-client-and-server-on-separate-interfaces/3228/3 "2024-02-08T13:43:00Z")

</div>

You didn’t configure IPv6 access but it uses IPv6.  
As such they don’t connect.

Try using both lines:

```auto
restrict default kod nomodify notrap nopeer noquery
restrict -6 default kod nomodify notrap nopeer noquery

```

Local networks are non-routable anyway, so no need to restrict to them if nobody routes them outside.  
If you do not want to use IPv6, run ntpd with -4 parameter.

Edit /etc/default/ntp file and change NTPD\_OPTS=‘-g’ to NTPD\_OPTS=‘-g -4’

Then it will only listen to IPv4 and ignores IPv6 in total.

---

<div class="post-metadata">

**Author:** ![davehart](https://sea2.discourse-cdn.com/flex016/user_avatar/community.ntppool.org/davehart/32/1411_2.png) [@davehart](https://community.ntppool.org/u/davehart)\
**Post date:** [February 8, 2024, 2:17pm UTC](https://community.ntppool.org/t/how-to-synchronize-time-between-two-devices-on-a-local-network-using-ntpd-with-one-device-serving-as-both-client-and-server-on-separate-interfaces/3228/4 "2024-02-08T14:17:08Z")

</div>

The problem is you’ve told each device to synchronize to itself via the obsolete local clock driver 127.127.1.0 driver. The fallback functionality provided by that driver is now handled by a built-in orphan mode.

Modify both ntp.conf files to remove both lines referencing 127.127.1.0. Add to both files:

> `tos orphan 11`

On the primary device with internet access add:

```auto
pool 2.pool.ntp.org. iburst
manycastserver 224.1.2.3

```

On the device without internet access add:

`manycastclient 224.1.2.3 iburst maxpoll 7`

Stop ntpd on both devices and delete `/var/lib/ntp/drift` as neither has actually calculated a meaningful frequency offset from UTC, and the 0.000 they have will dramatically slow the initial frequency correction.

Restart ntpd on the device with internet access and give it at least 15, preferably 30 minutes to find a cohort of pool servers and refine its frequency offset. Then restart the inside ntpd.

Using ntpd’s manycast server discovery scheme insulates the ntp.conf files from any need to know the IP addresses involved, and makes it easy to add additional devices with or without internet access. If you prefer, you could use IPv6 for the multicast addresses replacing `224.x.y.z` with `ff02::xyz` or `ff02::x:y:z` etc.

Let us know how it goes for you.

---

<div class="post-metadata">

**Author:** ![ebahapo](https://sea2.discourse-cdn.com/flex016/user_avatar/community.ntppool.org/ebahapo/32/1152_2.png) [@ebahapo](https://community.ntppool.org/u/ebahapo)\
**Post date:** [February 8, 2024, 3:13pm UTC](https://community.ntppool.org/t/how-to-synchronize-time-between-two-devices-on-a-local-network-using-ntpd-with-one-device-serving-as-both-client-and-server-on-separate-interfaces/3228/5 "2024-02-08T15:13:18Z")

</div>

> [@davehart](#):
>
> you could use IPv6 for the multicast addresses replacing `224.x.y.z` with `ff02::xyz` or `ff02::x:y:z` etc.

Rather, the IPv6 multicast address for NTP is `ff02::101`. Likewise, the multicast IPv4 address for NTP is `224.0.1.1`.

---

<div class="post-metadata">

**Author:** ![davehart](https://sea2.discourse-cdn.com/flex016/user_avatar/community.ntppool.org/davehart/32/1411_2.png) [@davehart](https://community.ntppool.org/u/davehart)\
**Post date:** [February 8, 2024, 3:36pm UTC](https://community.ntppool.org/t/how-to-synchronize-time-between-two-devices-on-a-local-network-using-ntpd-with-one-device-serving-as-both-client-and-server-on-separate-interfaces/3228/6 "2024-02-08T15:36:55Z")

</div>

Yes, IANA reserved those multicast addresses for NTP. I recommend using different addresses intentionally, in case your multicast leaks to a wider audience. Very few, if any, upstream connections will relay multicast upstream without specific configuration, but in academic or research networks the network administrators may be using those reserved addresses and other uses might conflict. If you control your entire network up to the upstreams, and you know those upstreams are not propagating multicast from your network, you might choose to use the reserved NTP multicast addresses. You might also choose to have more than one self-organizing NTP subnet and use different addresses for each.

---

<div class="post-metadata">

**Author:** ![ebahapo](https://sea2.discourse-cdn.com/flex016/user_avatar/community.ntppool.org/ebahapo/32/1152_2.png) [@ebahapo](https://community.ntppool.org/u/ebahapo)\
**Post date:** [February 8, 2024, 4:28pm UTC](https://community.ntppool.org/t/how-to-synchronize-time-between-two-devices-on-a-local-network-using-ntpd-with-one-device-serving-as-both-client-and-server-on-separate-interfaces/3228/7 "2024-02-08T16:28:35Z")

</div>

Those are sensible concerns, but your recommendation contradicts them. Only the `224.0.0.0/24` range is not routable. In this range, there are some addresses not yet assigned, within the `224.0.0.123-149` and `224.0.0.153-250` ranges, which should be chosen instead.

As for the IPv6 NTP multicast address, since its scope is local, it’s not routable by definition.

Finally, the original scenario is totally under control.

---

<div class="post-metadata">

**Author:** ![BalajiG](https://avatars.discourse-cdn.com/v4/letter/b/3da27b/32.png) [@BalajiG](https://community.ntppool.org/u/BalajiG)\
**Post date:** [February 9, 2024, 6:00am UTC](https://community.ntppool.org/t/how-to-synchronize-time-between-two-devices-on-a-local-network-using-ntpd-with-one-device-serving-as-both-client-and-server-on-separate-interfaces/3228/9 "2024-02-09T06:00:51Z")

</div>

Thanks @Bas

My issue is resolved after using

```auto
restrict default kod nomodify notrap nopeer noquery
restrict -6 default kod nomodify notrap nopeer noquery

```

On both devices. Also, I removed restrict line for local network based on your suggestion.  
Primary device:

```auto
driftfile /var/lib/ntp/drift
server 127.127.1.0
fudge 127.127.1.0 stratum 14
restrict default kod nomodify notrap nopeer noquery
restrict -6 default kod nomodify notrap nopeer noquery

```

Secondary device:

```auto
driftfile /var/lib/ntp/drift
server 192.168.10.1 iburst minpoll 3 maxpoll 6
server 127.127.1.0
fudge 127.127.1.0 stratum 14
restrict default kod nomodify notrap nopeer noquery
restrict -6 default kod nomodify notrap nopeer noquery

```

Thank you again. Have a good day!

Regards,  
Balaji G.

---

<div class="post-metadata">

**Author:** ![BalajiG](https://avatars.discourse-cdn.com/v4/letter/b/3da27b/32.png) [@BalajiG](https://community.ntppool.org/u/BalajiG)\
**Post date:** [February 9, 2024, 6:08am UTC](https://community.ntppool.org/t/how-to-synchronize-time-between-two-devices-on-a-local-network-using-ntpd-with-one-device-serving-as-both-client-and-server-on-separate-interfaces/3228/10 "2024-02-09T06:08:24Z")

</div>

Thank you @NTPman,

I confirmed that host firewall configuration is not blocking inbound NTP access.

---

<div class="post-metadata">

**Author:** ![BalajiG](https://avatars.discourse-cdn.com/v4/letter/b/3da27b/32.png) [@BalajiG](https://community.ntppool.org/u/BalajiG)\
**Post date:** [February 9, 2024, 6:10am UTC](https://community.ntppool.org/t/how-to-synchronize-time-between-two-devices-on-a-local-network-using-ntpd-with-one-device-serving-as-both-client-and-server-on-separate-interfaces/3228/11 "2024-02-09T06:10:01Z")

</div>

Hi @davehart

Thank you so much for providing another way of solution. It worked.

Have a great day!

Regards,  
Balaji G.

---

<div class="post-metadata">

**Author:** ![BalajiG](https://avatars.discourse-cdn.com/v4/letter/b/3da27b/32.png) [@BalajiG](https://community.ntppool.org/u/BalajiG)\
**Post date:** [February 9, 2024, 6:11am UTC](https://community.ntppool.org/t/how-to-synchronize-time-between-two-devices-on-a-local-network-using-ntpd-with-one-device-serving-as-both-client-and-server-on-separate-interfaces/3228/12 "2024-02-09T06:11:22Z")

</div>

Thanks @ebahapo for your in-depth clarification.

---

<div class="post-metadata">

**Author:** ![davehart](https://sea2.discourse-cdn.com/flex016/user_avatar/community.ntppool.org/davehart/32/1411_2.png) [@davehart](https://community.ntppool.org/u/davehart)\
**Post date:** [July 21, 2024, 5:22pm UTC](https://community.ntppool.org/t/how-to-synchronize-time-between-two-devices-on-a-local-network-using-ntpd-with-one-device-serving-as-both-client-and-server-on-separate-interfaces/3228/13 "2024-07-21T17:22:16Z")

</div>

> [@Bas](#):
>
> You didn’t configure IPv6 access but it uses IPv6.  
> As such they don’t connect.

Just for future reference of others reading this post, I want to clarify that IPv6 had nothing to do with his problem. All of the original poster’s configuration files in this thread, including the initial one to which you referred, used only IPv4 addresses not hostnames, so no IPv6 traffic or settings came into play.

I suspect you had in mind how DNS resolution of hostnames tends to prefer IPv6 over IPv4, and some systems have only local IPv6 but internet IPv4. Combined with ntpd using only the first IP address returned from a DNS lookup, this could result in `server some.example.org` spinning up a useless IPv6 association and staying with it forever, while either invoking `ntpd -4` or instead using `server -4 some.example.org` would work around the problem.
