UBUNTU系統,/etc/resolv.conf無法保持定義自訂的DNS伺服器解法

如果在UBUNTU的Linux環境,網路上游是用DHCP自己抓發配的DNS。
重開機/etc/resolv.conf的資料,若上游主機的設定檔有所錯誤,會造成主機開啟相關DNS正解反解的問題,而誤會找不到原因。
如果想要保持固定的DNS主機,除了修改成固定IP以外,以下的方式也會是另外一種解法。

安裝resolvconf套件。
sudo apt install resolvconf

編輯需要的自訂DNS伺服器。例如:
nameserver 8.8.8.8
nameserver 168.95.1.1
sudo nano /etc/resolvconf/resolv.conf.d/head

接著,指令更新resolve的檔案。
sudo resolvconf --enable-updates
sudo resolvconf -u

這時候如果看/etc/resolv.conf,應該會發現都被新增上去,本來只能ping IP也變成正常能解析網址了。
cat /etc/resolv.conf

# 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 168.95.192.1

之後,重開機在看看有無異常。

來源參考資料:
https://askubuntu.com/questions/1383165/nameserver-goes-missing-from-etc-resolv-conf
https://installati.one/ubuntu/21.04/resolvconf/
其他參考資料:
http://www.codebaoku.com/it-linux/it-linux-119362.html

發佈留言

發佈留言必須填寫的電子郵件地址不會公開。 必填欄位標示為 *

請輸入下列驗證碼計算後阿拉伯數字 (Translate it, if not Taiwanese to post reply) *