本文就基于Linux rpi2 4.1.11-v7+ #822 SMP PREEMPT Fri Oct 23 16:22:18 BST 2015 armv7l armv7l armv7l GNU/Linux
默认情况下eth0位自动获取IP,同时dns也会自动设置,即使手动设置dns /etc/resolv.conf,重启后依然会自动覆盖为dhcp获取的dns,resolv.conf内容为:
# Generated by NetworkManager
nameserver 192.168.1.1
说明是被NetworkManager覆盖的,经过多次尝试手动设置dns,重启后依然会被NetworkManager覆盖,在不禁用NetworkManager的情况下如何手动设置dns呢。
经过查看NetworkManager文档, man 5 NetworkManager.conf,得知,dns设置有三种
dns
Set the DNS (resolv.conf) processing mode.
default: The default if the key is not specified. NetworkManager
will update resolv.conf to reflect the nameservers provided by
currently active connections.
dnsmasq: NetworkManager will run dnsmasq as a local caching
nameserver, using a "split DNS" configuration if you are connected
to a VPN, and then update resolv.conf to point to the local
nameserver.
unbound: NetworkManager will talk to unbound and dnssec-triggerd,
providing a "split DNS" configuration with DNSSEC support. The
/etc/resolv.conf will be managed by dnssec-trigger daemon.
none: NetworkManager will not modify resolv.conf.
看明白了吗, 我们直接设置dns=none即可
setup
1、nano /etc/NetworkManager/NetworkManager.conf
2、在其中加入dns=none
.......
[main]
plugins=ifcfg-rh
dns=none
......
重启,问题解决