LoginSignup
11
9

More than 3 years have passed since last update.

macOS Server用 BIND(DNSサーバ)のセットアップ

Last updated at Posted at 2018-11-16

はじめに

『macOS Server 5.7』からDNSサービスがなくなった為、サーバの自分自身の名前解決のためのBIND(DNSサーバ)のセットアップを解説。だだし、DNSは汚染されるとセキュリティ上の問題になるため、ゾーンファイルの作成方法などは解説しません。オライリーの『DNS&BIND』やネット記事などで、知識を深めてから運用しましょう。

セットアップ方法

DNSサーバはBINDを使用します。BINDの導入については、『Homebrew』を使用します。『Command Line Tools』と『Homebrew』はインストール済みとします。

おおまかな流れ

  • HomebrewからBINDをインストール
  • Homebrewの機能を利用して、スタートアップファイル作成
  • BINDの基本動作確認
  • 設定ファイルを作成
  • 設定ファイルのデバッグ
  • DNSの動作確認

手順

BIND(DNSサーバ)のインストール

bindのFurmulaを探す

$ brew search bind
==> Formulae
bind        bindfs      glbinding   go-bindata  libbind     luabind     pybind11    valabind    vbindiff

bindのFurmulaの詳細を確認

$ brew info bind
bind: stable 9.12.3 (bottled), HEAD
Implementation of the DNS protocols
https://www.isc.org/downloads/bind/
Not installed
From: https://github.com/Homebrew/homebrew-core/blob/master/Formula/bind.rb
==> Dependencies
Required: json-c ✘, openssl ✘
==> Options
--HEAD
    Install HEAD version
==> Caveats
To have launchd start bind now and restart at startup:
  sudo brew services start bind
==> Analytics
install: 1,125 (30 days), 3,234 (90 days), 9,563 (365 days)
install_on_request: 811 (30 days), 2,224 (90 days), 6,249 (365 days)
build_error: 0 (30 days)

bindをインストール

$ brew install bind
Updating Homebrew...
==> Auto-updated Homebrew!
Updated 1 tap (homebrew/core).
==> Updated Formulae
beast                                mongodb                              node-build

==> Installing dependencies for bind: json-c and openssl
==> Installing bind dependency: json-c
==> Downloading https://homebrew.bintray.com/bottles/json-c-0.13.1.mojave.bottle.tar.gz
######################################################################## 100.0%
==> Pouring json-c-0.13.1.mojave.bottle.tar.gz
🍺  /usr/local/Cellar/json-c/0.13.1: 28 files, 232.3KB
==> Installing bind dependency: openssl
==> Downloading https://homebrew.bintray.com/bottles/openssl-1.0.2p.mojave.bottle.tar.gz
######################################################################## 100.0%
==> Pouring openssl-1.0.2p.mojave.bottle.tar.gz
==> Caveats
A CA file has been bootstrapped using certificates from the SystemRoots
keychain. To add additional certificates (e.g. the certificates added in
the System keychain), place .pem files in
  /usr/local/etc/openssl/certs

and run
  /usr/local/opt/openssl/bin/c_rehash

openssl is keg-only, which means it was not symlinked into /usr/local,
because Apple has deprecated use of OpenSSL in favor of its own TLS and crypto libraries.

If you need to have openssl first in your PATH run:
  echo 'export PATH="/usr/local/opt/openssl/bin:$PATH"' >> ~/.bash_profile

For compilers to find openssl you may need to set:
  export LDFLAGS="-L/usr/local/opt/openssl/lib"
  export CPPFLAGS="-I/usr/local/opt/openssl/include"

==> Summary
🍺  /usr/local/Cellar/openssl/1.0.2p: 1,793 files, 12MB
==> Installing bind
==> Downloading https://homebrew.bintray.com/bottles/bind-9.12.3.mojave.bottle.tar.gz
######################################################################## 100.0%
==> Pouring bind-9.12.3.mojave.bottle.tar.gz
==> Caveats
To have launchd start bind now and restart at startup:
  sudo brew services start bind
==> Summary
🍺  /usr/local/Cellar/bind/9.12.3: 342 files, 52.1MB
==> Caveats
==> openssl
A CA file has been bootstrapped using certificates from the SystemRoots
keychain. To add additional certificates (e.g. the certificates added in
the System keychain), place .pem files in
  /usr/local/etc/openssl/certs

and run
  /usr/local/opt/openssl/bin/c_rehash

openssl is keg-only, which means it was not symlinked into /usr/local,
because Apple has deprecated use of OpenSSL in favor of its own TLS and crypto libraries.

If you need to have openssl first in your PATH run:
  echo 'export PATH="/usr/local/opt/openssl/bin:$PATH"' >> ~/.bash_profile

For compilers to find openssl you may need to set:
  export LDFLAGS="-L/usr/local/opt/openssl/lib"
  export CPPFLAGS="-I/usr/local/opt/openssl/include"

