我有两个不同的嵌入式devices...an,旧的一个运行TI arago和一个Xilinx设备(petalinux)。
在这两种情况下,当将dns-nameservers添加到/etc/network/interfaces并使用/etc/init.d/networking restart重新配置网络或重新启动设备时,我都会看到相同的结果:/etc/resolv.conf文件始终保持为空。
系统中没有dhclient、resolvconf包、network-manager守护进程或mdns。
在这里,/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和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在执行/etc/init.d/networking restart时,这两个设备基本上都调用ifdown -a,然后调用ifup -a,在本例中是ifup和ifdown busybox实用程序。
如果提到不可变的文件属性解决方案:我不希望手动生成resolv.conf文件并更改文件属性以使其不可变(chattr +i),因为它似乎完全违背了系统的设计方式。如果resolv.conf应该是永久的,那么为什么首先将它存储在易失性内存中(由填充-Volatile.sh生成)?
谢谢你的提示!
Update:找到了解决方案,但会离开这个问题,因为有人在寻找它。
发布于 2019-02-03 22:00:18
在/etc/network/if-up.d/dns中创建具有此内容的脚本(在本例中只考虑eth0 ):
#!/bin/sh
if [ "$IFACE" = "eth0" ];then
for NS in $IF_DNS_NAMESERVERS; do
R="${R}nameserver $NS
"
done
echo "$R" > /etc/resolv.conf
fi使用chmod +x /etc/network/if-up.d/dns使其可执行。
每次重新启动设备或重新启动网络服务时,都会重新创建resolv.conf。就像一种魅力!
PS:如果在/etc/network/interfaces...for示例my-dns中使用了比D7更多的指令/命名,那么将$IF_DNS_NAMESERVERS替换为$IF_MY_DNS。虽然知道这一点很酷,但我宁愿坚持惯例,使用dns-nameservers。
https://unix.stackexchange.com/questions/498493
复制相似问题