Failure when using recorded lease causes all virtual interfaces to be flushed on Linux
name: Bug report
about: Create a report to help us improve
Describe the bug
If a dhclient
instance isn't able to connect to a DHCP server when it times out it tries to check if one of the previously recoded leases is still valid, and if so tries to use it. dhclient-script
on Linux sets the IP address and Gateway from the lease and tries to ping
the Gateway, when that fails it flushes ALL interfaces (including virtual interfaces) that may have been setup outside of dhclient
.
To Reproduce Steps to reproduce the behavior:
- Run
dhclient
with the default config on a modern Debian/Ubuntu. - Configure the DHCP server on the network to give a longer lease (1hr). This makes it easier to test.
- Ensure that
dhclient
gets the lease from the server. Check if the /var/lib/dhcp/dhclient.eth0.leases file exists. - Create virtual interface using
sudo ip addr add "192.168.42.1/16" brd + dev eth0 label eth0:1
- Verify that the virtual interface (eth0:1) is up using
ip addr
- Disconnect the connection to the DHCP server
- Restart
dhclient
- Wait for
dhclient
to timeout (default 300s) - Check if the virtual interface (eth0:1) is up. It isn't.
Expected behavior The virtual interface (eth0:1) should not be removed even if DHCP request fails.
Environment:
- ISC DHCP version:
- OS: Ubuntu
Additional Information
Looking at the dhclient-script
source for linux, in case of TIMEOUT
and when pinging the recorded lease IP address fails, ALL IP addresses are flushed from the interface :
# flush all IPs from interface
ip -4 addr flush dev ${interface}
from https://gitlab.isc.org/isc-projects/dhcp/-/blob/master/client/scripts/linux#L397
Changing L397 to ${ip} -4 addr flush dev ${interface} label ${interface}
should fix this.
I have tested this with a custom script file. And it seems to fix the issue.