Score:0

IPv6 source address selection with addrlabel and netplan

cn flag

I have configured my Ubuntu 22.04 via netplan like this:

network:
  version: 2
  renderer: networkd
  ethernets:
    enp3s0:
      addresses:
        - 192.168.10.10/24
        - 2001:db8:6789::10/64
      gateway4: 192.168.10.1
      gateway6: 2001:db8:6789::1
      nameservers:
          search: [example.com]
          addresses: ['2001:db8:6789::5', 192.168.10.5]

This works, and my client gets a static IPv6 and a dynamic IPv6. The latter is preferred as source per default, which is nice regarding privacy when using services on the Internet.

However, when using my services on my LAN, especially NFS, I want to use the client's static IPv6. I can get it to work by using these two commands:

ip addrlabel add prefix 2001:db8:6789::5/128 label 99     # NFS server
ip addrlabel add prefix 2001:db8:6789::10/128 label 99    # NFS client

But how can I make this permanent so this addrlabel is set at boot before the nfs-mounts start (also at boot)?

Score:0
cn flag

To answer my own question:

Firstly, Netplan is not an alternative to (systemd-)networkd or NetworkManager. Netplan is a "network configuration abstraction renderer", and for the example above, netplan actually creates a systemd-networkd file based on the netplan-configuration. It is saved as /run/systemd/network/10-netplan-enp3s0.network, and the content is:

[Match]
Name=enp3s0

[Network]
LinkLocalAddressing=ipv6
Address=192.168.10.10/24
Address=2001:db8:6789::10/64
Gateway=192.168.10.1
Gateway=2001:db8:6789::1
DNS=192.168.10.5
DNS=2001:db8:6789::5
Domains=example.com

So, to add ip addrlabel to my config, I had to create my own systemd-networkd-networkfile. It also needed to be (in lexical order) before the autogenerated file from netplan.

My solution was to create /etc/systemd/network/01-enp3s0.network with the following content:

[Match]
Name=enp3s0

[Network]
LinkLocalAddressing=ipv6
Address=192.168.10.10/24
Address=2001:db8:6789::10/64
Gateway=192.168.10.1
Gateway=2001:db8:6789::1
DNS=192.168.10.5
DNS=2001:db8:6789::5
Domains=example.com

[IPv6AddressLabel]
Label=99
Prefix=2001:db8:6789::5/128

[IPv6AddressLabel]
Label=99
Prefix=2001:db8:6789::10/128
Score:0
us flag

netplan 0.100 and later support label for this as documented at https://netplan.readthedocs.io/en/latest/netplan-yaml/#properties-for-all-device-types. Ubuntu 22.04 includes netplan 0.105, so this is supported.

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.