關於「resolvconf」的操作使用 [論壇 - Ubuntu 與工具程式及軟體推薦]


正在瀏覽:   1 名遊客


 到底部   前一個主題   下一個主題  [無發表權] 請登錄或者註冊



關於「resolvconf」的操作使用
會員五級
註冊日期:
2012/4/22 10:50
所屬群組:
已註冊使用者
等級: 33
HP : 161 / 806
MP : 508 / 13318
EXP: 24
離線
# 關於「resolvconf」的操作使用

================================================================================

## 撰寫此文時的操作環境

* Xubuntu 16.04 amd64 英文界面
* 網路連線使用「NetworkManager」,透過無限網卡,來連到「AP」。
* 對外連線則是在「AP」設定「PPPoE」連線。

================================================================================

## 緣起

最近我開機後,能正常連上網路,經過一段時間後,就會連不上,發現會有「這篇」和「這篇」提到的情形。


ping ip會連線,ping domain-name 則不通。



我最近也沒去動到設定,所以我也不曉得關鍵的因素,是出在那個環節,

然後我的解法,我沒去設定「AP」,因為我的手機是能正常連線的。

我一開始是去設定「/etc/resolv.conf」這個檔案,加上下面的內容


nameserver 8.8.8.8



就解決了。註:(關於「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」其中一個檔案,加上下面這一行


nameserver 8.8.8.8



然後執行


$ sudo resolvconf -u



就行了。

可以觀察「/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

執行


$ cat /etc/NetworkManager/NetworkManager.conf



顯示


[main]
plugins=ifupdown,keyfile,ofono
dns=dnsmasq

[ifupdown]
managed=false



執行


$ ps aux | grep dnsmasq



顯示


nobody 1389 0.0 0.0 56048 4184 ? S 17:29 0:00 /usr/sbin/dnsmasq --no-resolv --keep-in-foreground --no-hosts --bind-interfaces --pid-file=/var/run/NetworkManager/dnsmasq.pid --listen-address=127.0.1.1 --cache-size=0 --conf-file=/dev/null --proxy-dnssec --enable-dbus=org.freedesktop.NetworkManager.dnsmasq --conf-dir=/etc/NetworkManager/dnsmasq.d



## 鳥哥的 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

執行


$ dig www.google.com @127.0.1.1



================================================================================

而以下是「resolvconf」的探索紀錄

================================================================================

## manpage

$ man resolv.conf # (Package: manpages)
$ man resolvconf # (Package: resolvconf)

================================================================================

## 相關路徑

執行


$ dpkg -L resolvconf | sort



顯示


/.
/etc
/etc/dhcp
/etc/dhcp/dhclient-enter-hooks.d
/etc/dhcp/dhclient-enter-hooks.d/resolvconf
/etc/init
/etc/init.d
/etc/init.d/resolvconf
/etc/init/resolvconf.conf
/etc/network
/etc/network/if-down.d
/etc/network/if-down.d/resolvconf
/etc/network/if-up.d
/etc/network/if-up.d/000resolvconf
/etc/ppp
/etc/ppp/ip-down.d
/etc/ppp/ip-down.d/000resolvconf
/etc/ppp/ip-up.d
/etc/ppp/ip-up.d/000resolvconf
/etc/resolvconf
/etc/resolvconf/interface-order
/etc/resolvconf/resolv.conf.d
/etc/resolvconf/resolv.conf.d/base
/etc/resolvconf/resolv.conf.d/head
/etc/resolvconf/update.d
/etc/resolvconf/update.d/libc
/lib
/lib/resolvconf
/lib/resolvconf/list-records
/lib/systemd
/lib/systemd/system
/lib/systemd/system/resolvconf.service
/sbin
/sbin/resolvconf
/usr
/usr/share
/usr/share/doc
/usr/share/doc/resolvconf
/usr/share/doc/resolvconf/changelog.gz
/usr/share/doc/resolvconf/copyright
/usr/share/doc/resolvconf/NEWS.Debian.gz
/usr/share/doc/resolvconf/README.gz
/usr/share/doc/resolvconf/resolvconf-update-bind
/usr/share/lintian
/usr/share/lintian/overrides
/usr/share/lintian/overrides/resolvconf
/usr/share/man
/usr/share/man/man5
/usr/share/man/man5/interface-order.5.gz
/usr/share/man/man8
/usr/share/man/man8/resolvconf.8.gz
/usr/share/resolvconf
/usr/share/resolvconf/dump-debug-info
/var
/var/lib
/var/lib/resolvconf



執行


$ tree /etc/resolvconf/



顯示


/etc/resolvconf/
├── interface-order
├── resolv.conf.d
│   ├── base
│   └── head
├── update.d
│   └── libc
└── update-libc.d
    └── avahi-daemon

3 directories, 5 files



執行


$ tree /run/resolvconf/



顯示


/run/resolvconf/
├── enable-updates
├── interface
│   └── NetworkManager
└── resolv.conf

1 directory, 3 files



下面的心得,
我是閱讀「man resolvconf」,
以及觀看「/sbin/resolvconf」和「/etc/resolvconf/update.d/libc」這兩個「Shell Script」來對照觀看。
並且做一些簡單的測試,來輔助了解其中的規則。

執行


$ man resolvconf



可以看到其中一段內容如下,


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

執行


$ ls -l /etc/resolv.conf



顯示


lrwxrwxrwx 1 root root 29 Mar 14 13:31 /etc/resolv.conf -> ../run/resolvconf/resolv.conf



可以了解到「/etc/resolv.conf」是「Symbolic Link」到 「/run/resolvconf/resolv.conf」。


執行「man resolvconf」可以看到下面這一段說明。


To make the resolver use this dynamically generated resolver configuration file the administrator should ensure that /etc/resolv.conf is a
symbolic link to /run/resolvconf/resolv.conf. This link is normally created on installation of the resolvconf package. The link is never
modified by the resolvconf program itself. If you find that /etc/resolv.conf is not being updated, please check to make sure that the link
is intact.




執行下面指令觀看「/etc/resolv.conf」的內容



$ 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
nameserver 127.0.1.1



================================================================================

## 關於「/etc/resolvconf/resolv.conf.d/head」和「/etc/resolvconf/resolv.conf.d/tali

執行


$ man resolvconf



可以看到其中有一段


The dynamically generated resolver configuration file always starts with the contents of /etc/resolvconf/resolv.conf.d/head and ends with
the contents of /etc/resolvconf/resolv.conf.d/tail.



以下是「/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」,加入下面的內容


# head start
nameserver 8.8.8.8
# head end



所以「/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」,加入下面的內容


# tail start
nameserver 8.8.4.4
# tail end



執行下面指令更新


$ sudo resolvconf -u



會更新「/run/resolvconf/resolv.conf」,

上面有提到「/etc/resolv.conf」是「Symbolic link」到「/run/resolvconf/resolv.conf」

執行下面指令,觀看更新後的內容


$ view /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
# 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」,原本也是沒有內容的。

一開始我加入下面的內容


# base start
nameserver 8.8.8.8
nameserver 8.8.4.4
# base end



再次執行下面指令更新


$ sudo resolvconf -u



執行下面指令,觀看更新後的內容


$ view /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
# 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」這個檔案,(原本是沒有這個檔案的

設定內容如下


TRUNCATE_NAMESERVER_LIST_AFTER_LOOPBACK_ADDRESS=n



不過在「man resolvconf」提到「A deprecated synonym for this variable is TRUNCATE_NAMESERVER_LIST_AFTER_127.」

所以或是設定下面這個,一樣會有作用,


TRUNCATE_NAMESERVER_LIST_AFTER_127=n



再次執行下面指令更新


$ sudo resolvconf -u



執行下面指令,觀看更新後的內容


$ view /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
# head start
nameserver 8.8.8.8
# head end
nameserver 127.0.1.1
nameserver 8.8.8.8
nameserver 8.8.4.4
# tail start
nameserver 8.8.4.4
# tail end



執行「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」設定如下面的內容來測試


nameserver 8.8.8.8 208.67.222.222 208.67.220.220
nameserver 8.8.4.4



然後執行「sudo resolvconf -u」。

再執行「view /etc/resolvconf」觀看「/etc/resolvconf」的內容。

顯示


# 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
nameserver 8.8.8.8
nameserver 208.67.222.222

# tail start
nameserver 8.8.4.4
# tail end



註:上面的「ip」我是從「Arch Wiki / resolv.conf」找到的。


執行「man resolvconf」可以看到其中有一段說明


Between head and tail the libc script inserts dynamic nameserver information compiled
from, first, information provided for configured interfaces; second, static information from /etc/resolvconf/resolv.conf.d/base. Specifi‐
cally, it writes:

1) up to three nameserver lines, ordered according to /etc/resolvconf/interface-order, possibly fewer if one of the addresses is a loop‐
back address and the TRUNCATE_NAMESERVER_LIST_AFTER_LOOPBACK_ADDRESS environment variable is affirmatively set, as discussed in the
ENVIRONMENT VARIABLES section;

