Dnsmasq
dnsmasq は1000 クライアント以下のローカルネットワークで使用できるシンプルな DHCP/DNS サーバです。主な特徴は設定の簡単さと軽量さです。IPv6 にも対応しています。
インストール
USE フラグ
適切な USE フラグを選択してください:
USE flags for net-dns/dnsmasq Small forwarding DNS server
auth-dns
|
Add support for acting as an authorative DNS server. |
conntrack
|
Add support for Linux conntrack connection marking. |
dbus
|
Enable dbus support for anything that needs it (gpsd, gnomemeeting, etc) |
dhcp
|
Enable support for acting as a DHCP server. |
dhcp-tools
|
Install extra command line tools for manually managing DHCP leases. |
dnssec
|
Enable support DNSSEC validation and caching. |
dumpfile
|
Include code to dump packets to a libpcap-format file for debugging |
id
|
Whether report *.bind CHAOS info to clients, otherwise forward such requests upstream instead |
idn
|
Enable support for Internationalized Domain Names |
inotify
|
Enable inotify filesystem monitoring support |
ipv6
|
Add support for IP version 6 |
libidn2
|
Enable support for Internationalized Domain Names, via net-dns/libidn2 rather than net-dns/libidn |
loop
|
Include functionality to probe for and remove DNS forwarding loops |
lua
|
Enable Lua scripting support |
nettlehash
|
Use hashing functions from dev-libs/nettle |
nls
|
Add Native Language Support (using gettextGNU locale utilities) |
script
|
Enable support for calling scripts when leases change. |
selinux
|
!!internal use only!! Security Enhanced Linux support, this must be set by the selinux profile or breakage will occur |
static
|
!!do not set this during bootstrap!! Causes binaries to be statically linked instead of dynamically |
tftp
|
Enables built in TFTP server for netbooting. |
Emerge
次に、net-dns/dnsmasq パッケージをインストールしてください:
root #
emerge --ask net-dns/dnsmasq
設定
dnsmasq の振る舞いを変えるには、さまざまなリソースを変更することで行えます。これには以下が含まれます。
- /etc/conf.d/dnsmasq を通じて提供されるコマンドラインオプション
- メインの設定ファイル (/etc/dnsmasq.conf)
サービス
OpenRC
自動的に開始する必要がある場合は、dnsmasq を default ランレベルに追加してください:
root #
rc-update add dnsmasq default
すぐにサービスを開始するには:
root #
rc-service dnsmasq start
サービスの設定
/etc/conf.d/dnsmasq では、dnsmasq デーモンの起動時に渡されるコマンドラインオプションを設定できます。
/etc/conf.d/dnsmasq
dnsmasq サービス設定の例DNSMASQ_OPTS="--user=dnsmasq --group=dnsmasq -H /srv/virt/gentoo/hosts --max-cache-ttl=10"
メインの設定ファイル
dnsmasq の主な設定は /etc/dnsmasq.conf 設定ファイルを通じて行われます。このファイルは キー[=値]
の構文を使用しています。パッケージにより提供されるファイルはよく文書化されており、通しで読むことをおすすめします。ファイルの中で、あるいはコマンドラインオプションを通じて、(DHCP hosts ファイル等の) 追加のリソースに言及されているかもしれません。
以下はサンプルの設定ファイルです:
/etc/dnsmasq.conf
# このインターフェースだけで listen する interface=eth1 # mac アドレスに基づいて名前を割り当てる dhcp-host=00:1e:68:c2:ff:ee,endor,192.168.0.54,24h # 他の DHCP リクエストはこの範囲から ip を取得する dhcp-range=eth1,192.168.0.100,192.168.0.120,12h # TFTP サーバを有効化し、TFTP からアクセスできるファイルのルートディレクトリを設定する。 enable-tftp tftp-root=/var/lib/tftpboot dhcp-boot=/pxelinux.0
設定ファイルの編集が完了したら、サービスを再起動する必要があります。リロードには対応していますが、これは他のリソースのためのものです。
root #
/etc/init.d/dnsmasq restart
hosts ファイル
dnsmasq アプリケーションは -h
(--no-hosts
) コマンドライン引数を渡されない限り、DNS サービスを提供するために /etc/hosts ファイルを情報源のひとつとして使用します。
/etc/hosts ファイルが更新されたら、dnsmasq サービスはその設定を再読み込みするために SIGHUP シグナルを受信する必要があります。これは init スクリプトの reload コマンドを通しても対応しています:
root #
/etc/init.d/dnsmasq reload
この挙動は設定ファイルで no-hosts
パラメータを利用して無効化することもできます。
追加の hosts ファイル
DNS クエリのための情報源として使用するために、(追加の) hosts ファイルを渡すこともできます。これを行うには、-H /path/to/hostsfile
(--addn-hosts=/path/to/hostsfile
) コマンドラインオプションを追加してください。ディレクトリを渡すこともでき、その場合はディレクトリ内のすべてのファイルが追加の hosts ファイルとして扱われるでしょう。
通常の hosts ファイルと同様に、SIGHUP シグナルでファイルを再読み込みします。
この挙動は設定ファイルで addn-hosts
パラメータを利用して設定することもできます。
上流のネームサーバ
dnsmasq はデフォルトでは、/etc/resolv.conf で指定されたネームサーバを上流のネームサーバとして利用します。
-r
(--resolv-file
) コマンドラインオプションを介して、異なるファイルを利用することもできます。
この挙動は設定ファイルで resolv-file
パラメータを利用して設定することもできます。
機能
dnsmasq は DNS、TFTP、PXE、ルータ広告と DHCP サービスに対応しています。そのため、小〜中規模のネットワークのための多目的なネットワーク管理ツールとなっています。
DNS サービス
In order to (only) provide DNS services, first identify the upstream nameserver to use. If this is the same nameserver as specified in /etc/resolv.conf then no additional steps need to be taken. Otherwise, point dnsmasq to the proper resolv.conf file through the -r
(--resolv-file
) command line. Its syntax is the one used by the /etc/resolv.conf file, although dnsmasq only looks at the nameserver definitions.
例えば:
root #
echo "nameserver 8.8.8.8" >> /etc/dnsmasq.conf.resolv
Next point dnsmasq to this file through the configuration file:
/etc/dnsmasq.conf
カスタム resolv ファイルの設定resolv-file=/etc/dnsmasq.conf.resolv
To verify that the service is running (after restarting as the configuration file has just been changed), use the dig command (provided through net-dns/bind-tools), asking the DNS server (running on localhost in the following example) to resolve a local or remote address:
user $
dig @localhost +short www.gentoo.org
www-bytemark-v4v6.gentoo.org. 89.16.167.134
DNSSEC
Dnsmasq can validate DNSSEC data while passing through data. This can be accomplished by adding these lines to the config file:
/etc/dnsmasq.conf
DNSSEC を有効にする# DNSSEC setup dnssec trust-anchor=.,19036,8,2,49AAC11D7B6F6446702E54A1607371607A1A41855200FD2CE1CDDE32F24E8FB5 trust-anchor=.,20326,8,2,E06D44B80B8F1D39A95C0B0D7C65D08458E880409BBC683457104237C7F8EC8D dnssec-check-unsigned
The trusted anchor can be found on the iana.org site. After this change dnsmasq will return SERVFAIL and no DNS data if the validation fails. If the validation succeeds it sets the ad flag. In case the domain does not support DNSSEC dnsmasq behaves as before.
DHCP サービス
In order to enable the DHCP services of dnsmasq, use the dhcp-range
configuration setting.
For instance, to enable IPv6 address configuration through router advertisement (RA) with infinite lease time, and IPv4 address configuration also with infinite lease time:
/etc/dnsmasq.conf
Enabling IPv6 and IPv4 leasesdhcp-range=2001:db8:81:e2::,ra-only,infinite dhcp-range=192.168.100.100,192.168.100.149,infinite
It is possible to use static definitions for known hosts, either through the main configuration file (dhcp-host=
settings) or through a separate file. If a separate file is used, point dnsmasq to it through the --dhcp-hostsfile
command line option. The advantage of the latter approach is that it is sufficient to send a SIGHUP signal (or reload the service) in order to reread the entries, whereas definitions in the configuration file require a full service restart.
For more information about the syntax of the dhcp-host
parameter please refer to the manual page or configuration file as its syntax is very extensive.
使い方
This section covers various usage scenarios (maintenance and operational tasks) for the dnsmasq service.
リースをリセットする
Clients that had a network interface update which results in a different MAC address might not get the intended IP address immediately. This is because the dnsmasq service has provided this IP address to the old MAC address, and will wait until the lease of this address has expired before re-assigning it.
The dnsmasq service stores its leases in /var/lib/misc/dnsmasq.leases. If the lease needs to be removed faster, shut down the dnsmasq service, remove the lease from the dnsmasq.leases file and start the service again.
root #
/etc/init.d/dnsmasq stop
root #
nano -w /var/lib/misc/dnsmasq.leases
root #
/etc/init.d/dnsmasq start
Reloading non-main configuration settings
Next to the dnsmasq.conf file, the dnsmasq service can use external definitions for the following services:
- DHCP host configuration entries (through
--dhcp-hostsfile
command line option) - DHCP options (through
--dhcp-optsfile
command line option)
When these files are modified, a SIGHUP signal has dnsmasq reload these configuration files.
The resolv.conf files are by default polled by dnsmasq; changes on these files are automatically picked up unless the
-n
(--no-poll
) command line option is set or the no-poll
configuration parameter is used.