resolv.conf always empty

Unix & Linux Asked by marc on December 6, 2020

I have 2 different embedded devices…an old one running TI arago Linux and a Xilinx device (petalinux).

On both I see the same outcome when adding dns-nameservers to /etc/network/interfaces and reconfiguring the network with /etc/init.d/networking restart or rebooting the device:
The /etc/resolv.conf file always stays empty.

No dhclient, resolvconf package, network-manager daemon or mdns are present in the system.

Here the /etc/network/interfaces:

# /etc/network/interfaces -- configuration file for ifup(8), ifdown(8)

auto lo
iface lo inet loopback

auto eth0
iface eth0 inet static

and resolv.conf:

[[email protected]:~] ls -l /etc/resolv.conf 
lrwxrwxrwx    1 root     root           20 Feb  3 18:17 /etc/resolv.conf -> /var/run/resolv.conf
[[email protected]:~] ls -l /var/run/resolv.conf
-rw-r--r--    1 root     root            0 Feb  3 18:17 /var/run/resolv.conf

While executing /etc/init.d/networking restart, both devices call basically ifdown -a and then ifup -a, being both ifup and ifdown busybox utilities in this case.

In case mentioning the immutable file attributes solution: I don’t want to generate manually the resolv.conf file and change the file attributes to make it immutable (chattr +i), because it seems completely against how the system was designed. Why is then resolv.conf stored in volatile memory (generated by in the first place, if it should be permanent?

Thanks for any hints!

Update: found the solution, but will leave the question, for the sake of somebody searching for it.

One Answer

Create a script in /etc/network/if-up.d/dns with this content (in this example only eth0 is taken into account):

if [ "$IFACE" = "eth0" ];then
R="${R}nameserver $NS
echo "$R" > /etc/resolv.conf

Make it executable with chmod +x /etc/network/if-up.d/dns.

Everytime you reboot the device or restart the networking services, resolv.conf will be recreated. Works like a charm!

PS: If you use another directive/naming than dns-nameservers in /etc/network/interfaces...for example my-dns, then replace $IF_DNS_NAMESERVERS with $IF_MY_DNS. Although it's cool to know, I would rather stick to conventions and use dns-nameservers.

Answered by marc on December 6, 2020

Add your own answers!

Related Questions

Set permanent environment variable for all shells

0  Asked on October 31, 2021 by user14492


How does jq work with keys containing slash?

1  Asked on October 31, 2021 by fhcat


GRUB not showing up in Pop!_OS

1  Asked on October 31, 2021


Set scale for bc inside a variable

1  Asked on October 31, 2021 by mdem7705


partition size vs file system size

1  Asked on October 31, 2021 by fa7eme


Explanation for “Killed Process”

1  Asked on October 31, 2021 by althor


tracking list of installed packages with git

2  Asked on October 31, 2021 by 400-the-cat


Ask a Question

Get help from others!

© 2022 All rights reserved. Sites we Love: PCI Database, MenuIva, UKBizDB, Menu Kuliner, Sharing RPP, SolveDir