Goal
Almalinuxにて
Environment
- Almalinux 8.6 (Stone Smilodon)
- ndjbdns 1.06
- systemd 239 (239-68.el8_7.2)
ndjbdnsパッケージはdjbdnsの堅牢性を低下させる代わりにインストールを容易にしたもの。djbdnsとの互換性はある模様。 この記事ではndjbdnsパッケージを利用してDNSサーバを構築する。
補足だが、djbdnsは下記が含まれている。
1. Download ndjbdns from Web.
cd /usr/local/src wget "http://pjp.dgplug.org/ndjbdns/ndjbdns-1.06.tar.gz"
2. Install ndjbdns
インストール場所は/usr/local/src配下
tar zxvf ndjbdns-1.06.tar.gz cd ndjbdns-1.06 ./configure --prefix=/usr/local make install which tinydns # Output: /usr/local/sbin/tinydns which dnscache # Output: /usr/local/sbin/dnscache
GCCがない環境で./configure --prefix=/usr/local
をするとエラーがでる。
その場合は下記を実行。aptでいうbuild-essentialをインストール。
yum groupinstall "Development Tools" yum install kernel-devel kernel-headers # その後、./configure --prefix=/usr/local
3. Setting tinydns and dnscache
tinydnsとdnscacheは別のサービスと起動するがどちらもポート53を使用する。そのため、同じサーバ上で両方のサービスを動作させる場合、IPアドレスが2つ以上必要になる。 tinydnsとdnscacheが使用するIPアドレスは下記のファイルでそれぞれ指定できる。
- /usr/local/etc/ndjbdns/tinydns.conf
- /usr/local/etc/ndjbdns/dnscache.conf
cd /usr/local/src/ndjbdns-1.06 # 編集内容は下記を参照 vim /etc/init.d/tinydns.sh vim /etc/init.d/dnscache.sh vim /usr/local/etc/ndjbdns/tinydns.conf vim /usr/local/etc/ndjbdns/dnscache.conf
### BEGIN INIT INFO # Provides: tinydns # Required-Start: $network # Required-Stop: $network # Default-Stop: 0 1 2 3 4 5 6 # Short-Description: start and stop tinydns daemon at boot time. # Description: tinydns is a DNS server program. ### END INIT INFO # Source function library. . /etc/init.d/functions # Source networking configuration . /etc/sysconfig/network prog=PREFIX/sbin/tinydns config=/etc/ndjbdns/tinydns.conf -config=/etc/ndjbdns/tinydns.conf +config=/usr/local/etc/ndjbdns/tinydns.conf
### BEGIN INIT INFO # Provides: dnscache # Required-Start: $network # Required-Stop: $network # Default-Stop: 0 1 2 3 4 5 6 # Short-Description: start and stop dnscache daemon at boot time. # Description: dnscache is an iterative DNS resolver daemon. ### END INIT INFO # Source function library. . /etc/init.d/functions # Source networking configuration . /etc/sysconfig/network prog=PREFIX/sbin/dnscache -config=/etc/ndjbdns/dnscache.conf +config=/usr/local/etc/ndjbdns/dnscache.conf
# Address to listen on for incoming connections. It could be comma separated # list of IP addresses. # # IP=127.0.0.1[,x.x.x.x,...] -IP=127.0.0.1 +IP=Your IP Address 1 --- # ROOT: is the new root & working directory for tinydns. # Obviously, the user whose ID is mentioned above MUST be able to read from # this directory. # # Also, this is where `data' and `data.cdb' files should reside. -ROOT=PREFIX +ROOT=/usr/local/etc/ndjbdns
# Address to listen on for incoming connections. -IP=127.0.0.1 +IP=Your IP Address 2 --- # ROOT: is the new root & working directory for dnscache. # Obviously, the user whose ID is mentioned above MUST be able to read from # this directory. # # Also, this is where `ip/' and `servers/' directories should reside. -ROOT=PREFIX +ROOT=/usr/local/etc/ndjbdns
4. Enable starting tinydns and dnscache with Systemd
cd /usr/local/src/ndjbdns-1.06 cp ./etc/init.d/tinydns.sh /etc/init.d/ chmod u+x /etc/init.d/tinydns.sh cp ./etc/init.d/dnscache.sh /etc/init.d/ chmod u+x /etc/init.d/dnscache.sh systemctl start tinydns systemctl start dnscache systemctl enable tinydns systemctl enable dnscache
Almalinuxにおいて、sysVinitは内部的にはsystemdであったのでinit.dに登録することで、systemdで管理可能。 https://qiita.com/KEINOS/items/f3e6b3064b0cbe35fd03
djbdnsにはsystemd用のファイルも含まれているので、/etc/systemd/system/
に配置してもいいかもしれない。
${djbdnsフォルダ}/etc/systemd/tinydns.sysd
${djbdnsフォルダ}/etc/systemd/dnscache.sysd
Reference
https://qiita.com/metheglin/items/2c4f798eded252b2b61e https://blog.64p.org/entry/2013/07/22/142457
以上。