Solved Missing alias with DHCP configuration

I need multiple IP on my homelab server with this configuration:

Code:
#/etc/rc.conf
ifconfig_re0="DHCP"
ifconfig_re0_alias0="inet 192.168.1.100 netmask 255.255.255.255"
ifconfig_re0_alias1="inet 192.168.1.101 netmask 255.255.255.255"
ifconfig_re0_alias2="inet 192.168.1.102 netmask 255.255.255.255"
ifconfig_re0_alias3="inet 192.168.1.103 netmask 255.255.255.255"
ifconfig_re0_alias4="inet 192.168.1.104 netmask 255.255.255.255"

Code:
# ifconfig re0
re0: flags=1008843<UP,BROADCAST,RUNNING,SIMPLEX,MULTICAST,LOWER_UP> metric 0 mtu 1500
    options=8209b<RXCSUM,TXCSUM,VLAN_MTU,VLAN_HWTAGGING,VLAN_HWCSUM,WOL_MAGIC,LINKSTATE>
    ether 70:71:de:ad:be:ef
    inet 192.168.1.101 netmask 0xffffffff broadcast 192.168.1.101
    inet 192.168.1.102 netmask 0xffffffff broadcast 192.168.1.102
    inet 192.168.1.103 netmask 0xffffffff broadcast 192.168.1.103
    inet 192.168.1.104 netmask 0xffffffff broadcast 192.168.1.104
    inet 192.168.1.13 netmask 0xffffff00 broadcast 192.168.1.255
    media: Ethernet autoselect (1000baseT <full-duplex>)
    status: active
    nd6 options=29<PERFORMNUD,IFDISABLED,AUTO_LINKLOCAL>
All is fine except that, at boot, the first alias ( alias0) is missing (or ignored). I try from alias1 to alias5 but it's the same. Is this a bug?
Regards
 
The SYNCDHCP option fix the issue

Code:
#/etc/rc.conf
ifconfig_re0="SYNCDHCP"
ifconfig_re0_alias0="inet 192.168.1.100 netmask 255.255.255.255"
ifconfig_re0_alias1="inet 192.168.1.101 netmask 255.255.255.255"
...
 
Good catch! That only works at boot. A fix is to create /etc/dhclient-exit-hooks as follow:
sh:
#!/bin/sh
#
# File :  /etc/dhclient-exit-hooks

if [ "${interface}" != "re0" ] ; then
     exit
fi
case "${reason}" in
BOUND|RENEW|REBIND|REBOOT)
    /sbin/ifconfig ${interface} inet 192.168.1.100 netmask 255.255.255.255 alias
    /sbin/ifconfig ${interface} inet 192.168.1.101 netmask 255.255.255.255 alias
    /sbin/ifconfig ${interface} inet 192.168.1.102 netmask 255.255.255.255 alias
    /sbin/ifconfig ${interface} inet 192.168.1.103 netmask 255.255.255.255 alias
    /sbin/ifconfig ${interface} inet 192.168.1.104 netmask 255.255.255.255 alias
    ;;
esac
Source: dhclient-script(8) + Claude AI
 
DHCP and fixed addresses on the same interface is always problematic. Let alone multiple IPs in the same subnet and broadcasting domain. This calls for trouble and weird behavior.
I suspect you need all those IPs in the same subnet for a classic non-vnet jail setup? I highly suggest moving to a vnet-based setup; this way you don't have to deal with such interferences and edge-cases.
 
When a jail starts it will automagically add its IP as an alias to the interface and removes it when the jail stops. You do not need to "pre-assign" them. Just remove all those aliases and make sure it's properly set up in your jail.conf.

And I agree, don't mix DHCP and static addresses on the same interface, things can go weird when DHCP tries to renew or renegotiate and your primary (i.e. the first) IP address on your interface shifts.
 
It's not only DHCP that is the issue here.

Here is a copy of an email that I sent to net@.
I couldn't quickly find a link to that message in the mailing list archive, so took the easy way.

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

I do not recall getting any replies or followups.
 
Back
Top