2) up to one search line containing the combined domain search list from all "domain" and "search" input lines, also ordered according to
interface-order(5);

3) all other non-comment input lines.



================================================================================

以下的操作可以閱讀「man resolvconf」,
以及觀看「/sbin/resolvconf」和「/etc/init.d/resolvconf」來了解。


下面摘錄「/sbin/resolvconf」一開始設定的變數,下面說明會用到


RUN_DIR=/run/resolvconf
ENABLE_UPDATES_FLAGFILE="${RUN_DIR}/enable-updates"
POSTPONED_UPDATE_FLAGFILE="${RUN_DIR}/postponed-update"



================================================================================

## --enable-updates

執行


$ man resolvconf



可以看到其中一段說明,列在下面


--enable-updates
Set the flag indicating that resolvconf should run update scripts when invoked in the future with -a, -d or -u. If a delayed update
was scheduled then run update scripts.



觀看「/sbin/resolvconf」可以看到其中一段內容,列在下面


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




執行


$ sudo resolvconf --enable-updates



上面的指令,其中有一個動作,會產生「/var/run/resolvconf/enable-updates」這個檔案

然後執行


$ echo $?



顯示


0



上面是關於「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」。

所以也可以執行下面的指令


$ sudo /etc/init.d/resolvconf enable-updates



