最近发现我在/etc/resolv.conf中设置的dns老是被抹去. resolv.conf这个文件其实会被动态改变的, 不能直接修改里面的内容,网上看了解决方案是安装resolvconf。
1. 安装resolvconf
sudo install resolvconf
2. 修改head
vim /etc/resolvconf/resolv.conf.d/head
在 head中添加你想使用的dns
nameserver 8.8.8.8
nameserver 114.114.114.114
3. 刷新/etc/resolv.conf
执行resolvconf -u
命令来刷新/etc/resolv.conf
就可以看到在resolv.conf
的开头已经有了你在head
中添加的nameserver
# Dynamic resolv.conf(5) file for glibc resolver(3) generated by resolvconf(8)
# DO NOT EDIT THIS FILE BY HAND -- YOUR CHANGES WILL BE OVERWRITTEN
# 127.0.0.53 is the systemd-resolved stub resolver.
# run "systemd-resolve --status" to see details about the actual nameservers.
#
nameserver 8.8.8.8
nameserver 114.114.114.114
我一开用的是阿里的源sources.list
, 怎么都安装不了resolvconf
, 我将原来自带的源sources.list
复原之后,在/etc/resolv.conf
加上8.8.8.8
的dns再执行apt install resolvconf
, 就可以安装成功了