I have a laptop at home that I want to use as a server (Ubuntu 20.04.3 LTS).
I want the IP to stay the same for both eth0
and wlan0
(reason: so that port forwarding which I have set up on the router would stay functional no matter how the laptop is connected to the internet)
When I disconnect cable, I will enable wifi, and vice-versa when cable is connected, I will disable wifi to prevent IP collision. (using nmcli radio wifi on/off
)
This is my configuration:
/etc/netplan/00-installer-config.yaml:
network:
ethernets:
eth0:
optional: true
dhcp4: no
addresses:
- 192.168.0.189/24
# gateway4: 192.168.0.1
nameservers:
addresses:
- 194.168.4.100
- 194.168.8.100
wlan0:
dhcp4: no
addresses:
- 192.168.0.189/24
gateway4: 192.168.0.1
nameservers:
addresses:
- 194.168.4.100
- 194.168.8.100
version: 2
With this setup, I have these problems:
When I connect internet cable and I disable wifi, packets won't know how to reach the internet because eth0 doesn't have any gateway associated to it (because it's commented out as you can see).
if I try to reverse the setup (uncomment the gateway on the eth0 and comment it out for wifi), when I enable wifi and unplug the cable, packets again will not know how to reach internet.
If uncomment gateway4 on both interfaces and do sudo netplan apply
, I get the following error:
** (generate:2959): WARNING **: 22:54:14.848: Problem encountered while validating default route consistency.Please set up multiple
routing tables and use routing-policy
instead. Error: Conflicting
default route declarations for IPv4 (table: main, metric: default),
first declared in wlan0 but also in eth0
So what am I supposed to do do make it work?
EDIT:
So actually the 3rd option actually seems to work with no problem despite the error. And it actually works even when both interfaces are connected simultaneously (a bonus!). But I still don't understand the error message and/or whether someone might think that this is a bad setup for some reason.