Ant232
Posts: 115
Joined: Thu Jul 12, 2012 9:34 pm

Can I Force Timesync(NTP) to use wifi

Mon May 27, 2019 11:10 am

Hi all,

I have a strange setup where the eth0 is connected to a network that has no internet access or NTP server. I also have a wifi adapter that connects to a network that does have access to an NTP server.
Timesync (I'm using Stretch) seems to priorities eth0 when it looks for the NTP server (I am not sure of this, but that's what seems to be happening). When I have both connected it doesn't see the NTP serve but when I dissconnect the eth0 cable and leave it unplugged for a little while the Pi then gets it's NTP sync.
Is there any way to get Timesync to 'default' to wlan?

Many thanks
Ant

Andyroo
Posts: 4180
Joined: Sat Jun 16, 2018 12:49 am
Location: Lincs U.K.

Re: Can I Force Timesync(NTP) to use wifi

Mon May 27, 2019 11:24 am

Try editing the /etc/ntp.conf

Code: Select all

interface listen wlan0
interface ignore eth0
Change the names to match yours though :lol: and restart the time service (or Pi)

I do not have a Pi handy with two network interfaces at the mo. so that’s untested :oops:
Need Pi spray - these things are breeding in my house...

epoch1970
Posts: 3555
Joined: Thu May 05, 2016 9:33 am
Location: Paris, France

Re: Can I Force Timesync(NTP) to use wifi

Mon May 27, 2019 1:16 pm

It could rather be a matter of route priority. On Raspbian ethernet has priority over wifi.
By default dhcpcd gives metric 200+ to ethernet interfaces and metric 300+ to wireless interfaces. Metric 0 denotes the highest priority.
If multiple interfaces can lead to the same destination (e.g. default route or network 192.168.x.x) the one with highest priority, e.g. eth0, metric 202 is chosen.

To give priority to wlan0, add "metric 100" to the "interface wlan0" block in dhcpcd.conf, or conversely add "metric 400" to the "interface eth0" block.
Last edited by epoch1970 on Mon May 27, 2019 4:10 pm, edited 1 time in total.
"S'il n'y a pas de solution, c'est qu'il n'y a pas de problème." Les Shadoks, J. Rouxel

Ant232
Posts: 115
Joined: Thu Jul 12, 2012 9:34 pm

Re: Can I Force Timesync(NTP) to use wifi

Mon May 27, 2019 1:41 pm

Thank you for the replies. Extraordinarily useful.. Sorry but there is another scenario that I should have included in my original post, that is that sometimes eth0 will have the NTP ref on it.

@Andyroo Thank you for your reply. I have to find a way to priorities the interface that the Pi gets it NTP reference. I have to leave both eth0 and wlan0 as possible options. That failing, your suggestion could be a plan B, so thank you for that.

@epoch1970 Thank also you for your reply. Would this priorities all traffic. I have node-red running various flows that connect over UDP and TCP with external devices on eth0. The time ref would then have to come from wlan0. But.... (sorry about this :)) there could be a setup where the time ref is from eth0 and wlan0 is not used.

Is there a way that time sync can look for a NTP server on one interface and if it does not find it then it looks at the other interface, meanwhile node-red always has it's communication through eth0.

Thanks again,
Ant

epoch1970
Posts: 3555
Joined: Thu May 05, 2016 9:33 am
Location: Paris, France

Re: Can I Force Timesync(NTP) to use wifi

Mon May 27, 2019 3:03 pm

NTP is a UDP/IP protocol, it uses routing in the OS.
By default linux doesn't care much about interfaces. Only routes/IP addresses matter. You don't select which interface gets used, linux does.
To limit the choices the OS has, you can add specific routes.

Eg

Code: Select all

# ip route show
default via 172.17.0.1 dev eth0 proto dhcp 
default via 172.17.0.1 dev wlan0 proto dhcp metric 100 
...

# ip r get 1.2.3.4
1.2.3.4 via 172.17.0.1 dev eth0 src 172.17.255.230 uid 0 <= eth0 has metric 0, it is chosen
    cache 

# ip r add 1.2.3.4/32 via 172.17.0.1 dev wlan0

# ip r get 1.2.3.4
1.2.3.4 via 172.17.0.1 dev wlan0 src 172.17.255.57 uid 0 <= wlan0 has the most relevant route defined, it is chosen
    cache 

# ip r
default via 172.17.0.1 dev eth0 proto dhcp 
default via 172.17.0.1 dev wlan0 proto dhcp metric 100 
1.2.3.4 via 172.17.0.1 dev wlan0 
...
"S'il n'y a pas de solution, c'est qu'il n'y a pas de problème." Les Shadoks, J. Rouxel

Ant232
Posts: 115
Joined: Thu Jul 12, 2012 9:34 pm

Re: Can I Force Timesync(NTP) to use wifi

Mon May 27, 2019 3:51 pm

@ epoch1970
Thank you for the reply. This will take a little learning so it's 'kettle on time'. I appreciate you time very much.

sushant_ocv
Posts: 15
Joined: Mon May 20, 2019 8:14 am

Re: Can I Force Timesync(NTP) to use wifi

Mon May 27, 2019 5:29 pm

cool, this thread helped me to solve a bit related issue. thanks mate.

Return to “General discussion”