Windowsでは名前解決したアドレスはローカルキャッシュに残っているが、
Linuxではローカルキャッシュに残って無いので場合によっては、
名前解決の処理やネットワークの負荷を軽減する為にLinuxでも利用した方が良い場合がある。
但し、便利な反面ローカルにキャッシュが残っている事を認識してないと問題解決に
時間がかかる場合があるので、運用者は常に認識しておいた方が良いかと。

DNSMASQのインストール

[root@HOME001 htop-0.8.3]# yum install dnsmasq
Loaded plugins: fastestmirror, security
Loading mirror speeds from cached hostfile
 * base: ftp.iij.ad.jp
 * extras: ftp.iij.ad.jp
 * updates: ftp.iij.ad.jp
Setting up Install Process
Resolving Dependencies
--> Running transaction check
---> Package dnsmasq.i686 0:2.48-6.el6 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

========================================================================================================================================================================
 Package                                  Arch                                  Version                                     Repository                             Size
========================================================================================================================================================================
Installing:
 dnsmasq                                  i686                                  2.48-6.el6                                  base                                  144 k

Transaction Summary
========================================================================================================================================================================
Install       1 Package(s)

Total download size: 144 k
Installed size: 281 k
Is this ok [y/N]: y
Downloading Packages:
dnsmasq-2.48-6.el6.i686.rpm                                                                                                                      | 144 kB     00:00
Running rpm_check_debug
Running Transaction Test
Transaction Test Succeeded
Running Transaction
  Installing : dnsmasq-2.48-6.el6.i686                                                                                                                              1/1
  Verifying  : dnsmasq-2.48-6.el6.i686                                                                                                                              1/1

Installed:
  dnsmasq.i686 0:2.48-6.el6

Complete!
[root@HOME001 htop-0.8.3]# /sbin/chkconfig --list dnsmasq
dnsmasq         0:off   1:off   2:off   3:off   4:off   5:off   6:off
[root@HOME001 htop-0.8.3]#

自動起動する場合は、chkconfigにて自動起動設定して下さい。

ローカルからDNSを利用出来るように設定ファイルの編集
/etc/dnsmasq.conf

 [root@HOME001 htop-0.8.3]# cat /etc/dnsmasq.conf | grep "127.0.0.1" | egrep -i -v ^#
 listen-address=127.0.0.1
 [root@HOME001 htop-0.8.3]#

1

/etc/resolv.conf

 [root@HOME001 htop-0.8.3]# cat /etc/resolv.conf | grep "127.0.0.1" | egrep -i -v ^#
 nameserver 127.0.0.1
 [root@HOME001 htop-0.8.3]#

resolv

サービスの再起動

[root@HOME001 htop-0.8.3]# /etc/init.d/dnsmasq restart
Shutting down dnsmasq:                                     [  OK  ]
Starting dnsmasq:                                          [  OK  ]
[root@HOME001 htop-0.8.3]# 

dnsmasq

ローカルで名前解決が出来るか確認

[root@HOME001 htop-0.8.3]# dig @127.0.0.1 kakaku.com

; <<>> DiG 9.8.2rc1-RedHat-9.8.2-0.10.rc1.el6 <<>> @127.0.0.1 kakaku.com
; (1 server found)
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 37234
;; flags: qr rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 0

;; QUESTION SECTION:
;kakaku.com.                    IN      A

;; ANSWER SECTION:
kakaku.com.             411     IN      A       210.129.151.129

;; Query time: 9 msec
;; SERVER: 127.0.0.1#53(127.0.0.1)
;; WHEN: Sun Dec 30 13:53:28 2012
;; MSG SIZE  rcvd: 44

&#91;root@HOME001 htop-0.8.3&#93;# 
&#91;/SHELL&#93;

<a href="http://variable.jp/2012/12/30/linux%e3%81%ab%e3%81%8a%e3%81%91%e3%82%8bdns-cache/dig/" rel="attachment wp-att-2450"><img src="http://variable.jp/wp-content/uploads/2012/12/dig.jpg" alt="dig" width="624" height="351" /></a>

<a href="http://variable.jp/2012/12/30/linux%e3%81%ab%e3%81%8a%e3%81%91%e3%82%8bdns-cache/dig-grep/" rel="attachment wp-att-2452"><img src="http://variable.jp/wp-content/uploads/2012/12/dig-grep.jpg" alt="dig-grep" width="442" height="80" /></a>

<strong>ローカルキャッシュのリフレッシュ</strong>
[SHELL]
[root@HOME001 htop-0.8.3]# /etc/init.d/dnsmasq force-reload
Shutting down dnsmasq:                                     [  OK  ]
Starting dnsmasq:                                          [  OK  ]
[root@HOME001 htop-0.8.3]#

force-reload

参考

Dnsmasq

いろいろなキャッシュ:dnsmasq, cache proxy

dnsmasqで簡易DNSサーバ

Comments are closed.

Post Navigation