或是執行


$ sudo service 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」。


以上套件,可以執行下面指令找到。

執行


$ dpkg -l '*systemd*'



顯示


Desired=Unknown/Install/Remove/Purge/Hold
| Status=Not/Inst/Conf-files/Unpacked/halF-conf/Half-inst/trig-aWait/Trig-pend
|/ Err?=(none)/Reinst-required (Status,Err: uppercase=bad)
||/ Name Version Architecture Description
+++-===============================-====================-====================-============
ii dh-systemd 1.29ubuntu4 all debhelper add-on to handle systemd unit files
ii libpam-systemd:amd64 229-4ubuntu16 amd64 system and service manager - PAM module
un libsystemd-daemon-dev <none> <none> (no description available)
ii libsystemd-dev:amd64 229-4ubuntu16 amd64 systemd utility library - development files
un libsystemd-id128-dev <none> <none> (no description available)
un libsystemd-journal-dev <none> <none> (no description available)
un libsystemd-login-dev <none> <none> (no description available)
ii libsystemd0:amd64 229-4ubuntu16 amd64 systemd utility library
ii python3-systemd 231-2build1 amd64 Python 3 bindings for systemd
ii systemd 229-4ubuntu16 amd64 system and service manager
un systemd-container <none> <none> (no description available)
un systemd-services <none> <none> (no description available)
un systemd-shim <none> <none> (no description available)
ii systemd-sysv 229-4ubuntu16 amd64 system and service manager - SysV links
un systemd-ui <none> <none> (no description available)




執行


$ dpkg -l '*upstart*'



顯示


Desired=Unknown/Install/Remove/Purge/Hold
| Status=Not/Inst/Conf-files/Unpacked/halF-conf/Half-inst/trig-aWait/Trig-pend
|/ Err?=(none)/Reinst-required (Status,Err: uppercase=bad)
||/ Name Version Architecture Description
+++-===============================-====================-====================-============
un gir1.2-upstart-app-launch-2 <none> <none> (no description available)
ii upstart 1.13.2-0ubuntu21.1 amd64 event-based init daemon - essential binaries
un upstart-app-launch <none> <none> (no description available)
un upstart-app-launch-tools <none> <none> (no description available)
un upstart-bin <none> <none> (no description available)
un upstart-compat-sysv <none> <none> (no description available)
un upstart-job <none> <none> (no description available)
un upstart-monitor <none> <none> (no description available)
un upstart-sysv <none> <none> (no description available)




執行


$ dpkg -l '*sysv*'



顯示


Desired=Unknown/Install/Remove/Purge/Hold
| Status=Not/Inst/Conf-files/Unpacked/halF-conf/Half-inst/trig-aWait/Trig-pend
|/ Err?=(none)/Reinst-required (Status,Err: uppercase=bad)
||/ Name Version Architecture Description
+++-===============================-====================-====================-============
un git-daemon-sysvinit <none> <none> (no description available)
un php-sysvmsg <none> <none> (no description available)
un php-sysvsem <none> <none> (no description available)
un php-sysvshm <none> <none> (no description available)
un php7.0-sysvmsg <none> <none> (no description available)
un php7.0-sysvsem <none> <none> (no description available)
un php7.0-sysvshm <none> <none> (no description available)
ii systemd-sysv 229-4ubuntu16 amd64 system and service manager - SysV links
ii sysv-rc 2.88dsf-59.3ubuntu2 all System-V-like runlevel change mechanism
un sysvconfig <none> <none> (no description available)
un sysvinit <none> <none> (no description available)
un sysvinit-core <none> <none> (no description available)
ii sysvinit-utils 2.88dsf-59.3ubuntu2 amd64 System-V-like utilities
un upstart-compat-sysv <none> <none> (no description available)
un upstart-sysv <none> <none> (no description available)



執行


$ dpkg -l '*init*'



顯示


