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:

[root@linux:~] ls -l /etc/resolv.conf 
lrwxrwxrwx    1 root     root           20 Feb  3 18:17 /etc/resolv.conf -> /var/run/resolv.conf
[root@linux:~] 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!

Ask a Question

Get help from others!

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