日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 人文社科 > 生活经验 >内容正文

生活经验

【Ubuntu】在Ubuntu中设置永久的DNS

發布時間:2023/11/27 生活经验 26 豆豆
生活随笔 收集整理的這篇文章主要介紹了 【Ubuntu】在Ubuntu中设置永久的DNS 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
1、問題描述

ping不通域名,比如“ping www.baidu.com”時,報錯“ping: unknown host www.baidu.com”。這是因為ubuntu默認情況下沒有設置DNS。
在ubuntu上設置DNS的方法,修改“/etc/resolv.conf”,添加“nameserver 8.8.8.8”,但是重啟后就失效了。

2、原因查找

在“/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

這里已經明確說明,resolv.conf是由resolvconf命令動態生成的,不要編輯這個文件。

resolvconf是什么?

resolvconf 是"域名服務信息"管理工具,說白了就是管理ubuntu系統的DSN,包括添加、刪除、更新、使能或禁止更新等。
使用方法:resolvconf (-d IFACE|-a IFACE|-u|–enable-updates|–disable-updates|–updates-are-enabled)
可以使用man查看詳細信息:man resolvconf

如何生成的resolv.conf?

ubunut啟動后調用初始化腳本:/etc/init.d/resolvconf start

 83   start)84     # The "start" method should only be used at boot time.85     # Don't run this on package upgrade, for example.86     log_action_begin_msg "Setting up resolvconf"87     # Wipe runtime directories in case they aren't on a tmpfs88     wipe_runtime_directories89     # Create runtime directories in case they are on a tmpfs90     create_runtime_directories91     # Request a postponed update (needed in case the base file has content).92     :> "$POSTPONED_UPDATE_FLAGFILE" || log_action_end_msg_and_exit 1 "failed requesting update"93     # Enable updates and perform the postponed update.94     resolvconf --enable-updates || log_action_end_msg_and_exit 1 "failed to enable updates"95     log_action_end_msg_and_exit 096     ;;

對上面這段腳本的解釋:
首先,注釋里面提示==/etc/init.d/resolvconf start==只能在系統啟動時調用一次,因為它會在/run/中創建resolvconf及相關文件目錄。
wipe_runtime_directories:清除/run/resolvconf目錄
create_runtime_directories:創建/run/resolvconf/interface目錄
:> “$POSTPONED_UPDATE_FLAGFILE” 創建文件 /run/resolvconf/postponed-update,這個文件下面會用到。
resolvconf --enable-updates:resolvconf路徑是/sbin/resolvconf
/sbin/resolvconf也是一個腳本,執行 --enable-updates 選項

--enable-updates): >| "$ENABLE_UPDATES_FLAGFILE" || exit 1if [ -e "$POSTPONED_UPDATE_FLAGFILE" ] ; then(update_and_exit -u) || :fiexit 0

對上面這段腳本的解釋:
創建文件 /run/resolvconf/enable-updates;
如果文件 /run/resolvconf/postponed-update存在,則執行(update_and_exit -u),這個文件在上面的步驟中已經創建;
update_and_exit函數如下

 56 update_and_exit()57 {58     rm -f "$POSTPONED_UPDATE_FLAGFILE"59     exec run-parts ${1:+--arg="$1"} ${2:+--arg="$2"} /etc/resolvconf/update.d60 }

刪除:/run/resolvconf/postponed-update
run-parts功能:批量執行目錄下的腳本;
/etc/resolvconf/update.d下只有一個腳本libc;
libc功能是用 /etc/resolvconf/resolv.conf.d 目錄下的三個文件head、base、tail生成/run/resolvconf/resolv.conf,并創建軟鏈接/etc/resolv.conf

3、解決方法

要想設置永久的DNS,一個正經的辦法是修改 /etc/resolvconf/resolv.conf.d/base

nameserver 8.8.8.8
nameserver 8.8.4.4

修改完后執行:

/sbin/resolvconf -u

再重啟后就不用再設置DNS了

總結

以上是生活随笔為你收集整理的【Ubuntu】在Ubuntu中设置永久的DNS的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。

歡迎分享!

轉載請說明來源于"生活随笔",并保留原作者的名字。

本文地址:【Ubuntu】在Ubuntu中设置永久的DNS