Desired=Unknown/Install/Remove/Purge/Hold
| Status=Not/Inst/Conf-files/Unpacked/halF-conf/Half-inst/trig-aWait/Trig-pend
|/ Err?=(none)/Reinst-required (Status,Err: uppercase=bad)
||/ Name Version Architecture Description
+++-===============================-====================-====================-============
ii busybox-initramfs 1:1.22.0-15ubuntu1 amd64 Standalone shell setup for initramfs
un git-daemon-sysvinit <none> <none> (no description available)
ii init 1.29ubuntu4 amd64 System-V-like init utilities - metapackage
ii init-system-helpers 1.29ubuntu4 all helper tools for all init systems
ii initramfs-tools 0.122ubuntu8.8 all generic modular initramfs generator (automation)
ii initramfs-tools-bin 0.122ubuntu8.8 amd64 binaries used by initramfs-tools
ii initramfs-tools-core 0.122ubuntu8.8 all generic modular initramfs generator (core tools)
ii initscripts 2.88dsf-59.3ubuntu2 amd64 scripts for initializing and shutting down the system
ii kinit 5.18.0-0ubuntu1.1 amd64 process launcher to speed up launching KDE applications
un linux-initramfs-tool <none> <none> (no description available)
ii live-boot-initramfs-tools 1:20151213 all Live System Boot Components (initramfs-tools backend)
un module-init-tools <none> <none> (no description available)
ii pastebinit 1.5-1 all command-line pastebin client
ii ruby-minitest 5.8.4-2 all Ruby test tools supporting TDD, BDD, mocking, and benchmarking
un sysvinit <none> <none> (no description available)
un sysvinit-core <none> <none> (no description available)
ii sysvinit-utils 2.88dsf-59.3ubuntu2 amd64 System-V-like utilities
ii xinit 1.3.4-3ubuntu0.1 amd64 X server initialisation tool



若是「xsession」這一段,則是可以參考「這篇」。

================================================================================

## --disable-updates

執行


$ man resolvconf



可以看到其中一段說明,列在下面


--disable-updates
	   Clear the flag.



觀看「/sbin/resolvconf」可以看到其中一段內容,列在下面


--disable-updates)
	  rm -f "$POSTPONED_UPDATE_FLAGFILE" || :
	  rm -f "$ENABLE_UPDATES_FLAGFILE" || exit 1
	  exit 0
	  ;;




執行


$ sudo resolvconf --disable-updates



上面的指令,其中有一個動作,會刪除「/var/run/resolvconf/enable-updates」這個檔案

然後執行


$ echo $?



顯示


0



接下來執行


$ sudo ls /var/run/resolvconf/enable-updates



顯示


ls: cannot access '/var/run/resolvconf/enable-updates': No such file or directory




接下來觀看「/etc/init.d/resolvconf」這個檔案,可以看到其中一段內容,列在下面


disable-updates)
	  resolvconf --disable-updates || log_action_end_msg_and_exit 1 "failed to disable updates"
	  exit 0
	  ;;



所以也可以執行下面的指令


$ sudo /etc/init.d/resolvconf disable-updates



或是執行


$ sudo service resolvconf disable-updates




================================================================================

## --updates-are-enabled

執行


$ man resolvconf



可以看到其中一段說明,列在下面


--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
	  ;;




執行


$ resolvconf --updates-are-enabled



然後執行


$ echo $?



當「/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
	  ;;




所以也可以執行下面的指令


$ sudo /etc/init.d/resolvconf status



或是執行


$ sudo service resolvconf status



================================================================================

## -u

執行


$ man resolvconf



可以看到其中一段說明,列在下面


-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
	  ;;




執行


$ sudo resolvconf -u



上面的指令,在上面有提到怎麼使用了,請參考上面的範例。


接下來觀看「/etc/init.d/resolvconf」這個檔案,可以看到其中一段內容,列在下面


reload|force-reload)
	  resolvconf -u || log_action_end_msg_and_exit 1 "failed to update"
	  exit 0
	  ;;



所以也可以執行下面的指令


$ sudo /etc/init.d/resolvconf reload



或是執行


$ sudo service resolvconf reload



================================================================================

## status

執行


$ service resolvconf status



或是執行


$ /etc/init.d/resolvconf status



或是執行


$ systemctl status resolvconf



顯示


● resolvconf.service - Nameserver information manager
Loaded: loaded (/lib/systemd/system/resolvconf.service; enabled; vendor preset: enabled)
Active: active (exited) since Wed 2017-03-15 20:26:13 CST; 6s ago
Docs: man:resolvconf(8)
Process: 5660 ExecStop=/sbin/resolvconf --disable-updates (code=exited, status=0/SUCCESS)
Process: 5716 ExecStart=/sbin/resolvconf --enable-updates (code=exited, status=0/SUCCESS)
Process: 5710 ExecStartPre=/bin/touch /run/resolvconf/postponed-update (code=exited, status=0/SUCCESS)
Process: 5707 ExecStartPre=/bin/mkdir -p /run/resolvconf/interface (code=exited, status=0/SUCCESS)
Main PID: 5716 (code=exited, status=0/SUCCESS)

Mar 15 20:26:13 at-home systemd[1]: Starting Nameserver information manager...
Mar 15 20:26:13 at-home systemd[1]: Started Nameserver information manager.




執行下面指令,觀看「/lib/systemd/system/resolvconf.service」這個檔


$ cat /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
   ;;




================================================================================

執行


$ sudo service resolvconf



或是執行


$ sudo /etc/init.d/resolvconf



