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
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.
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
.
Answered by marc on December 6, 2020
Get help from others!
Recent Answers
Recent Questions
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP