OK, looks like I have a solution
Short answer: Use something other than NetworkManager to handle the interfaces. After this HA then canât see them and continues on happily as if they never existed. I chose to use Networkd to manage the ethernet interfaces because its there and dnsmasq for DNS, except the reason for this is slightly complicated.
Long answer:
So, the PC has an ethernet interface via a USB device that receives internet, a WiFi interface in AP mode (hotspot) that connects to all the IoT energy and temperature sensors in my house, and a PCI ethernet interface that shares internet to a small network behind a basic firewall.
The client (USB) interface was just auto-configured by DHCP and the host ethernet interface was usually setup with a static IP and âShared to other computersâ in the Network Manager applet. This is what was getting messed up by HA. HA would reset it to either IPv4 disabled or as a regular DHCP client.
HA can have its way with the WiFi network, as it is there for HA anyway. Fortunately, as youâll read later, it keeps a static IP.
Reading documentation for the Network Manager applet, âShared To Other Computersâ means:
Shared to other computers â Choose this option if the interface you are configuring is for sharing an Internet or WAN connection. The interface is assigned an address in the 10.42.x.1/24 range, a DHCP server and DNS server are started, and the interface is connected to the default network connection on the system with network address translation (NAT).
That was surprisingly hard to come across but it does tell us what to repliccate in Networkd.
So, I made both devices âUnmanagedâ in Network manager by:
15.1. Permanently configuring a device as unmanaged in NetworkManager
⌠2. Create the /etc/NetworkManager/conf.d/99-unmanaged-devices.conf file with the following content:
To configure a specific interface as unmanaged, add:
[keyfile]
unmanaged-devices=interface-name:enp1s0;interface-name:enx*
I made both the PCI interface (enp1s0
) and the USB dongle (enx*
) unmanaged. It is great you can use wild cards here, because the USB dongle changes its name each time it is plugged in.
Setting up the /etc/systemd/network/*.network files is pretty easy, I have 2:
enp1s0.network
:
[Match]
Name=enp1s0
[Network]
Address=192.168.1.123/24
IPForward=ipv4
IPMasquerade=ipv4
DHCPServer=yes
[DHCPServer]
EmitDNS=yes
DNS=192.168.2.123
enx.network
:
[Match]
Name=enx*
[Network]
IPForward=ipv4
DHCP=yes
https://wiki.archlinux.org/title/systemd-networkd
Wild cards can be used here too, which is good. Not sure if the enx*
interface needs a .network
file, but its there.
I tried to setup dnsmasq, for DNS but found it conflicted with a copy of dnsmasq that NetworkManager uses.
For enp1s0
if EmitDNS is listed on its own, it will emit the address of the upstream DNS server address it knows about, the one automatically put in /etc/resolv.conf
, which in this system is the DNS provided on adapter enx*
. This works fine except unfortunately the address is not static and resets every time enx*
is plugged in and out. So, DNS doesnât work until the DHCP leases on enp1s0
expire and then they are resent the DNS address for enx*
at whatever it is when this occurs.
I was struggling to get this to work with dnsmasq, as installing a new dnsmasq instance next to network manager gives a conflict on port 53. But then I noticed that the wifi hotspot has a static IP and a DNS server instance of dnsmasq running on that IP. So, for the DNS=
section of enp1s0
I just gave it that address and it configures the DHCP clients to go to the wifiâs IP for DNS instead of the upstream one from enx*
. dnsmasq handles the changing IP of enx*
.
I believe you can add extra config files to use the dnsmasq instance in NetworkManager for other purposes but I am lucky to not have needed to.
So this all this seems to work, was a necessary learning process for me. This post will kind of act as a reference for me when all this inevitably blows up in the future and I need to remember what I was thinking . But I hope it gets someone else on the right path too.