setting ip address removes / replaces first of aliases

From: Andriy Gapon <avg_at_FreeBSD.org>
Date: Thu, 13 Nov 2025 17:42:54 UTC
I've just been toying with IP configurations and made a curious (but not very 
surprising observation).

If I set an IP address on an interface, then add a bunch of aliases, then remove 
the original IP address and then finally set it again, then the first of the 
aliases gets removed.

This is not surprising because after removing the original IP address, the first 
of the aliases becomes kind of _the_ IP address.  That's because all interface 
addresses are equal regardless of whether an address was set or added (in other 
words, there is no "the" address).  So, when the original address is set again, 
it replaces(*) what was the first alias.

It's basically just the semantics of those operations.  Setting an address 
replaces the first of already present addresses, if any.  Adding an alias just 
appends another address.

But in a sense this is curious because the behavior breaks imaginary distinction 
between the main address and the aliases.  One might have expected that removing 
and then setting again the main address would not affect the aliases.

In summary, I think that the replacement behavior makes perfect sense when there 
is only one address on an interface.  But with multiple addresses it's not clear 
that setting an address is intended to replace whatever happens to be the first 
of the present addresses.
And if we do the replacement then it better be the in-place replacement unlike 
what we actually do now.  That is, the new address should be the first in the list.

(*) -- from what I can see, it's not exactly an in-place replacement, it's 
remove the first of the existing addresses and append the new one.

P.S.
Just in case, my terminology:
setting an address: ifconfig $if a.b.c.d
adding an alias: ifconfig $if alias a.b.c.d
removing an address: ifconfig $if -alias a.b.c.d

-- 
Andriy Gapon