KITA Eng.

北海道でサーバー技術者として歩み出したひとが綴るblog。

/etc/resolv.conf についての取り扱いUbuntu12.04以降から

Ubuntuにおいては、12.04LTSから/etc/resolv.confのしくみが変わったようです。 確かに、12.04LTSのリリースノートにもさりげなく書かれています。

"PrecisePangolin/ReleaseNotes/UbuntuServer - Ubuntu Wiki"

Common Infrastructure
resolvconf is now used to manage /etc/resolv.conf on all Ubuntu systems. You can learn more here

resolvconfってのが/etc/resolv.confを管理するようになったそうです。詳しいことはリンク先を読めよっていうので、クリックしてみると...

リンク先の"DNS in Ubuntu 12.04 | Stéphane Graber's website"には、次のようにあります。

resolvconf is a set of script and hooks managing DNS resolution. The most notable difference for the user is that any change manually done to /etc/resolv.conf will be lost as it gets overwritten next time something triggers resolvconf. Instead, resolvconf uses DHCP client hooks, a Network Manager plugin and /etc/network/interfaces to generate a list of nameservers and domain to put in /etc/resolv.conf.

resolvconfっていうので、/etc/resolv.confは管理するようになったから、/etc/resolv.confに手動で変更を加えても、resolvconfが何らかによって動かされたときにすべて上書きされてしまうということだそうです。

詳しいことは、man resolvconfmanページに書かれているのですが、要点については、リンク先でも言及されていて、以下の通りです。

I use static IP configuration, where should I put my DNS configuration?
The DNS configuration for a static interface should go as “dns-nameservers”, “dns-search” and “dns-domain” entries added to the interface in /etc/network/interfaces
How can I override resolvconf’s configuration or append some entries to it?
Resolvconf has a /etc/resolvconf/resolv.conf.d/ directory that can contain “base”, “head”, “original” and “tail” files. All in resolv.conf format.
base: Used when no other data can be found
head: Used for the header of resolv.conf, can be used to ensure a DNS server is always the first one in the list
original: Just a backup of your resolv.conf at the time of resolvconf installation
tail: Any entry in tail is appended at the end of the resulting resolv.conf. In some cases, upgrading from a previous Ubuntu release, will make tail a symlink to original (when we think you manually modified resolv.conf in the past)
I really don’t want resolvconf, how can I disable it?
I certainly wouldn’t recommend disabling resolvconf but you can do it by making /etc/resolv.conf a regular file instead of a symlink.
Though please note that you may then be getting inconsistent /etc/resolv.conf when multiple software are fighting to change it.

巷では、baseに書いてあげればOKみたいなことが書かれているものもありますが、この説明を読む限り、/etc/resolvconf/resolv.conf.d/baseDNS解決について、他に参照すべきものがなかった時に使われるファイルのようです。baseに書いてsudo resolvconf -uしたけど駄目だったみたいなことが起こるのは、baseを読むまでもなく、他にDNS解決について参照すべきものがあったから読み込まれなかったということなのでしょう。自分の最初はbaseに書いても反映されないじゃん現象で悩みました。

headは、とにかくresolv.confの先頭に挿入されるものを記述するファイルのようです。/etc/resolv.confの先頭にあるコメントの部分もここから拾われているようです。

/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を見たときには、ここに書いたやつは更新されて消えてしまうんだって本気で思いましたが、そういうことではなかったようです。なんと紛らわしい...
どうしても上のほうに入れたいDNSサーバーとかがあれば/etc/resolvconf/resolv.conf.d/headに書けばよさそうです。

originalは途中からresolvconfがインストールされたのでなければ関係なさそう。resolvconfがインストールされたときにあった、/etc/resolv.confを保持するファイルっぽい。うちのUbuntu 14.04 LTSにはoriginのファイルはなかった。

tailは、とにかく/etc/resolv.confの最後尾につけられる部分とのことです。他のDNSの設定がうまくないときの最終奥義的なものでしょうか。一般的な環境ならGoogleのパブリックDNSとかのIPを入れといたらいんじゃないかと個人的には思ったりします。というか、先日のVPN Clientを起動させてVPNをつなぐと名前解決がうまくいかない問題は、これで解決しました。

/etc/resolv.confにかかわる設定ファイル群はまだあるようですが、今日はここまでです。