==> bind
To have launchd start bind now and restart at startup:
  sudo brew services start bind

bindを一回起動してTapする。結果として、/Library/LaunchDaemons/homebrew.mxcl.bind.plistが作成される。

$ sudo brew services start bind
Password:
==> Tapping homebrew/services
Cloning into '/usr/local/Homebrew/Library/Taps/homebrew/homebrew-services'...
remote: Enumerating objects: 14, done.
remote: Counting objects: 100% (14/14), done.
remote: Compressing objects: 100% (10/10), done.
remote: Total 14 (delta 0), reused 9 (delta 0), pack-reused 0
Unpacking objects: 100% (14/14), done.
Tapped 1 command (44 files, 58.6KB).
==> Successfully started `bind` (label: homebrew.mxcl.bind)

起動しているか確認

$ ps awux | grep -v grep | grep named

一旦停止する

$ sudo brew services stop bind

ログを確認する

$ cat /usr/local/var/log/named/named.log 
14-Nov-2018 18:03:14.683 managed-keys-zone: loaded serial 0
14-Nov-2018 18:03:14.688 zone 0.0.127.in-addr.arpa/IN: loaded serial 1997022700
14-Nov-2018 18:03:14.691 zone localhost/IN: loaded serial 42
14-Nov-2018 18:03:14.692 all zones loaded
14-Nov-2018 18:03:14.693 running

BIND構成の確認

  • bindのインストール先:/usr/local/Cellar/bind/9.12.3
  • name.conf:/usr/local/etc/named.conf
  • rndc.key:/usr/local/etc/rndc.key
  • ゾーンファイルのディレクトリ:/usr/local/var/named
  • ログファイル:/usr/local/var/log/named/named.log
  • 起動ファイル:/Library/LaunchDaemons/homebrew.mxcl.bind.plist
  • 起動コマンド:/usr/local/opt/bind/sbin/named -f -c /usr/local/etc/named.conf

BINDの起動・停止・再起動

起動
sudo brew services start bind
停止
sudo brew services stop bind
再起動
sudo brew services restart bind

このあとすることは、、、

named.confを書き換えることによって、『マスター』、『スレーブ』、『キャッシュ』サーバを作成することができる。macOS Server向けのDNSと限定して考えると、内部向けの『マスター』と『キャッシュ』サーバの構築ということになるかと思われる。

例えば、内部向けの『マスター』と『キャッシュ』サーバの構築の設定のポイントは、

  • ipv6からの応答を無効(場合による)
  • dnsの問い合わせをlocalhost and/or localnetsに限定
  • rndcの応答をlocalhostに限定
  • 『キャッシュ』用のヒントファイルを用意
  • 『マスター』用のゾーンファイル正引き・逆引きを用意
  • ログのローテーョンを指定
  • セキュリテイを再考

便利なコマンド

dig

基本は、dig @nameserver domain q-type
逆引きは、dig @nameserver -x ip

ステイタスの確認
$ dig 127.0.0.1 www.example.com A
$ dig @127.0.0.1 -x 10.0.1.100

netstat

応答状況の確認

ステイタスの確認
$ netstat -an -f inet

rndc

homebrew版だと、rndcのパスが通っていないので、/usr/local/sbin/rndcと打つかパスを通す。name.confの設定でportが953ではなく、54になっているのでポート番号も指定する。rndcからのrndc.keyのパスも通ってないのでパスを指定する。

ステイタスの確認
$ sudo rndc -k /usr/local/etc/rndc.key -p 54 status

rndc statsとrndc dumpdbを使う場合、/usr/local/var/named/に、named.statsまたは、named_dump.dbが作成される。

BINDの名前解決の統計情報をファイルに出力
$ sudo rndc -k /usr/local/etc/rndc.key -p 54 stats
メモリー上のキャッシュをファイルに出力
$ sudo rndc -k /usr/local/etc/rndc.key -p 54 dumpdb

named-checkconf

named.confが正しい記述をされているか文法のチェックができる。設定のチェックは行いません。

name.confのチェック
$ sudo named-checkconf /usr/local/etc/named.conf

named-checkzone

named-checkzone ドメイン名 ファイル名

BINDの名前解決の統計情報をファイルに出力
$ sudo named-checkzone example.com example.com.zone
$ sudo named-checkzone 10.0.0.in-addr.arpa example.com.zone

追記

IPv6を設定してないとエラーログがいっぱい吐き出される件

Big SurにBIND 9.16.11をインストールしたら、IPv6を設定していなとログがいっぱい吐き出される。その回避策。

/usr/local/Cellar/bind/9.16.11/homebrew.mxcl.bind.plistを編集して、IPv4のみのモードにする。(plist形式で記述)

IPv4モード
/usr/local/opt/bind/sbin/named -4 -f -c /usr/local/etc/named.conf

リファレンス

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