Score:0

Same IP but for two different interfaces netplan

au flag

I have an ubuntu server 22.04 installation on a laptop with two interfaces wlp3s0 (wireless) and enp3s0 (ethernet). Wireless connection is used at home, ethernet connection is used at the office.

The scenario is this. Office has to be static ip where gateway is 192.168.80.1. I have to add dns nameserver to connect to the internet. Home has to be also the same static ip. Where gateway is 192.168.80.32 (ip of router).

Separately I can make each work with the downside of changing the config file everytime I login. But together I can only enable static IP but no connection to internet. This is the config file

network:
  version: 2
  renderer: networkd
  ethernets:
    enp3s0:
      dhcp4: false
      dhcp6: false
      optional: true
      addresses:
        - 192.168.80.111/24
      routes:
        - to: default
          via: 192.168.80.1
          table: 200
      nameservers:
        addresses:
          - 55.11.22.33
          - 55.11.22.34
  wifis:
    wlp3s0:
      dhcp4: false
      dhcp6: false
      optional: true
      addresses: [192.168.80.111/24]
      nameservers:
        addresses: [192.168.80.32]
      access-points:
        "wifi_conn":
          password: "passconn"
      routes:
        - to: default
          via: 192.168.80.32

The default renderer is networkd. How can I ensure that both interfaces utilize same IP and connect each of them to internet whether wireless or ethernet?

cn flag
"with the downside of changing the config file everytime I login" that can be automated: if wifi finds your ssid use one config otherwise use the other. "Home has to be also the same static ip." I doubt this has to be the same as you can change your internal ip on your router. Do that and you can make 1 config.
llesh avatar
au flag
@Rinzwind I get what you are saying. I can certainly create a script. But I thought a more elegant way is by putting these two in one netplan config. E.g go to wireless network in when no ethernet connection is detected and viceversa
cn flag
netplan does not understand conditions; generally I would expect 2 yaml files with different names something like "10-home.yaml" and "20-work.yaml" and then have systemd switch between the too based on finding a network.
llesh avatar
au flag
Do I have to generate and apply both configs or does systemd do it for me?
user535733 avatar
cn flag
Networkd is simply not designed for the use case of a laptop moving between different networks, each with different requirements. It's seems like the wrong tool for this job, which is why it is frustrating. NetworkManager is specifically designed for this use case -- it seems like a better tool for this job.
cn flag
I am not sure. Never had to use it for 2 with the same IP ;-)
llesh avatar
au flag
@guiverc edited the question
Score:0
au flag

I managed to make it work by putting both of configs in one file. When tried to generate the netplan config, this error appears.

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 enp0s25 but also in wlp3s0

From one of the comments here I went and added two properties metric and optional. metric was used to solve the conflict of default routes whereas optional is set to true so during boot we do not have to wait the network to come up. I will not consider this as a final solution since it is done more like trial and error.

network:
  version: 2
  renderer: networkd
  ethernets:
    enp0s25:
      dhcp4: false
      dhcp6: false
      optional: true
      addresses:
        - 192.168.80.111/24
      routes:
        - to: default
          via: 192.168.80.1
          metric: 100
      nameservers:
        addresses:
          - 55.11.22.33
          - 55.11.22.34
network:
  version: 2
  renderer: networkd
  wifis:
    wlp3s0:
      dhcp4: false
      dhcp6: false
      optional: true
      addresses: [192.168.80.111/24]
      nameservers:
        addresses: [192.168.80.1, 8.8.8.8]
      access-points:
        "wifi_conn":
          password: "passconn"
      routes:
        - to: default
          via: 192.168.80.32
          metric: 200
            #table: 100

Having said all of this I would not consider this as solved as there could be better solutions.

I sit in a Tesla and translated this thread with Ai:

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.