最近發現我在/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, 就可以安裝成功了
