NetAppのcluster ONTAP8.x/ONTAP9はNISを使える、と書いてあるものの、詳細を確認すると、NISホスト名は使用できず、NISユーザとパスワード、NISグループ、NIS netgroup(ホスト名用のグループ)しか使えないとのこと。
NIS netgroup対応といっても、netgroupに含まれるホスト名にNIS ホスト名が許されるわけではなく、DNS起因のホスト名の使用が許される、というものでした。(ONTAPシミュレータで確認)
既存のDNSサーバにエントリを追加してもらえれば解決ではありますが、できるかどうかわからないので、お手軽にできる回避策として、RHEL6/RHEL7などの標準パッケージ群に含まれているdnsmasqを使用した簡易DNSサーバを立ててみることにした。
dnsmasqは/etc/hostsもしくはhostsフォーマットに準じたファイルを指定して、そこのエントリを元にDNS応答を返すことができる。
NISホスト名を「ypcat hosts」で一括出力するとhostsフォーマットでエントリが取得できるので、crontabで定期的に「ypcat hosts」を実行して情報更新を行い、dnsmasqでDNSで応答を返せるようにした。
まずは、DNSサーバのインストール。
1 | [root@nisclient ~]# yum install dnsmasq |
2 | 読み込んだプラグイン:fastestmirror |
4 | Loading mirror speeds from cached hostfile |
5 | * base: ftp.nara.wide.ad.jp |
6 | * extras: ftp.nara.wide.ad.jp |
7 | * updates: ftp.nara.wide.ad.jp |
9 | --> トランザクションの確認を実行しています。 |
10 | ---> Package dnsmasq.x86_64 0:2.48-18.el6_9 will be インストール |
15 | ================================================================================ |
16 | パッケージ アーキテクチャ バージョン リポジトリー 容量 |
17 | ================================================================================ |
19 | dnsmasq x86_64 2.48-18.el6_9 base 150 k |
22 | ================================================================================ |
29 | dnsmasq-2.48-18.el6_9.x86_64.rpm | 150 kB 00:00 |
30 | rpm_check_debug を実行しています |
34 | インストールしています : dnsmasq-2.48-18.el6_9.x86_64 1/1 |
35 | Verifying : dnsmasq-2.48-18.el6_9.x86_64 1/1 |
38 | dnsmasq.x86_64 0:2.48-18.el6_9 |
/etc に配置された設定ファイルを確認。
1 | [root@nisclient ~]# ls -l /etc/dnsmasq.* |
2 | -rw-r--r--. 1 root root 21214 10月 3 08:18 2017 /etc/dnsmasq.conf |
NISで配布されたhostsを/etc/hosts-from-nisに保存するということにして、/etc/hosts は使用しない、ということにして、/etc/dnsmasq.conf の以下を変更
2 | # If you don't want dnsmasq to read /etc/hosts, uncomment the |
5 | # or if you want it to read another file, as well as /etc/hosts, use |
7 | #addn-hosts=/etc/banner_add_hosts |
2 | # If you don't want dnsmasq to read /etc/hosts, uncomment the |
5 | # or if you want it to read another file, as well as /etc/hosts, use |
7 | addn-hosts=/etc/hosts-from-nis |
上記以外のエントリは標準設定のままです。NISから配布されたhostsを/etc/hosts-from-nisに保存
1 | [root@nisclient ~]# ypcat hosts > /etc/hosts-from-nis |
2 | [root@nisclient ~]# cat /etc/hosts-from-nis |
3 | 127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4 |
4 | 127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4 |
5 | 127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4 |
6 | 127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4 |
8 | 172.17.44.49 server49 server49.vm2.example.com |
9 | 172.17.44.49 server49 server49.vm2.example.com |
続いてfirewalld/iptablesの設定変更して、ポート53のtcp/udpを許可。
1 | [root@nisclient ~]# cat /etc/sysconfig/iptables |
2 | # Firewall configuration written by system-config-firewall |
3 | # Manual customization of this file is not recommended. |
8 | -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT |
9 | -A INPUT -p icmp -j ACCEPT |
10 | -A INPUT -i lo -j ACCEPT |
11 | -A INPUT -m state --state NEW -m tcp -p tcp --dport 22 -j ACCEPT |
12 | -A INPUT -m state --state NEW -m tcp -p tcp --dport 53 -j ACCEPT |
13 | -A INPUT -m state --state NEW -m udp -p udp --dport 53 -j ACCEPT |
14 | -A INPUT -j REJECT --reject-with icmp-host-prohibited |
15 | -A FORWARD -j REJECT --reject-with icmp-host-prohibited |
17 | [root@nisclient ~]# service iptables restart |
18 | iptables: チェインをポリシー ACCEPT へ設定中filter [ OK ] |
19 | iptables: ファイアウォールルールを消去中: [ OK ] |
20 | iptables: モジュールを取り外し中: [ OK ] |
21 | iptables: ファイアウォールルールを適用中: [ OK ] |
firewalldの場合は以下
1 | -bash-4.2# firewall-cmd --list-all |
4 | icmp-block-inversion: no |
7 | services: dhcpv6-client ssh |
16 | -bash-4.2# firewall-cmd --permanent --zone=public --add-service=dns |
18 | -bash-4.2# firewall-cmd --reload |
20 | -bash-4.2# firewall-cmd --list-all |
23 | icmp-block-inversion: no |
26 | services: dhcpv6-client dns ssh |
で、dnsmasqを起動して、DNSにより名前解決ができるか確認してみます。
1 | [root@nisclient ~]# service dnsmasq status |
3 | [root@nisclient ~]# service dnsmasq start |
4 | Starting dnsmasq: [ OK ] |
5 | [root@nisclient ~]# service dnsmasq status |
6 | dnsmasq (pid 1556) を実行中... |
9 | [root@nisclient ~]# nslookup nfstest 127.0.0.1 |