顯示


Usage: /etc/init.d/resolvconf {start|stop|restart|reload|force-reload|enable-updates|disable-updates|status}



可以對照「/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

執行


$ cat /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

執行


$ grep 'Make the file' /etc/resolvconf/update.d/libc -n -A 7 -B 1



顯示


131-
132:### Make the file ###
133-: > "$TMPFILE"
134-[ -f "$HEADFILE" ] && cat "$HEADFILE" >> "$TMPFILE"
135-for N in $NMSRVRS ; do echo "nameserver $N" >> "$TMPFILE" ; done
136-[ "$SRCHS" ] && echo "search $SRCHS" >> "$TMPFILE"
137-[ "$RSLVCNFFILES" ] && sed -e '/^[[:space:]]*$/d' -e '/^[[:space:]]*#/d' -e '/^[[:space:]]*\(\(nameserver\)\|\(search\)\|\(domain\)\)[[:space:]]/d' $RSLVCNFFILES >> "$TMPFILE" 2>/dev/null
138-[ -f "$TAILFILE" ] && cat "$TAILFILE" >> "$TMPFILE"
139-




================================================================================

## 關於「dpkg-reconfigure resolvconf

若是「/etc/resolv.conf」這個檔案被刪除了,你可以執行下面的指令來修復


$ sudo dpkg-reconfigure resolvconf



會出現一個對話框,裡面的文字,可以在「/var/lib/dpkg/info/resolvconf.templates」找到。

當然也可以使用「ln」的方式。

執行


$ grep '/etc/resolv.conf' /var/lib/dpkg/info/resolvconf.*



或是執行


$ grep '/etc/resolv.conf' /var/lib/dpkg/info/resolvconf.* | grep ln



就會在「/var/lib/dpkg/info/resolvconf.postinst」這個檔案,找到相關的指令


/var/lib/dpkg/info/resolvconf.postinst: ln -nsf ../run/resolvconf/resolv.conf /etc/resolv.conf



所以若是使用「ln」的方式復原,範例指令如下


$ sudo ln -nsf ../run/resolvconf/resolv.conf /etc/resolv.conf




這可以回覆「這篇」提到的

GNOME Lover 寫到:
...略...
目前能提供的資訊如下:
1. sudo dpkg-reconfigure resolvconf 無效
...略...



還有回覆「這篇」提到的。

================================================================================

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

================================================================================

3/15 20:31:54
應用擴展 工具箱
回覆: 關於「resolvconf」的操作使用
管理員
註冊日期:
2011/3/11 6:32
所屬群組:
討論區管理群
等級: 44
HP : 216 / 1084
MP : 1088 / 21459
EXP: 38
離線
幫大忙了,感謝分享

3/15 23:03:52
本篇發表文章以「創用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
所屬群組:
已註冊使用者
等級: 33
HP : 161 / 806
MP : 508 / 13318
EXP: 24
離線
## 關於「/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」。

而其中有一行


nameserver 127.0.1.1



之前並沒有提到是依據那個檔案產生的,因為當時沒有深究,

經過研究後,該行是來自「/run/resolvconf/interface/NetworkManager」這個檔案。


================================================================================


可以先做個小實驗

執行


$ 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
nameserver 127.0.1.1



執行


$ cat /run/resolvconf/interface/NetworkManager



顯示


nameserver 127.0.1.1



執行下面指令,更改「/run/resolvconf/interface/NetworkManager」這個檔案的內容


$ sudo sh -c 'echo nameserver 8.8.4.4 > /run/resolvconf/interface/NetworkManager'



或是執行下面指令,更改「/run/resolvconf/interface/NetworkManager」這個檔案的內容


$ echo 'nameserver 8.8.4.4' | sudo resolvconf -a NetworkManager



執行


$ cat /run/resolvconf/interface/NetworkManager



顯示


nameserver 8.8.4.4



執行下面指令,就會重新產生「/run/resolvconf/resolv.conf


$ sudo resolvconf -u



然後執行


$ 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
nameserver 8.8.4.4



================================================================================

執行下面指令,將「/run/resolvconf/interface/NetworkManager」恢復原狀


$ echo 'nameserver 127.0.1.1' | sudo resolvconf -a NetworkManager



然後在執行下面指令,重新產生「/run/resolvconf/resolv.conf」。


$ sudo resolvconf -u



================================================================================

待續...

10/2 14:56:42
應用擴展 工具箱
回覆: 關於「resolvconf」的操作使用
會員五級
註冊日期:
2012/4/22 10:50
所屬群組:
已註冊使用者
等級: 33
HP : 161 / 806
MP : 508 / 13318
EXP: 24
離線
在進一步討論之前,先再來介紹「resolvconf」的用法。

上面有介紹過「resolvconf -u」的用法了。

接下來介紹「resolvconf -d」的用法。

================================================================================

## 關於「resolvconf -d

執行


$ ls /run/resolvconf/interface/NetworkManager



顯示


