LoginSignup
35
26

More than 5 years have passed since last update.

ネームサーバーを変更する

Last updated at Posted at 2015-11-23

はじめに

昨今のLinuxは、サービスの起動・管理にsystemdという名前のソフトウェアが採用されています。これまではupstartという名前のソフトウェアが主流でしたが、現在は大半のLinux系OSがsystemdを採用しているので、systemdの仕様に慣れる必要があります。

upstartにおけるサービスの起動等

upstart
$ service サービス名 start/restart/stop
または、
$ /etc/init.d/サービス名 start/restart/stop

systemdにおけるサービスの起動等

systemd
$ systemctl start/restart/stop サービス名

ネームサーバーを変更する

/etc/systemd/resolved.confのDNSディレクティブのコメントを外し、参照したいネームサーバを追記することで設定を変更することができます。例えば、BIND, dnsmasq, unboundなどのDNSサービスが起動しているサーバのアドレスが192.168.0.2だとすると下記のように記述します。

/etc/systemd/resolved.conf
#  This file is part of systemd.
# ...
# See resolved.conf(5) for details

[Resolve]
DNS=192.168.0.2
#FallbackDNS=
#LLMNR=yes

systemdにおいて、名前解決を管理しているサービスを再起動します。

$ systemctl restart systemd-resolved.service

以上で参照するネームサーバの修正は完了です。
名前解決が反映されない場合は、ネームサーバ側のDNSサービスを再起動すればうまくいくようになるかもしれません。

以下の項目は補足です。

systemdにおけるresolv.conf

systemdにおいて/etc/resolv.confは、/run/systemd/resolve/resolv.confへのシンボリックリンクとなっています。/etc/resolv.confを修正してもその変更は反映されません。

 $ ls -l /etc/resolv.conf 
lrwxrwxrwx 1 root root 34 Nov 19 10:31 /etc/resolv.conf 
 -> ../run/systemd/resolve/resolv.conf

systemdにおけるresolv.confの実態は、/run/systemd/resolve/resolv.confです。ただし、/etc/resolv.conf`と同じようにこのファイルを直接修正してもその変更は反映されません。

/run/systemd/resolve/resolv.conf
# This file is managed by systemd-resolved(8). Do not edit.
#
# Third party programs must not access this file directly, but
# only through the symlink at /etc/resolv.conf. To manage
# resolv.conf(5) in a different way, replace the symlink by a
# static file or a different symlink.

nameserver 192.168.0.1

systemd-resolved.service

systemdでは、Unitという単位で処理を管理し、Unitの定義ファイルは、/usr/lib/systemd/systemディレクトリに保存されています。Unitに関する詳細はこちらをご参照ください。
/run/systemd/resolve/resolv.confを見ると冒頭部分に「This file is managed by systemd-resolved(8).」と書いてあるので、ネームサーバに関する設定はsystemd-resolvedによって管理されていることがわかります。
公式ドキュメントによると、参照するDNSサーバ(ネームサーバ)は、下記の3つから決定されると書いてあります。いづれかの方法でDNSサーバの参照先を変更することができます。

  • /etc/systemd/resolved.conf
  • /etc/systemd/network/*.network
  • DHCP

最後に

systemdにおけるサービスの管理詳細は、主にこちらの公式ドキュメントに記載されています。

35
26
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
35
26