Score:0

Obtaining two DHCP addresses on Linux

br flag

There have been various questions asked a long time ago about obtaining two IP addresses via DHCP on Linux. Most of those are still relating to old 'alias interfaces', like eth0:0, which has been deprecated for a long time.

As referenced in this question, it should be possible to get multiple IP addresses by using send dhcp-client-identifier with different values, and indeed there is a partial example of this in the manual page for dhclient.conf

But that refers to "you must also provide a separate client script for the pseudo-interface" to configure it. Such a script would presumably need to run ip address add and ip address del for the secondary IP address when the DHCP client reaches the right states.

Is there any example anywhere out there of a working version of such a script? And will it work with the default script for the primary address (which seems to be very enthusiastic in deleting any and all other IP addresses on the interface)

Has anyone ever got such a setup to work?

A.B avatar
cl flag
A.B
The enthusiasm is from the kernel, not a script: https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/tree/Documentation/networking/ip-sysctl.rst?h=v5.15#n1661
br flag
If you are referring to the `promote_secondaries` flag, then that does the opposite - it retains a secondary IP when the primary is removed. I'm referring to lines like `ip -4 addr flush dev ${interface} label ${interface}` in `/sbin/dhclient-script`, which will flush all IP addresses on an interface when the interface gets a `BOUND`, `RENEW`, `REBIND` or `REBOOT` event in some cases. It may be that the script arguments are always such that the line does not get called, but it is hard to tell.
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.