/run/resolvconf/interface/NetworkManager



接著執行下面指令


$ sudo resolvconf -d NetworkManager



然後執行下面指令,確認「/run/resolvconf/interface/NetworkManager」這個檔案是否存在


$ ls /run/resolvconf/interface/NetworkManager



顯示


ls: cannot access '/run/resolvconf/interface/NetworkManager': No such file or directory



表示「/run/resolvconf/interface/NetworkManager」這個檔案不存在。

================================================================================

接下來介紹「resolvconf -a」的用法。

================================================================================

## 關於「resolvconf -a」/ 方式一

上面有先使用過了。


執行下面指令,設定「/run/resolvconf/interface/NetworkManager」這個檔案的內容。


$ echo 'nameserver 8.8.8.8' | sudo resolvconf -a NetworkManager



執行下面指令,觀看「/run/resolvconf/interface/NetworkManager」這個檔案的內容


$ cat /run/resolvconf/interface/NetworkManager



顯示


nameserver 8.8.8.8



================================================================================

## 關於「resolvconf -a」/ 方式二

執行下面指令,先產生一個檔案「demo.txt」


$ echo 'nameserver 8.8.8.8' > demo.txt



然後再執行下面指令,設定「/run/resolvconf/interface/NetworkManager」這個檔案的內容。


$ cat demo.txt | sudo resolvconf -a NetworkManager



================================================================================

## 關於「resolvconf -a」/ 方式三

執行下面指令,先產生一個檔案「demo.txt」


$ echo 'nameserver 8.8.8.8' > demo.txt



然後再執行下面指令,設定「/run/resolvconf/interface/NetworkManager」這個檔案的內容。


$ sudo resolvconf -a NetworkManager < demo.txt



================================================================================

待續...

10/2 15:02:56
應用擴展 工具箱
回覆: 關於「resolvconf」的操作使用
會員五級
註冊日期:
2012/4/22 10:50
所屬群組:
已註冊使用者
等級: 33
HP : 161 / 806
MP : 508 / 13318
EXP: 24
離線
接下來再來談到關於「/run/resolvconf/interface/NetworkManager」這個檔案如何產生的。

推測應該是「NetworkManager」產生的。

================================================================================

## 實驗ㄧ

一樣先來做個小實驗,

做實驗前,先觀看一下「/etc/NetworkManager/NetworkManager.conf」的設定內容


$ cat /etc/NetworkManager/NetworkManager.conf



顯示


[main]
plugins=ifupdown,keyfile,ofono
dns=dnsmasq

[ifupdown]
managed=false



執行


$ ps aux | grep Network



顯示


root 1108 0.0 0.2 378548 12288 ? Ssl 14:22 0:00 /usr/sbin/NetworkManager --no-daemon
nobody 1448 0.0 0.0 56048 3700 ? S 14:22 0:00 /usr/sbin/dnsmasq --no-resolv --keep-in-foreground --no-hosts --bind-interfaces --pid-file=/var/run/NetworkManager/dnsmasq.pid --listen-address=127.0.1.1 --cache-size=0 --conf-file=/dev/null --proxy-dnssec --enable-dbus=org.freedesktop.NetworkManager.dnsmasq --conf-dir=/etc/NetworkManager/dnsmasq.d



執行


$ /etc/init.d/network-manager status



================================================================================

以下實驗開始,

執行下面指令,將「/run/resolvconf/interface/NetworkManager」這個檔案刪除


$ sudo resolvconf -d NetworkManager



然後執行下面指令,確認「/run/resolvconf/interface/NetworkManager」這個檔案是否存在


$ ls /run/resolvconf/interface/NetworkManager



顯示


ls: cannot access '/run/resolvconf/interface/NetworkManager': No such file or directory



表示「/run/resolvconf/interface/NetworkManager」這個檔案不存在。

================================================================================

接下來先執行下面指令,「Disable Networking」


$ nmcli network off




然後再執行下面指令,「Enable Networking」


$ nmcli network on



稍等一下,最後再執行下面指令,


$ cat /run/resolvconf/interface/NetworkManager



顯示


nameserver 127.0.1.1



表示「/run/resolvconf/interface/NetworkManager」這個檔案,又被重新產生。

註: 上面「Disable Networking」和「Enable Networking」這兩個動作,除了可以透過上面「nmcli」這個指令來操作,
也可以透過「nm-applet」這個圖形界面來操作,在下拉選單的選項「Enable Networking」,「取消勾選」和「勾選」。

================================================================================

## 實驗二

再來做另一個實驗

執行


$ nmcli connection



顯示


NAME UUID TYPE DEVICE
Ethernet connection 1 fc463c66-37c1-4ab7-91ef-aca74daa6c85 802-3-ethernet enp4s0



執行


$ sudo cat '/etc/NetworkManager/system-connections/Ethernet connection 1'




顯示


