0

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
    address 192.168.1.2
    netmask 255.255.255.0
    gateway 192.168.1.1
    dns-nameservers 192.168.1.1

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 populate-volatile.sh) 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.

0

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

#!/bin/sh
if [ "$IFACE" = "eth0" ];then
for NS in $IF_DNS_NAMESERVERS; do
R="${R}nameserver $NS
"
done
echo "$R" > /etc/resolv.conf
fi

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.

  • I'm not convinced this is a good solution. Do you have mdns running on these systems? – tripleee Feb 4 at 10:51
  • @tripleee No, mdns is not installed in the system. Can you share a more extended answer on why you are not convinced this is a good solution or do you have a better one? Thanks. – marc Feb 4 at 10:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.