====== Playing with dhclient ====== ===== Goal ===== Sometimes one is faced with a difficult task - a backup link that requires DHCP to configure the interface. In itself, the task does not seem hard. The devil, however, is in the detail. The backup link default route(s) should not be inserted into the default routing table, but rather into a separate table. The goal is to modify dhclient to do what we want while still being able to upgrade the package with security updates without extra work. ===== dhclient-script ===== Upon every event **dhclient** runs ///sbin/dhclient-script//. This script is responsible for configuring the interface and adding routes according to the obtained lease. On release, it does the opposite. Before **dhclient-script** does anything, it sources ///etc/dhcp3/dhclient-enter-hooks// and runs scripts in ///etc/dhcp3/dhclient-enter-hooks.d// ===== dhclient-enter-hooks ===== This is where we hijack the process. On Debian, only the //dhclient-enter-hooks.d// directory exists, the script **dhclient-enter-hooks** is not present. We copy ///sbin/dhclient-script//, and throw out much of the useless stuff (or add more, if that's your thing, but in that case there is probably no need to suppress the default processing, just use a normal hook :) {{:linux:dhclient-enter-hooks.txt|}} Unfortunately, the script requires sipcalc to calculate the prefix length of the connected segment from numeric netmask which is received from dhclient. I would be more than happy to replace it if someone came up with a simple solution in shell :)