[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



執行


$ nmcli connection show 'Ethernet connection 1' | grep dns -i



顯示


ipv4.dns:
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



執行


$ cat /etc/NetworkManager/NetworkManager.conf



顯示


[main]
plugins=ifupdown,keyfile,ofono
dns=dnsmasq

[ifupdown]
managed=false



請將「dns=dnsmasq」那一行拿掉,也就是最後的結果是


[main]
plugins=ifupdown,keyfile,ofono

[ifupdown]
managed=false



然後執行下面指令


$ sudo /etc/init.d/network-manager force-reload



顯示


[ ok ] Reloading network-manager configuration (via systemctl): network-manager.service.



註:
也可以透過「SIGHUP」這個「SIGNAL」重新載入「NetworkManager」的「configuration.」,
可以參考「man NetworkManager」。
或是參考「#3 回覆: 關於「NetworkManager」的操作使用」這篇的說明。

執行


$ cat /run/resolvconf/interface/NetworkManager



顯示


$ nameserver 192.168.1.1



註:
另外有一個檔案「/run/NetworkManager/resolv.conf」,
內容也是跟上面一樣的,不過這個檔,目前沒去深究相關的作用,只是發現有這樣檔案存在。


執行


$ 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
nameserver 192.168.1.1



================================================================================

## 實驗三

更進一步的實驗,一樣接續著實驗二「/etc/NetworkManager/NetworkManager.conf」的「dns=dnsmasq」那一行是拿掉的

執行下面指令,產生一個新的連線設定。


$ nmcli connection add type ethernet ifname enp4s0 con-name con001



顯示


$ Connection 'con001' (e073d2fc-276a-4336-8666-26caea7c5ad4) successfully added.



執行


$ sudo cat /etc/NetworkManager/system-connections/con001



顯示


[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



執行


$ nmcli connection show con001 | grep dns -i



顯示


ipv4.dns:
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



執行下面指令,加入「ipv4.dns」到設定檔。


$ nmcli connection modify con001 +ipv4.dns 8.8.8.8,8.8.4.4



執行


$ sudo cat /etc/NetworkManager/system-connections/con001



顯示


[connection]
id=con001
uuid=e073d2fc-276a-4336-8666-26caea7c5ad4
type=ethernet
interface-name=enp4s0
permissions=
secondaries=

[ethernet]
mac-address-blacklist=

[ipv4]
dns=8.8.8.8;8.8.4.4;
dns-search=
method=auto

[ipv6]
addr-gen-mode=stable-privacy
dns-search=
method=auto




執行


$ nmcli connection show con001 | grep dns -i



顯示


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



執行


$ nmcli connection



顯示


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」


$ nmcli connection up con001



顯示


Connection successfully activated (D-Bus active path: /org/freedesktop/NetworkManager/ActiveConnection/3)



執行


$ nmcli connection



顯示


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



執行


$ nmcli connection show con001 | grep dns -i



顯示


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



執行


$ cat /run/resolvconf/interface/NetworkManager



顯示


nameserver 192.168.1.1
nameserver 8.8.8.8
nameserver 8.8.4.4



執行


$ 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
nameserver 192.168.1.1
nameserver 8.8.8.8
nameserver 8.8.4.4




================================================================================

待續...

10/2 15:13:07
應用擴展 工具箱
回覆: 關於「resolvconf」的操作使用
會員五級
註冊日期:
2012/4/22 10:50
所屬群組:
已註冊使用者
等級: 33
HP : 161 / 806
MP : 508 / 13318
EXP: 24
離線
接下來,來探索「network-manager」的「Source Package: network-manager

================================================================================

執行


$ apt-get source 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」當關鍵字,來找尋相關的檔案。


$ grep 'resolvconf' network-manager-1.2.6/* -R -n



顯示


...略...
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」當關鍵字找尋,執行下面指令


$ grep 'dispatch_resolvconf' network-manager-1.2.6/src/dns-manager/nm-dns-manager.c -n



顯示


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」的功能。

執行


$ grep 'RESOLVCONF_PATH' network-manager-1.2.6/src/dns-manager/nm-dns-manager.c -n



顯示


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,



先簡單探索到這,其餘的尚未深究。

================================================================================

待續...

10/2 15:22:17
應用擴展 工具箱
回覆: 關於「resolvconf」的操作使用
會員五級
註冊日期:
2012/4/22 10:50
所屬群組:
已註冊使用者
等級: 33
HP : 161 / 806
MP : 508 / 13318
EXP: 24
離線
要瞭解「resolvconf -u」的機制,可以「trace」下面三個檔案。

* /sbin/resolvconf
* /etc/resolvconf/update.d/libc
* /lib/resolvconf/list-records


以下會提到一些關鍵的點。

================================================================================

執行


$ grep 'RUN_DIR=' /sbin/resolvconf -n



顯示


12:RUN_DIR=/run/resolvconf



執行


$ grep '/interface' /sbin/resolvconf -n



顯示


53:mkdir -p "${RUN_DIR}/interface"
54:cd "${RUN_DIR}/interface"



注意,在執行「/sbin/resolvconf」時,過程中,會切換到「/run/resolvconf/interface」這個資料夾。

================================================================================

執行


$ grep 'update_and_exit' /sbin/resolvconf -n



顯示


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"



執行


$ grep 'update_and_exit' /sbin/resolvconf -n -A 5



顯示


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」的說明。



================================================================================

執行


$ grep 'Make the file' /etc/resolvconf/update.d/libc -n -A 7 -B 1



顯示


133-
134:### Make the file ###
135-: > "$TMPFILE"
136-[ -f "$HEADFILE" ] && cat "$HEADFILE" >> "$TMPFILE"
137-for N in $NMSRVRS ; do echo "nameserver $N" >> "$TMPFILE" ; done
138-[ "$SRCHS" ] && echo "search $SRCHS" >> "$TMPFILE"
139-[ "$RSLVCNFFILES" ] && sed -e '/^[[:space:]]*$/d' -e '/^[[:space:]]*#/d' -e '/^[[:space:]]*\(\(nameserver\)\|\(search\)\|\(domain\)\)[[:space:]]/d' $RSLVCNFFILES >> "$TMPFILE" 2>/dev/null
140-[ -f "$TAILFILE" ] && cat "$TAILFILE" >> "$TMPFILE"
141-



執行「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」。

================================================================================

執行


$ grep 'RSLVCNFFILES=' /etc/resolvconf/update.d/libc -n



顯示


110:RSLVCNFFILES="$(/lib/resolvconf/list-records)"
114:[ -f "$BASEFILE" ] && RSLVCNFFILES="$RSLVCNFFILES



================================================================================

執行


$ head /lib/resolvconf/list-records -n 12



顯示


#!/bin/bash
# Need bash because we use nullglob, extglob
#
# list-records [--after RECORD]
#
# Print, one per line, names of non-empty files in the current directory
# that match the shell glob patterns in /etc/resolvconf/interface-order.
# If the "--after RECORD" option is given and RECORD is not null then only
# start listing after RECORD (i.e., do not print RECORD itself, and if
# RECORD is not found then print nothing).
#



執行


$ grep 'uniquify' /lib/resolvconf/list-records -n



顯示


25:uniquify()
83:uniquify $PATTERNS



執行


$ grep 'uniquify' /lib/resolvconf/list-records -n -A 13



顯示


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-
--
...略...



================================================================================

執行


$ grep 'PATTERNS' /lib/resolvconf/list-records -n



顯示


42:PATTERNS="lo.inet6
65: PATTERNS="$(sed -e '
83:uniquify $PATTERNS


================================================================================

要了解「/lib/resolvconf/list-records」的用法,
還有「uniquify()」的用法,
可以先從下面幾個測試瞭解一些概念,


================================================================================

## 測試前提

執行


$ ls /run/resolvconf/interface



顯示


lo.dnsmasq NetworkManager



表示我測試的環境有下面兩個檔案

* /run/resolvconf/interface/lo.dnsmasq
* /run/resolvconf/interface/NetworkManager

註:
關於「/run/resolvconf/interface/lo.dnsmasq」這個檔案,
要安裝「dnsmasq」這個套件,然後在運行時,才會出現,這是另一個議題,暫不討論。

================================================================================

## 測試一

執行


cd /run/resolvconf/interface
echo *


顯示


lo.dnsmasq NetworkManager




================================================================================

## 測試二

執行


cd /run/resolvconf/interface
PATTERNS="*"
echo $PATTERNS


顯示


lo.dnsmasq NetworkManager



================================================================================

## 測試三

執行


cd /run/resolvconf/interface
PATTERNS="*"
echo "$PATTERNS"


注意上面「$PATTERNS」左右有加上「"」,所以並不會被展開,可以對照上面「測試二」。

所以顯示


*




================================================================================

## 測試四

執行


cd /run/resolvconf/interface
/lib/resolvconf/list-records



顯示


lo.dnsmasq
NetworkManager



================================================================================

## 測試五

執行


$ cat /run/resolvconf/interface/lo.dnsmasq



顯示


nameserver 127.0.0.1



執行


$ cat /run/resolvconf/interface/NetworkManager



顯示


nameserver 127.0.1.1



執行


cd /run/resolvconf/interface/

sed -e /^[[:space:]]*$/d -e /^[[:space:]]*#/d -e /^[[:space:]]*\(\(nameserver\)\|\(search\)\|\(domain\)\)[[:space:]]/d lo.dnsmasq NetworkManager



顯示


nameserver 127.0.0.1
nameserver 127.0.1.1



================================================================================

以上補充

報告完畢


10/2 15:30:47
應用擴展 工具箱


 [無發表權] 請登錄或者註冊


可以查看帖子.
不可發帖.
不可回覆.
不可編輯自己的帖子.
不可刪除自己的帖子.
不可發起投票調查.
不可在投票調查中投票.
不可上傳附件.
不可不經審核直接發帖.