Score:0

Eth0 and Wifi both need the same gateway, same IPs

jp flag

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.

jp flag
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.
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.