Hatena::ブログ(Diary)

ytooyamaのチラシの裏(「の」の連続) このページをアンテナに追加 RSSフィード

 ※このサイトではトラッキングするはてなブックマークの「ソーシャルボタン」は
 設置していません。また今後もソーシャルボタンを設置する予定はありません。
(→詳細 / まとめ

 ■アクセスの多い記事リンク

  続・Flash Player 11.3以降で日本語入力できない、動画再生できなくなる件
  Debian 6.0.xをVirtualBox 4.1.xで動かす時のメモ
  「MacBookをSSD化してみた」シリーズまとめ
  iOS 6でバッテリーの節約

2014-06-22

dnsmasqで簡易的なDNSサーバーを構築

【14/10/3追記】

「dnsmasqで簡易的なDHCPサーバーを構築」はこちら

http://d.hatena.ne.jp/ytooyama/20141003/1412345557

LinuxDNSというとBINDがすぐに思い浮かびます。

DNSサーバーを構築する時の選択肢は、最近は色々増えてきましたが、家の環境で名前解決したいような小規模な用途程度でBINDを構築するのはちょっとばっかし気が重いですよね。

そこでWebで色々調べたところ、dnsmasqというものが用途としてあっているようでした。例えばCentOSFedoraなら次の手順で導入できます。

(以下、太字はコマンド)

■導入方法

# yum install dnsmasq

■設定方法

# vi /etc/dnsmasq.conf

# Listen on this specific port instead of the standard DNS port

# (53). Setting this to zero completely disables DNS function,

# leaving only DHCP and/or TFTP.

port=53 #コメントを外してポートを変更

# Never forward plain names (without a dot or domain part)

domain-needed #コメントを外す

# Never forward addresses in the non-routed address spaces.

bogus-priv #コメントを外す

# Set this (and domain: see below) if you want to have a domain

# automatically added to simple names in a hosts-file.

expand-hosts #コメントを外す

# Add local-only domains here, queries in these domains are answered

# from /etc/hosts or DHCP only.

#local=/localnet/

local=/local.tooyama.org/

(shorthostnameで補完するドメインを記述)

# Set the domain for dnsmasq. this is optional, but if it is set, it

# does the following things.

# 1) Allows DHCP hosts to have fully qualified domain names, as long

# as the domain part matches this setting.

# 2) Sets the "domain" DHCP option thereby potentially setting the

# domain of all systems configured by DHCP

# 3) Provides the domain part for "expand-hosts"

domain=local.tooyama.org

(shorthostnameで補完するドメインを記述)

# vi /etc/hosts

DNSサーバーとするhostsファイルを編集)

127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4

::1 localhost localhost.localdomain localhost6 localhost6.localdomain6

192.168.1.3 www2.local.tooyama.org www2

192.168.1.3 ntp2.local.tooyama.org ntp2

192.168.1.6 www.local.tooyama.org www

(名前解決したいエントリを記述)

# systemctl restart dnsmasq

(dnsmasqサービスを再起動..CentOSの場合はserviceコマンドを使う)

# systemctl enable dnsmasq

(dnsmasqサービスを自動起動..CentOSの場合はchkconfigコマンドを使う)

ファイアウォール

ポート53を解放します。

ファイアウォールの設定はCentOSの場合はiptablesを直接いじるか、system-config-firewallコマンドで設定します。Fedoraの場合はfirewall-cmdで設定します。

# firewall-cmd --add-port=53/tcp

# firewall-cmd --add-port=53/udp

# firewall-cmd --permanent --add-port=53/tcp

# firewall-cmd --permanent --add-port=53/udp

ファイアウォールコマンドでポート開放)

これだけです。あとはクライアントDNSの設定を構築したサーバーに設定すれば、簡易DNSサーバーの完成です。

■名前解決したいエントリーを追加する

名前解決したいエントリーを追加するには、dnsmasqの/etc/hostsに記述していきます。追加した内容を反映させるには、dnsmasqサービスを再起動するだけです。本当に簡単ですね。

■使用例

$ ping -c 1 www2.local.tooyama.org

PING www2.local.tooyama.org (192.168.1.3): 56 data bytes

64 bytes from 192.168.1.3: icmp_seq=0 ttl=64 time=0.297 ms

--- www2.local.tooyama.org ping statistics ---

1 packets transmitted, 1 packets received, 0.0% packet loss

round-trip min/avg/max/stddev = 0.297/0.297/0.297/0.000 ms

DHCPもたてたい

まだ実際に試していないけど、dnsmasqでできるらしいです。

【参考にしたサイト】

投稿したコメントは管理者が承認するまで公開されません。

スパム対策のためのダミーです。もし見えても何も入力しないでください
ゲスト


画像認証

リンク元