I have a machine (18.04, will be 20.04 at some point) that has a wired NIC as well as a USB card with a wireless one. It is usually connected by cable, but sometimes the cable is disconnected (mechanically, by someone, for various reasons).
I would like to ensure that the static IP 192.168.10.1
is always reachable:
- either via the cable when it is plugged in,
- or via Wi-Fi when it is not.
Is there a standard (or at least reasonable) way to do this?
I saw an answer to a question that was suggesting to assign this IP to the lo
interface:
ip address add IP/32 dev lo
but I am not sure this is a reasonable approach?
The solution was to use networkd-dispatcher. It can be installed via
apt install networkd-dispatcher
but it was already installed on my system.It creates
/usr/lib/networkd-dispatcher
and in there (among others)no-carrier.d
→ this is where to put the script to turn wifi onroutable.d
→ this is where to put the script to turn wifi offI made two scripts along the lines of
I fixed the IP of the wireless card to the same one as the wired one - only one of them is live at a given time.