關於「resolvconf」的操作使用 [論壇 - Ubuntu 與工具程式及軟體推薦]
正在瀏覽:
1 名遊客
關於「resolvconf」的操作使用 |
|||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
會員五級
![]() ![]() 註冊日期:
2012/4/22 10:50 所屬群組:
已註冊使用者 等級: 37
HP : 0 / 901
![]() |
# 關於「resolvconf」的操作使用
================================================================================ ## 撰寫此文時的操作環境 * Xubuntu 16.04 amd64 英文界面 * 網路連線使用「NetworkManager」,透過無限網卡,來連到「AP」。 * 對外連線則是在「AP」設定「PPPoE」連線。 ================================================================================ ## 緣起 最近我開機後,能正常連上網路,經過一段時間後,就會連不上,發現會有「這篇」和「這篇」提到的情形。
我最近也沒去動到設定,所以我也不曉得關鍵的因素,是出在那個環節, 然後我的解法,我沒去設定「AP」,因為我的手機是能正常連線的。 我一開始是去設定「/etc/resolv.conf」這個檔案,加上下面的內容
就解決了。註:(關於「8.8.8.8」,其他更多的位址可以參考「Arch Wiki / resolv.conf」。 關於這方面的概念, 可以參考「鳥哥的 Linux 私房菜 / 第十九章、主機名稱控制者: DNS 伺服器 / 19.2 Client 端的設定 / 19.2.1 相關設定檔:」 或是閱讀「man resolv.conf」。 不過因為發現到「Ubuntu現在的機制」,只要重開機,在「/etc/resolv.conf」編輯的內容,就會重置, 所以我花了點時間,去探索「resolvconf」。 指令: 「resolvconf」 套件: 「resolvconf」。 ================================================================================ ## 解法 先大略的提解法, 就是在「/etc/resolvconf/resolv.conf.d/head」或是「/etc/resolvconf/resolv.conf.d/tail」其中一個檔案,加上下面這一行
然後執行
就行了。 可以觀察「/etc/resolv.conf」的內容, 即使是重開機,「/etc/resolv.conf」也會保持原來的修改,可以參考下面的說明。 ================================================================================ ## TODO: 我遇到的狀況,尚未確定是否跟「dnsmasq」有關,有些概念還不懂,先暫記,:p 一些關於「dnsmasq」的探索,則是改紀錄到另一篇「關於「dnsmasq」的操作使用」。 * Debian Wiki / dnsmasq * Ubuntu Community Help Wiki / Dnsmasq * Arch Wiki / dnsmasq * subject: ubuntu 1604 /etc/resolv.conf 127.0.1.1 * $ man NetworkManager.conf 執行
顯示
執行
顯示
## 鳥哥的 Linux 私房菜 * 第十九章、主機名稱控制者: DNS 伺服器 / 19.2 Client 端的設定 / 19.2.1 相關設定檔: /etc/hosts, /etc/resolv.conf, /etc/nsswitch.conf * 第十九章、主機名稱控制者: DNS 伺服器 / 19.2 Client 端的設定 / 19.2.2 DNS 的正、反解查詢指令: host, nslookup, dig * 第四章、連上 Internet 執行
================================================================================ 而以下是「resolvconf」的探索紀錄 ================================================================================ ## manpage $ man resolv.conf # (Package: manpages) $ man resolvconf # (Package: resolvconf) ================================================================================ ## 相關路徑 執行
顯示
執行
顯示 /etc/resolvconf/ ├── interface-order ├── resolv.conf.d │ ├── base │ └── head ├── update.d │ └── libc └── update-libc.d └── avahi-daemon 3 directories, 5 files 執行
顯示 /run/resolvconf/ ├── enable-updates ├── interface │ └── NetworkManager └── resolv.conf 1 directory, 3 files 下面的心得, 我是閱讀「man resolvconf」, 以及觀看「/sbin/resolvconf」和「/etc/resolvconf/update.d/libc」這兩個「Shell Script」來對照觀看。 並且做一些簡單的測試,來輔助了解其中的規則。 執行
可以看到其中一段內容如下, DESCRIPTION The resolvconf package comprises a simple database for run-time nameserver information and a simple framework for notifying applications of changes in that information. Resolvconf thus sets itself up as the intermediary between programs that supply nameserver information and applications that use that information. Information is added to or removed from the database using the resolvconf program. See the OPTIONS section below for a discussion of the available options. SUPPLIERS OF NAMESERVER INFORMATION Normally the resolvconf program is run only by network interface configuration programs such as ifup(8), ifdown, NetworkManager(8), dhclient(8), and pppd(8); and by local nameservers such as dnsmasq(8). These programs obtain nameserver information from some source and push it to resolvconf. ================================================================================ ## 關於「/etc/resolv.conf」和「/run/resolvconf/resolv.conf」 執行
顯示
可以了解到「/etc/resolv.conf」是「Symbolic Link」到 「/run/resolvconf/resolv.conf」。 執行「man resolvconf」可以看到下面這一段說明。
執行下面指令觀看「/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 nameserver 127.0.1.1 ================================================================================ ## 關於「/etc/resolvconf/resolv.conf.d/head」和「/etc/resolvconf/resolv.conf.d/tali」 執行
可以看到其中有一段
以下是「/etc/resolvconf/resolv.conf.d/head」原本的內容 # 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 編輯「/etc/resolvconf/resolv.conf.d/head」,加入下面的內容
所以「/etc/resolvconf/resolv.conf.d/head」最後的內容變成 # 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 # head start nameserver 8.8.8.8 # head end 而「/etc/resolvconf/resolv.conf.d/tali」原本沒有這個檔案, 編輯「/etc/resolvconf/resolv.conf.d/tali」,加入下面的內容
執行下面指令更新
會更新「/run/resolvconf/resolv.conf」, 上面有提到「/etc/resolv.conf」是「Symbolic link」到「/run/resolvconf/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 # head start nameserver 8.8.8.8 # head end nameserver 127.0.1.1 # tail start nameserver 8.8.4.4 # tail end ================================================================================ ## 關於「/etc/resolvconf/resolv.conf.d/base」 另外還有一個檔案「/etc/resolvconf/resolv.conf.d/base」,原本也是沒有內容的。 一開始我加入下面的內容
再次執行下面指令更新
執行下面指令,觀看更新後的內容
顯示 # 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 # head start nameserver 8.8.8.8 # head end nameserver 127.0.1.1 # tail start nameserver 8.8.4.4 # tail end 發現沒有任何反應,跟上面是一樣的內容 然後在看了「/etc/resolvconf/update.d/libc」和「man resolvconf」的「ENVIRONMENT VARIABLES」, 可以知道有一個參數「TRUNCATE_NAMESERVER_LIST_AFTER_LOOPBACK_ADDRESS」可以設定 可以設定在「/etc/default/resolvconf」這個檔案,(原本是沒有這個檔案的) 設定內容如下
不過在「man resolvconf」提到「A deprecated synonym for this variable is TRUNCATE_NAMESERVER_LIST_AFTER_127.」 所以或是設定下面這個,一樣會有作用,
再次執行下面指令更新
執行下面指令,觀看更新後的內容
顯示
執行「man resolvconf」可以在「ENVIRONMENT VARIABLES」看到其中有一段說明 ENVIRONMENT VARIABLES The following variables can be set in the configuration file /etc/default/resolvconf. If the file does not exist you will have to create it. REPORT_ABSENT_SYMLINK If set to "yes" then resolvconf will print a message when /etc/resolv.conf is not a symbolic link to the resolvconf-generated resolver configuration file. Set to "no" to prevent the printing of this message. The default is "yes". TRUNCATE_NAMESERVER_LIST_AFTER_LOOPBACK_ADDRESS If set to "yes" then the libc script will include no more nameserver addresses after the first nameserver address that is a loopback address. (In IPv4 a loopback address is any one that starts with "127.". In IPv6 the loopback address is "::1".) The advantage of truncating the nameserver list after a loopback address is that doing so inhibits unnecessary changes to resolv.conf and thus reduces the number of instances in which the update-libc.d/ scripts have to be run. When an interface is brought up or down the local caching nameserver that listens on the loopback address is still informed of the change and adapts accordingly; the clients of the resolver which use the local caching nameserver do not need to be notified of the change. A disadvantage of this mode of operation is that applications have no secondary or tertiary nameserver address to fall back on should the local caching nameserver crash. Insofar as a local nameserver crash can be regarded as an unlikely event, this is a relatively minor disadvantage. Set to "no" to disable truncation. The default is "yes". A deprecated synonym for this variable is TRUNCATE_NAMESERVER_LIST_AFTER_127. 另外測試的時候,發現在「/etc/resolvconf/resolv.conf.d/base」設定, 然後執行「sudo resolvconf -u」,最多只會出現兩筆, 有興趣深究的話,可以閱讀「/etc/resolvconf/update.d/libc」,了解其中的實作規則,以此為準。 另外也可以把「/etc/resolvconf/resolv.conf.d/base」設定如下面的內容來測試
然後執行「sudo resolvconf -u」。 再執行「view /etc/resolvconf」觀看「/etc/resolvconf」的內容。 顯示
註:上面的「ip」我是從「Arch Wiki / resolv.conf」找到的。 執行「man resolvconf」可以看到其中有一段說明
================================================================================ 以下的操作可以閱讀「man resolvconf」, 以及觀看「/sbin/resolvconf」和「/etc/init.d/resolvconf」來了解。 下面摘錄「/sbin/resolvconf」一開始設定的變數,下面說明會用到
================================================================================ ## --enable-updates 執行
可以看到其中一段說明,列在下面
觀看「/sbin/resolvconf」可以看到其中一段內容,列在下面 --enable-updates) : >| "$ENABLE_UPDATES_FLAGFILE" || exit 1 if [ -e "$POSTPONED_UPDATE_FLAGFILE" ] ; then (update_and_exit -u) || : fi exit 0 ;; 執行
上面的指令,其中有一個動作,會產生「/var/run/resolvconf/enable-updates」這個檔案 然後執行
顯示
上面是關於「Exit Status」,可以參考「這篇」, 或是執行「man bash」,使用「exit status」或「Special Parameters」當關鍵字來找尋,也可以找到相關的說明。 觀看「/etc/init.d/resolvconf」可以看到其中一段內容,列在下面 enable-updates) resolvconf --enable-updates || log_action_end_msg_and_exit 1 "failed to enable updates" exit 0 ;; 註:在「start)」和「restart)」也有「resolvconf --enable-updates」。 所以也可以執行下面的指令
或是執行
這部份請參考下面幾篇文章 * 浅析 Linux 初始化 init 系统,第 1 部分: sysvinit * 浅析 Linux 初始化 init 系统,第 2 部分: UpStart * 浅析 Linux 初始化 init 系统,第 3 部分: Systemd * SystemdForUpstartUsers 我有列在「這篇」和「這篇」索引,有紀錄相關的連結。 然後接下來這幾篇 「這篇」,「這篇」,「這篇」,「這篇」,則是相關的討論案例,有的也會提到上面的連結。 後來有發現下面這幾篇一系列的文章,也可以參考 * Linux 守護進程的啟動方法 * Systemd 入門教程:命令篇 * Systemd 入門教程:實戰篇 * Node 應用的 Systemd 啟動 也可以探索下面的套件,來搭配,輔助了解其中的機制。 我「之前有做簡單的探索」,裡面有紀錄一些套件。 雖然還沒有了解透徹,不過當時了解到的,後來也忘光光,只留下一些基本的概念了。 * systemd * systemd-sysv * upstart * sysvinit-utils * initscripts * sysv-rc * init-system-helpers 以上套件,可執行「dpkg -L」就可以知道這些套件,安裝在系統裡有哪些檔案,例如「dpkg -L initscripts」。 以上套件,可以執行下面指令找到。 執行
顯示
執行
顯示
執行
顯示
執行
顯示
若是「xsession」這一段,則是可以參考「這篇」。 ================================================================================ ## --disable-updates 執行
可以看到其中一段說明,列在下面 --disable-updates Clear the flag. 觀看「/sbin/resolvconf」可以看到其中一段內容,列在下面 --disable-updates) rm -f "$POSTPONED_UPDATE_FLAGFILE" || : rm -f "$ENABLE_UPDATES_FLAGFILE" || exit 1 exit 0 ;; 執行
上面的指令,其中有一個動作,會刪除「/var/run/resolvconf/enable-updates」這個檔案 然後執行
顯示
接下來執行
顯示
接下來觀看「/etc/init.d/resolvconf」這個檔案,可以看到其中一段內容,列在下面 disable-updates) resolvconf --disable-updates || log_action_end_msg_and_exit 1 "failed to disable updates" exit 0 ;; 所以也可以執行下面的指令
或是執行
================================================================================ ## --updates-are-enabled 執行
可以看到其中一段說明,列在下面 --updates-are-enabled Return 0 if the flag is set, otherwise return 1. 觀看「/sbin/resolvconf」可以看到其中一段內容,列在下面 --updates-are-enabled) if [ -e "$ENABLE_UPDATES_FLAGFILE" ] ; then exit 0 else exit 1 fi ;; 執行
然後執行
當「/run/resolvconf/enable-updates」這個檔案「存在」,執行上面指令,會顯示「0」 當「/run/resolvconf/enable-updates」這個檔案「不存在」,執行上面指令,會顯示「1」 這個可以應用在寫「Shell Script」的「test」上面。 可以執行「help if」,「help test」或「help [」來了解寫法,或參考「這篇」。 例如 #!/usr/bin/env bash if resolvconf --updates-are-enabled; then echo 'yes' else echo 'no' fi 接下來觀看「/etc/init.d/resolvconf」這個檔案,可以看到其中一段內容,列在下面 status) if resolvconf --updates-are-enabled ; then log_success_msg "resolvconf updates are enabled" else log_failure_msg "resolvconf updates are disabled" fi exit 0 ;; 所以也可以執行下面的指令
或是執行
================================================================================ ## -u 執行
可以看到其中一段說明,列在下面 -u Just run the update scripts (if updating is enabled). 觀看「/sbin/resolvconf」可以看到其中一段內容,列在下面 -u) if [ -e "$ENABLE_UPDATES_FLAGFILE" ] ; then update_and_exit -u else : >| "$POSTPONED_UPDATE_FLAGFILE" exit 0 fi ;; 執行
上面的指令,在上面有提到怎麼使用了,請參考上面的範例。 接下來觀看「/etc/init.d/resolvconf」這個檔案,可以看到其中一段內容,列在下面 reload|force-reload) resolvconf -u || log_action_end_msg_and_exit 1 "failed to update" exit 0 ;; 所以也可以執行下面的指令
或是執行
================================================================================ ## status 執行
或是執行
或是執行
顯示
執行下面指令,觀看「/lib/systemd/system/resolvconf.service」這個檔
顯示 [Unit] Description=Nameserver information manager Documentation=man:resolvconf(8) DefaultDependencies=no Before=network-pre.target Wants=network-pre.target [Service] RemainAfterExit=yes ExecStartPre=/bin/mkdir -p /run/resolvconf/interface ExecStartPre=/bin/touch /run/resolvconf/postponed-update ExecStart=/sbin/resolvconf --enable-updates ExecStop=/sbin/resolvconf --disable-updates [Install] WantedBy=sysinit.target 觀看「/usr/sbin/service」這個檔案的內容 ...略... # When this machine is running systemd, standard service calls are turned into # systemctl calls. if [ -n "$is_systemd" ] then UNIT="${SERVICE%.sh}.service" ...略... 還有 case "${ACTION}" in restart|status) exec systemctl $sctl_args ${ACTION} ${UNIT} ;; 還有 *) # We try to run non-standard actions by running # the init script directly. run_via_sysvinit ;; ================================================================================ 執行
或是執行
顯示
可以對照「/etc/init.d/resolvconf」的其中一段內容如下 *) echo "Usage: /etc/init.d/resolvconf {start|stop|restart|reload|force-reload|enable-updates|disable-updates|status}" >&2 exit 3 ;; 其餘的,就照上面提到的範例,來探索了,就不再額外說明了。 ================================================================================ ## 關於「/etc/init/resolvconf.conf」 執行
顯示 # upstart script for resolvconf description "Initialize or finalize resolvconf" start on mounted MOUNTPOINT=/run stop on runlevel [06] pre-start script mkdir -p /run/resolvconf/interface # Request a postponed update (needed in case the base file has content). touch /run/resolvconf/postponed-update # Enable updates and perform the postponed update. resolvconf --enable-updates end script post-stop script resolvconf --disable-updates end script ================================================================================ ## 關於「/etc/resolvconf/update.d/libc」 執行
顯示
================================================================================ ## 關於「dpkg-reconfigure resolvconf」 若是「/etc/resolv.conf」這個檔案被刪除了,你可以執行下面的指令來修復
會出現一個對話框,裡面的文字,可以在「/var/lib/dpkg/info/resolvconf.templates」找到。 當然也可以使用「ln」的方式。 執行
或是執行
就會在「/var/lib/dpkg/info/resolvconf.postinst」這個檔案,找到相關的指令
所以若是使用「ln」的方式復原,範例指令如下
這可以回覆「這篇」提到的 GNOME Lover 寫到: 還有回覆「這篇」提到的。 ================================================================================ ## Manpage * $ man 5 resolv.conf * $ man 8 resolvconf * $ man 8 interface-order * $ man 1 dig * $ man 1 nslookup * $ man 8 mtr * $ man 8 ping ## Package * manpages * resolvconf ## File * /etc/hosts * /etc/resolv.conf * /run/resolvconf/resolv.conf * /etc/resolvconf/resolv.conf.d/head * /etc/resolvconf/resolv.conf.d/base * /etc/resolvconf/resolv.conf.d/tail ================================================================================ 以上提供參考,讓未來想要探索這方面議題的人,有探索的起點。 一些套件探索的技巧,可以參考這篇「[索引] 套件操作實務」。 報告完畢 ![]() ================================================================================ 後記 (2017-04-18): 相關討論 * #4 回覆: firefox 連不上 google,其他網站如yahoo卻能連上 ================================================================================ 後記 (2017-05-21): 相關討論 * subject: ubuntu 1604 /etc/resolv.conf 127.0.1.1 ================================================================================
2017/3/15 20:31
|
||||||||||
![]() |
回覆: 關於「resolvconf」的操作使用 |
|||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
管理員
![]() ![]() 註冊日期:
2011/3/11 6:32 所屬群組:
討論區管理群 等級: 44
HP : 216 / 1084
![]() |
幫大忙了,感謝分享
2017/3/15 23:03
|
||||||||||
本篇發表文章以「創用CC BY 3.0 或更新之台灣地區版本」授權條款釋出,如何使用敬請參考
Creative Commons — 姓名標示 3.0 台灣 — CC BY 3.0 TW http://creativecommons.org/licenses/by/3.0/tw/ 「你不懂的東西就不要亂講,被懂得人看破手腳就算了,騙不懂的人誤導別人,還要別人把你當成大師,這就真的是說不過去了。」 by Allen Own 出處 http://www.plurk.com/p/i4uogm 自由知識創作平台介紹 https://docs.google.com/document/d/1MGG6lW_0qCgH4U785R-IwSc_INdoBGej1l-JxiA4gPE 如何建立新的自由知識創作平台文件 https://docs.google.com/document/d/11NdzOW2lGYksfyQIcPMPye5tlmj1J0QTkgPTmQvIvKA |
|||||||||||
![]() |
回覆: 關於「resolvconf」的操作使用 |
|||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
會員五級
![]() ![]() 註冊日期:
2012/4/22 10:50 所屬群組:
已註冊使用者 等級: 37
HP : 0 / 901
![]() |
## 關於「/run/resolvconf/interface/NetworkManager」
在上面「#1」,提到的了 * /etc/resolvconf/resolv.conf.d/head * /etc/resolvconf/resolv.conf.d/base * /etc/resolvconf/resolv.conf.d/tail 上面三個檔案,被當作依據來產生「/run/resolvconf/resolv.conf」。 而「/etc/resolv.conf」則是「symbolic link」到「/run/resolvconf/resolv.conf」。 而其中有一行
之前並沒有提到是依據那個檔案產生的,因為當時沒有深究, 經過研究後,該行是來自「/run/resolvconf/interface/NetworkManager」這個檔案。 ================================================================================ 可以先做個小實驗 執行
顯示 # 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 nameserver 127.0.1.1 執行
顯示
執行下面指令,更改「/run/resolvconf/interface/NetworkManager」這個檔案的內容
或是執行下面指令,更改「/run/resolvconf/interface/NetworkManager」這個檔案的內容
執行
顯示
執行下面指令,就會重新產生「/run/resolvconf/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 nameserver 8.8.4.4 ================================================================================ 執行下面指令,將「/run/resolvconf/interface/NetworkManager」恢復原狀
然後在執行下面指令,重新產生「/run/resolvconf/resolv.conf」。
================================================================================ 待續...
2017/10/2 14:56
|
||||||||||
![]() |
回覆: 關於「resolvconf」的操作使用 |
|||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
會員五級
![]() ![]() 註冊日期:
2012/4/22 10:50 所屬群組:
已註冊使用者 等級: 37
HP : 0 / 901
![]() |
在進一步討論之前,先再來介紹「resolvconf」的用法。
上面有介紹過「resolvconf -u」的用法了。 接下來介紹「resolvconf -d」的用法。 ================================================================================ ## 關於「resolvconf -d」 執行
顯示
接著執行下面指令
然後執行下面指令,確認「/run/resolvconf/interface/NetworkManager」這個檔案是否存在
顯示
表示「/run/resolvconf/interface/NetworkManager」這個檔案不存在。 ================================================================================ 接下來介紹「resolvconf -a」的用法。 ================================================================================ ## 關於「resolvconf -a」/ 方式一 上面有先使用過了。 執行下面指令,設定「/run/resolvconf/interface/NetworkManager」這個檔案的內容。
執行下面指令,觀看「/run/resolvconf/interface/NetworkManager」這個檔案的內容
顯示
================================================================================ ## 關於「resolvconf -a」/ 方式二 執行下面指令,先產生一個檔案「demo.txt」
然後再執行下面指令,設定「/run/resolvconf/interface/NetworkManager」這個檔案的內容。
================================================================================ ## 關於「resolvconf -a」/ 方式三 執行下面指令,先產生一個檔案「demo.txt」
然後再執行下面指令,設定「/run/resolvconf/interface/NetworkManager」這個檔案的內容。
================================================================================ 待續...
2017/10/2 15:02
|
||||||||||
![]() |
回覆: 關於「resolvconf」的操作使用 |
|||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
會員五級
![]() ![]() 註冊日期:
2012/4/22 10:50 所屬群組:
已註冊使用者 等級: 37
HP : 0 / 901
![]() |
接下來再來談到關於「/run/resolvconf/interface/NetworkManager」這個檔案如何產生的。
推測應該是「NetworkManager」產生的。 ================================================================================ ## 實驗ㄧ 一樣先來做個小實驗, 做實驗前,先觀看一下「/etc/NetworkManager/NetworkManager.conf」的設定內容
顯示 [main] plugins=ifupdown,keyfile,ofono dns=dnsmasq [ifupdown] managed=false 執行
顯示
執行
================================================================================ 以下實驗開始, 執行下面指令,將「/run/resolvconf/interface/NetworkManager」這個檔案刪除
然後執行下面指令,確認「/run/resolvconf/interface/NetworkManager」這個檔案是否存在
顯示
表示「/run/resolvconf/interface/NetworkManager」這個檔案不存在。 ================================================================================ 接下來先執行下面指令,「Disable Networking」
然後再執行下面指令,「Enable Networking」
稍等一下,最後再執行下面指令,
顯示
表示「/run/resolvconf/interface/NetworkManager」這個檔案,又被重新產生。 註: 上面「Disable Networking」和「Enable Networking」這兩個動作,除了可以透過上面「nmcli」這個指令來操作, 也可以透過「nm-applet」這個圖形界面來操作,在下拉選單的選項「Enable Networking」,「取消勾選」和「勾選」。 ================================================================================ ## 實驗二 再來做另一個實驗 執行
顯示
執行
顯示 [connection] id=Ethernet connection 1 uuid=fc463c66-37c1-4ab7-91ef-aca74daa6c85 type=ethernet interface-name=enp4s0 permissions= secondaries= [ethernet] mac-address-blacklist= [ipv4] dns-search= method=auto [ipv6] addr-gen-mode=stable-privacy dns-search= method=auto 執行
顯示
執行
顯示
請將「dns=dnsmasq」那一行拿掉,也就是最後的結果是 [main] plugins=ifupdown,keyfile,ofono [ifupdown] managed=false 然後執行下面指令
顯示
註: 也可以透過「SIGHUP」這個「SIGNAL」重新載入「NetworkManager」的「configuration.」, 可以參考「man NetworkManager」。 或是參考「#3 回覆: 關於「NetworkManager」的操作使用」這篇的說明。 執行
顯示
註: 另外有一個檔案「/run/NetworkManager/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 nameserver 192.168.1.1 ================================================================================ ## 實驗三 更進一步的實驗,一樣接續著實驗二「/etc/NetworkManager/NetworkManager.conf」的「dns=dnsmasq」那一行是拿掉的 執行下面指令,產生一個新的連線設定。
顯示
執行
顯示 [connection] id=con001 uuid=e073d2fc-276a-4336-8666-26caea7c5ad4 type=ethernet interface-name=enp4s0 permissions= secondaries= [ethernet] mac-address-blacklist= [ipv4] dns-search= method=auto [ipv6] addr-gen-mode=stable-privacy dns-search= method=auto 執行
顯示
執行下面指令,加入「ipv4.dns」到設定檔。
執行
顯示
執行
顯示
執行
顯示 NAME UUID TYPE DEVICE Ethernet connection 1 fc463c66-37c1-4ab7-91ef-aca74daa6c85 802-3-ethernet enp4s0 con001 e073d2fc-276a-4336-8666-26caea7c5ad4 802-3-ethernet -- 執行下面指令,啟動「con001」
顯示
執行
顯示 NAME UUID TYPE DEVICE con001 e073d2fc-276a-4336-8666-26caea7c5ad4 802-3-ethernet enp4s0 Ethernet connection 1 fc463c66-37c1-4ab7-91ef-aca74daa6c85 802-3-ethernet -- 執行
顯示 ipv4.dns: 8.8.8.8,8.8.4.4 ipv4.dns-search: ipv4.dns-options: (default) ipv4.dns-priority: 0 ipv4.ignore-auto-dns: no ipv6.dns: ipv6.dns-search: ipv6.dns-options: (default) ipv6.dns-priority: 0 ipv6.ignore-auto-dns: no IP4.DNS[1]: 192.168.1.1 IP4.DNS[2]: 8.8.8.8 IP4.DNS[3]: 8.8.4.4 執行
顯示
執行
顯示 # 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 nameserver 192.168.1.1 nameserver 8.8.8.8 nameserver 8.8.4.4 ================================================================================ 待續...
2017/10/2 15:13
|
||||||||||
![]() |
回覆: 關於「resolvconf」的操作使用 |
|||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
會員五級
![]() ![]() 註冊日期:
2012/4/22 10:50 所屬群組:
已註冊使用者 等級: 37
HP : 0 / 901
![]() |
接下來,來探索「network-manager」的「Source Package: network-manager」
================================================================================ 執行
就會下載下面三個檔案 * network-manager_1.2.6-0ubuntu0.16.04.1.debian.tar.xz * network-manager_1.2.6-0ubuntu0.16.04.1.dsc * network-manager_1.2.6.orig.tar.xz 並且解開到「network-manager-1.2.6」這個資料夾。 然後執行下面指令,先使用「resolvconf」當關鍵字,來找尋相關的檔案。
顯示 ...略... network-manager-1.2.6/man/NetworkManager.conf.5:234:resolvconf: NetworkManager will run resolvconf to update the DNS configuration\&. ...略... network-manager-1.2.6/src/dns-manager/nm-dns-manager.h:102: through resolvconf network-manager-1.2.6/src/dns-manager/nm-dns-manager.c:67:#define RESOLVCONF_PATH "/sbin/resolvconf" network-manager-1.2.6/src/dns-manager/nm-dns-manager.c:184: NM_UTILS_LOOKUP_STR_ITEM (NM_DNS_MANAGER_RESOLV_CONF_MAN_RESOLVCONF, "resolvconf"), network-manager-1.2.6/src/dns-manager/nm-dns-manager.c:602:dispatch_resolvconf (NMDnsManager *self, network-manager-1.2.6/src/dns-manager/nm-dns-manager.c:650: "Failed to close pipe to resolvconf: %d", errnosv); network-manager-1.2.6/src/dns-manager/nm-dns-manager.c:653: _LOGW ("resolvconf failed with status %d", err); network-manager-1.2.6/src/dns-manager/nm-dns-manager.c:656: "resolvconf failed with status %d", err); network-manager-1.2.6/src/dns-manager/nm-dns-manager.c:1183: result = dispatch_resolvconf (self, searches, nameservers, options, error); network-manager-1.2.6/src/dns-manager/nm-dns-manager.c:1631: else if (nm_streq (man, "resolvconf")) 可以找到「network-manager-1.2.6/src/dns-manager/nm-dns-manager.c」這個檔案, 然後可以使用「dispatch_resolvconf」當關鍵字找尋,執行下面指令
顯示 602:dispatch_resolvconf (NMDnsManager *self, 1183: result = dispatch_resolvconf (self, searches, nameservers, options, error); 可以找到「dispatch_resolvconf」這個「function」的定義, 在「network-manager-1.2.6/src/dns-manager/nm-dns-manager.c」這個檔案, 在第「602行」看起,初步來看,推測有呼叫外部的「/sbin/resolvconf」, 並且有使用「resolvconf -a」和「resolvconf -d」的功能。 執行
顯示 66:#ifndef RESOLVCONF_PATH 67:#define RESOLVCONF_PATH "/sbin/resolvconf" 613: if (!g_file_test (RESOLVCONF_PATH, G_FILE_TEST_IS_EXECUTABLE)) { 617: RESOLVCONF_PATH " is not executable"); 622: _LOGI ("Removing DNS information from %s", RESOLVCONF_PATH); 624: cmd = g_strconcat (RESOLVCONF_PATH, " -d ", "NetworkManager", NULL); 631: _LOGI ("Writing DNS information to %s", RESOLVCONF_PATH); 633: cmd = g_strconcat (RESOLVCONF_PATH, " -a ", "NetworkManager", NULL); 639: RESOLVCONF_PATH, 先簡單探索到這,其餘的尚未深究。 ================================================================================ 待續...
2017/10/2 15:22
|
||||||||||
![]() |
回覆: 關於「resolvconf」的操作使用 |
|||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
會員五級
![]() ![]() 註冊日期:
2012/4/22 10:50 所屬群組:
已註冊使用者 等級: 37
HP : 0 / 901
![]() |
要瞭解「resolvconf -u」的機制,可以「trace」下面三個檔案。
* /sbin/resolvconf * /etc/resolvconf/update.d/libc * /lib/resolvconf/list-records 以下會提到一些關鍵的點。 ================================================================================ 執行
顯示
執行
顯示
注意,在執行「/sbin/resolvconf」時,過程中,會切換到「/run/resolvconf/interface」這個資料夾。 ================================================================================ 執行
顯示 56:update_and_exit() 75: update_and_exit -d "$IFACE" 83: update_and_exit -u 92: (update_and_exit -u) || : 162: update_and_exit -a "$IFACE" 執行
顯示 56:update_and_exit() 57-{ 58- rm -f "$POSTPONED_UPDATE_FLAGFILE" 59- exec run-parts ${1:+--arg="$1"} ${2:+--arg="$2"} /etc/resolvconf/update.d 60-} 61- -- ...略... 當呼叫「update_and_exit -u」時, 上面的「exec run-parts ${1:+--arg="$1"} ${2:+--arg="$2"} /etc/resolvconf/update.d」 就會展開成「exec run-parts --arg=-u /etc/resolvconf/update.d」。 也就是會執行「/etc/resolvconf/update.d/」這個資料夾裡面的檔案, 請參考「$ man run-parts」和「$ help exec」的說明。 ================================================================================ 執行
顯示
執行「sudo resolvconf -u」,重新產生「/run/resolvconf/resolv.conf」,主要在上面那一段, 可以搭配上面「#3」來看。 而上面「sed -e '/^[[:space:]]*$/d' -e '/^[[:space:]]*#/d' -e '/^[[:space:]]*\(\(nameserver\)\|\(search\)\|\(domain\)\)[[:space:]]/d' $RSLVCNFFILES」, 會被展開類似「sed -e /^[[:space:]]*$/d -e /^[[:space:]]*#/d -e /^[[:space:]]*\(\(nameserver\)\|\(search\)\|\(domain\)\)[[:space:]]/d lo.dnsmasq NetworkManager」。 ================================================================================ 執行
顯示 110:RSLVCNFFILES="$(/lib/resolvconf/list-records)" 114:[ -f "$BASEFILE" ] && RSLVCNFFILES="$RSLVCNFFILES ================================================================================ 執行
顯示
執行
顯示 25:uniquify() 83:uniquify $PATTERNS 執行
顯示 25:uniquify() 26-{ 27- local E 28- RSLT="" 29- while [ "$1" ] ; do 30- for E in $RSLT ; do 31- [ "$1" = "$E" ] && { shift ; continue 2 ; } 32- done 33- RSLT="${RSLT:+$RSLT 34-}$1" 35- shift 36- done 37-} 38- -- ...略... ================================================================================ 執行
顯示
================================================================================ 要了解「/lib/resolvconf/list-records」的用法, 還有「uniquify()」的用法, 可以先從下面幾個測試瞭解一些概念, ================================================================================ ## 測試前提 執行
顯示
表示我測試的環境有下面兩個檔案 * /run/resolvconf/interface/lo.dnsmasq * /run/resolvconf/interface/NetworkManager 註: 關於「/run/resolvconf/interface/lo.dnsmasq」這個檔案, 要安裝「dnsmasq」這個套件,然後在運行時,才會出現,這是另一個議題,暫不討論。 ================================================================================ ## 測試一 執行
顯示
================================================================================ ## 測試二 執行
顯示
================================================================================ ## 測試三 執行
注意上面「$PATTERNS」左右有加上「"」,所以並不會被展開,可以對照上面「測試二」。 所以顯示
================================================================================ ## 測試四 執行
顯示
================================================================================ ## 測試五 執行
顯示
執行
顯示
執行
顯示
================================================================================ 以上補充 報告完畢 ![]()
2017/10/2 15:30
|
||||||||||
![]() |
您可以查看帖子.
您不可發帖.
您不可回覆.
您不可編輯自己的帖子.
您不可刪除自己的帖子.
您不可發起投票調查.
您不可在投票調查中投票.
您不可上傳附件.
您不可不經審核直接發帖.