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


正在瀏覽:   1 名遊客


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



關於「resolvconf」的操作使用
會員五級
註冊日期:
2012/4/22 10:50
所屬群組:
已註冊使用者
等級: 31
HP : 153 / 765
MP : 447 / 11735
EXP: 60
離線
# 關於「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」也可以設定「192.168.1.1」也就是您的AP位址,更多的位址可以參考「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



就行了。
即使是重開機,也會保持原來的修改,可以參考下面的說明。


而以下是探索的紀錄


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

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



TODO: 我遇到的狀況,尚未確定是否跟「dnsmasq」有關,有些概念還不懂,先暫記,:p

* Debian Wiki / dnsmasq
* Ubuntu Community Help Wiki / Dnsmasq

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

執行


$ 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




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

執行


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

一開始我加入下面的內容


# 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



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

## 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 無效
...略...



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


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

以上提供參考,讓未來想要探索這方面議題的人,有探索的起點。

一些套件探索的技巧,可以參考這篇「[索引] 套件操作實務」。

報告完畢



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

後記 (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 / 20172
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
應用擴展 工具箱


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


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