[07:15] <slyon> Lucas8037: Is this for `netplan apply`? Does it work after a reboot?
[09:52] <Jay50> Hi Netplan :)  I'm trying to add a second IP address to an interface
[09:54] <Jay50> When I use ip addr add <ip> dev eth0 , it adds it in the expected order (second)... when I use a netplan drop-in, then netplan apply, it adds it first... (I think this is because the primary IP has a limited lft, while my second IP has an lft of forever). Anyway to explicitly set priority for the addresses?
[10:01] <slyon> Jay50: can you show your YAML config? usually the first IP of the list is set as the primary. Maybe it changes the order if you define lifetime for one of them but not the other?
[10:02] <slyon> in this case a workaround might be to add some additional parameters to the other one as well (e.g. a random label)
[10:06] <Jay50> # cat /etc/netplan/50-cloud-init.yaml# This file is generated from information provided by the datasource...network:    ethernets:        eth0:            dhcp4: true            dhcp6: false            match:                macaddress: <....>            set-name: eth0    version: 2
[10:07] <Jay50> ```# cat /etc/netplan/80-public.yaml network:  version: 2  ethernets:    eth0:      addresses:      - <...>/32```
[10:07] <Jay50> Apologies apparently I'm terrible at formatting things
[10:07] <slyon> thats fine
[10:08] <slyon> but here only one IP address is defined in 80-public.yaml, right?
[10:08] <slyon> 80-public.yaml (eth0) will overwrite 50-cloud-init.yaml (eth0)
[10:09] <slyon> so if you want to have a DHCP4 address and your manual address, you'd need to add `dhcp4: true` to 80-public.yaml as well
[10:09] <Jay50> I thought it might too, but in fact it does not, both the DHCP and static IP are present on the interface after `netplan apply`
[10:10] <Jay50> Only the order is unexpected
[10:11] <Jay50> On a machine where the address in 50-cloud-init has a lifetime of forever, applying 80-public correctly appends the address to the interface
[10:11] <slyon> is this after a clean reboot or some intermediate state, where the DHCP address might have been there before defining the manual IP?
[10:11] <Jay50> When the address in 50-cloud-init has a limited lifetime, the address in 80-public supersedes the address in 50-cloud-init
[10:12] <slyon> and you define that limited lifetime on the DHCP server?
[10:13] <Jay50> Unfortunately not, my cloud service provider defines that
[10:13] <Jay50> I'm currently working around it by simply using `ip addr add ...` since that maintains the correct order
[10:14] <slyon> Okay.. so the IP from DHCP is supposed to be the primary and your 80-public IP is supposed to be the secondary, correct?
[10:15] <Jay50> Yes exactly
[10:15] <slyon> Alright, I think I know what's going on then:
[10:15] <slyon> Usually the first IP address assigned is set to be the primary.
[10:16] <slyon> So if netplan knows about a manual address, it will assign it right away, while the DHCP request/response takes some time and is thus assigned afterwards, becoming the secondary.
[10:16] <Jay50> Makes sense
[10:17] <slyon> If you do it manually, you do it after DHCP is finished, thus having the expected order.
[10:19] <slyon> Unfortunately, I think there is now way to fix this in netplan config. But you could add your "ip addr add ..." command to the "routable.d" hook in networkd-dispatcher, to make it run after the interface is UP (i.e. configured via DHCP): https://netplan.io/faq/#use-pre-up%2C-post-up%2C-etc.-hook-scripts
[10:20] <Jay50> Alright, thats sounds like my best option
[10:20] <Jay50> Thanks a million for your help
[10:20] <slyon> yw
[10:20] <Jay50> Have a great day
[10:20] <slyon> thank, same to you!