0

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.

Daniel Katz
  • 113
  • 6
  • 1
    I found this thread which seems to explain what you are encountering. The user davidgo explained it well. Read the thread and see if you can follow it. https://superuser.com/questions/1686557/netplan-configuration . He also refers to this question as the answer https://askubuntu.com/questions/1008571/how-can-i-configure-default-route-metric-with-dhcp-and-netplan#1014760 –  Nov 25 '21 at 00:39
  • Thanks that plus "netplan.io/reference" helped me. The reference says that gateway4 is deprecated and instead I should see "Default routes". I find the routing config unnecessarily complex though if I just needed to add a metric. I don't quite understand the `to: 0.0.0.0/0` but I used the "default" as it is said that both should work. – Daniel Katz Nov 25 '21 at 15:03

0 Answers0