-1

I am working with a custom Linux image for an embedded device built with yocto. It has no network management other than the interface configurations for ifup/ifdown. /etc/resolv.conf is created dhcp (dhcpcd) and the system does not have any additional software for managing these files (such as resolvconf or dnsmasq.)

# Generated by dhcpcd from eth0.dhcp
# /etc/resolv.conf.head can replace this line
domain routername.home
nameserver 192.168.0.1

With this set up what is it possible to dynamically update /etc/resolv.conf, and have the updates persist?

Buoy
  • 111
  • Dynamically update the file to do what, exactly? What are you hoping to accomplish? – spuck Sep 16 '21 at 17:47
  • I would like to have my application be able to update /etc/resolv.conf and have the changes persist over network interface restarts when DHCP will re-write the file. – Buoy Sep 17 '21 at 15:44
  • Changing the content of the file should be easy; it's just a file, after all. So your question is how to prevent dhcpd from changing the file at all, or do you sometimes want it to update the file, but not other times? – spuck Sep 17 '21 at 17:33

2 Answers2

0

Just googling update resolv.conf gives me a multitude of results, many from this very community. For example:

How do I set my DNS when resolv.conf is being overwritten?

Knowing your distro would help find the right one. For example this doesn't work on Bunsenlabs Lithium 3, which is Debian 10 -based, but it might help on pure Debian 10.

Peregrino69
  • 2,417
  • Yes, I have reviewed many of these answers but they are all relying on addition software to update the file. I am working on a custom linux image, not a distro, and do not have the ability to install addition packages. – Buoy Sep 15 '21 at 18:49
  • Please update your question. This is all new info relevant to someone trying to help you. Nothing on the link I provided says anything about installing additional packages. Helping out with a custom build is pretty much impossible without having some details - what's it built on? What DHCP client is used? What's managing the network settings? Does your image run DNS within itself? – Peregrino69 Sep 15 '21 at 19:09
  • Please note - I'm not brushing you off, I'm trying to help you improve your chances to finding an answer. Without giving these details in the question the community members need to go through commentaries to understand your situation, have to guess what might or might not work - as both my answer and your comment prove the only valid answer at this point is "it depends". Also knowing what you've already tried without success will help us to help you. – Peregrino69 Sep 15 '21 at 19:18
0

According to its man page, dhcpcd apparently uses dhcpcd-run-hooks to run any number of shell scripts on each DHCP event (e.g. initial acquisition of IP address, renewals, and reconfigurations).

The locations for these hook scripts are given as /libexec/dhcpcd-hooks directory for system default hooks, and /etc/dhcpcd.enter-hook and /etc/dhcpcd.exit-hook for user-defined hooks, but this part could certainly be customized by the system builder.

You could find out where these scripts are located in your custom build, examine them to figure out what they do, and then augment, modify or outright replace the script that modifies your DNS settings to achieve exactly what you want.

The man page of dhcpcd.conf indicates there is even a nohook configuration keyword that can be used to disable one or more hook scripts.

The usage example is highly relevant to your question:

nohook script

Don't run this hook script. Matches full name, or prefixed with 2 numbers optionally ending with .sh. So to stop dhcpcd from touching your DNS settings or starting wpa_supplicant you would do:

nohook resolv.conf, wpa_supplicant
telcoM
  • 96,466