I’ve tweaked it yet again, trying to get this as simple as possible.
The router is now using a subnet of 255.255.255.0
(previously it was 255.255.0.0
).
I’ve configured eth0
to have a static address of 192.168.1.10/24
and wlan0
to have a static address of 192.168.1.20/24
.
I have also ran nmcli connection modify wlan0 802-11-wireless.mac-address-randomization 1
to stop the randomising of the mac whilst testing, and likewise nmcli connection modify wlan0 802-11-wireless.powersave 2
to disable any powersaving. Hopefully I can revert these two settings once I bottom out this remaining issue.
I’ve added a /etc/NetworkManager/dispatcher.d
script thus:
#!/bin/bash
function enable_disable_wifi() {
result=$(nmcli dev | grep "ethernet" | grep -w "connected")
if [ -n "$result" ]; then
nmcli radio wifi off
else
nmcli radio wifi on
ping -c 3 -4 -R 8.8.8.8 > /var/home/adam/ping.txt
url https://ifconfig.co/json > /var/home/adam/ifconfig.txt
fi
}
if [ "$2" = "up" ]; then
enable_disable_wifi
fi
if [ "$2" = "down" ]; then
enable_disable_wifi
fi
Ref: Example 15 in nmcli-examples: NetworkManager Reference Manual
The idea here being if ethernet is plugged in wifi is turned off entirely, and if ethernet is removed wifi is turned on.
With ethernet plugged in I can successfully ssh to 192.168.1.10
. When I remove ethernet the dispatcher script runs:
In ping.txt
I can see:
PING 8.8.8.8 (8.8.8.8) 56(124) bytes of data.
64 bytes from 8.8.8.8: icmp_seq=1 ttl=119 time=21.5 ms
64 bytes from 8.8.8.8: icmp_seq=2 ttl=119 time=365 ms
64 bytes from 8.8.8.8: icmp_seq=3 ttl=119 time=599 ms
--- 8.8.8.8 ping statistics ---
3 packets transmitted, 3 received, 0% packet loss, time 2002ms
rtt min/avg/max/mdev = 21.542/328.430/598.538/236.989 ms
And in ifconfig.txt
:
{
"ip": "<redact>",
"ip_decimal": <redact>,
"country": "United Kingdom",
"country_iso": "GB",
"country_eu": true,
"latitude": <redact>,
"longitude": <redact>,
"time_zone": "Europe/London",
"asn": "<redact>",
"asn_org": "<redact>",
"hostname": "<redact>",
"user_agent": {
"product": "curl",
"version": "7.85.0",
"raw_value": "curl/7.85.0"
}
So it seems like it has definitely connected to the wifi, has internet access, and is correctly doing dns resolution.
However if I use Fing
on my phone to scan the network I can’t see 192.168.1.20
connected to the router, nor can I see it when I log into the router directly (I presume this latter is just the router software not updating efficiently).
Similarly if I ping 192.168.1.20
from my mac I get:
% ping 192.168.1.20
PING 192.168.1.20 (192.168.1.20): 56 data bytes
Request timeout for icmp_seq 0
Request timeout for icmp_seq 1
Request timeout for icmp_seq 2
^C
--- 192.168.1.20 ping statistics ---
4 packets transmitted, 0 packets received, 100.0% packet loss
And equally a nil response if trying to ssh.
So I feel that I’m almost there with this there is just this last little niggle of other devices being able to pick up the change.