0

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.

5
  • are your interfaces actually configured using 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). Commented Jun 27, 2023 at 9:04
  • @MarcusMüller I'm not sure. Is there a way to find out, other than renaming the dhclient binary and seeing if it fails? (I'm using Devuan Chimaera here, a systemd-free Debian-based distro, if that makes a difference.) Commented Jun 27, 2023 at 9:11
  • yeah, that makes a difference. On a systemd-based distro, you'd do this with NetworkManager or systemd-networkd, which basically bring the functionality you need – it's a bit surprising you're not using systemd in a situation where you need all the strengths of systemd (dynamic system reconfiguration, continuous exchange on the state of the machine, these kinds of things). Are you sure you want to go with Devuan in this particular use case? Seems a bit like going with a harder-than-necessary choice. Commented Jun 27, 2023 at 10:24
  • @MarcusMüller Yes, Devuan is a project requirement. Commented Jun 27, 2023 at 11:54
  • ah, darn, I guessed as much. Well, you're in bad luck then, I guess, and will have to duct tape this together. I'm sorry for these constraints you have no control over! Commented Jun 27, 2023 at 12:07

1 Answer 1

0

If you are in fact using dhclient, then you can replace the default dhclient script (often /usr/sbin/dhclient-script, but possibly elsewhere) with a custom script. You then have full control over what you do with information obtained from the DHCP lease.

Use the original script as your starting point, and then modify it so that instead of setting the default route it writes the gateway information to a file.

The man page has details on how the script is called.

0

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.