I am building a server that has multiple upstream network interfaces, each of which receives IP addresses, default routes, and other DHCP information from different routers.
For my application, I need to know the gateway for each interface, so that I can set routes to particular hosts and networks through the appropriate interface. The default routes that dhclient sets are not useful and are removed - but I'd like to know the gateway.
- Capturing the DHCP response packet and parsing it is a last resort.
- Getting the information from each default routes (before removing it) is possible, but likely to be unreliable if multiple interfaces come up simultaneously.
How can I intercept the DHCP response information effectively?
Update:
Adding:
# Debug how this is being called.
date >> /tmp/dhclient.log
echo "dhclient-script $@" >> /tmp/dhclient.log
env >> /tmp/dhclient.log
to the start of /sbin/dhclient-script showed me how I needed to modify dhclient-script.
dhclient? That's becoming rare these days – the relevant network interface managers understandably bring their own built-in DHCP clients and typically share what info they get using some specified API (typically, DBUS).