ubuntu resolvconf 設置永久dns


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


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM