Score:0

Netplan static address plus dhcp address on same interface with priority to static address

az flag

I have a small home server than I occasionally move between networks. I want it to have a static IP for accessing services running on it, but also a DHCP IP so that when I move networks it will always pick up a routable address.

My config looks like this so far:

network:
  version: 2
  renderer: NetworkManager
  ethernets:
    eno1:
      dhcp4: yes
      dhcp6: no
      addresses:
        - 192.168.188.2/24
      gateway4: 192.168.188.1
      nameservers:
        addresses: [127.0.0.1, 1.1.1.1]

This does seem to work and I end up with two IP addresses on the same interface, in the same subnet.

I know that it is possible to set a priority using the metric property. Is that possible with this set up? I would like the static IP to have priority. Does that even make any sense? I am unsure if "priority" makes any difference if they both have the same interface and gateway.

I have tried lowering the dchp priority with:

...
      dhcp4-overrides:
        route-metric: 200

But that seems to set the metric on both addresses:

❯ ip route
...
192.168.188.0/24 dev eno1 proto kernel scope link src 192.168.188.2 metric 200
192.168.188.0/24 dev eno1 proto kernel scope link src 192.168.188.228 metric 200

Is what I want to do possible? Does it even make sense?

Thanks!

Score:0
us flag

It sounds like the situation you're describing is that you want to have a static address for the machine on your home network, but you also want the machine to have networking when not on your home network.

The conventional way to handle this is by configuring your home DHCP server to assign a static address to the machine, not by having both a dynamic dhcp-assigned address plus a statically configured address. This would simplify your client config significantly.

Another option is to resolve the services on this machine using mdns (local name resolution; aka RendezVous) instead of on a static IP address. However this generally requires all machines wishing you connect to your services to be in the same broadcast domain (AKA local network segment) which may not be the case here.

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.