dnsmasqでDHCP・DNSサーバを立てて移行した手順まとめ
きっかけ
現在の環境
市販用ルータ(BBR-4MG)上でDHCPサーバが動いてる状態。
こいつをオフにしてDHCPサーバとついでにDNSサーバもでっちあげる。
とりあえず便宜上ホスト名はhogeでIPは192.168.0.10とする。
DHCPをインストールするサーバはDebian squeeze。
手順
dnsmasqのインストール
$ sudo apt-get install dnsmasq
でいけるはず。
dnsmasqの設定
以下は設定例です。実際の設定とは違っています。
- DHCPで192.168.0.50-70を動的に割り当てる
- dhcp-host=... でMACアドレス*2、IPアドレス、ホスト名を指定
- NTP
- /etc/ntp.confを書き換えてくれるらしいけどまだ確認してない
--- /etc/dnsmasq.conf.bak 2012-02-26 11:44:47.403911388 +0900 +++ /etc/dnsmasq.conf 2012-02-26 12:14:20.908510981 +0900 @@ -140,6 +140,7 @@ # agent. If you don't know what a DHCP relay agent is, you probably # don't need to worry about this. #dhcp-range=192.168.0.50,192.168.0.150,255.255.255.0,12h +dhcp-range=192.168.0.50,192.168.0.70,255.255.255.0,12h # This is an example of a DHCP range which sets a tag, so that # some DHCP options may be set only for this network. @@ -163,6 +164,28 @@ # need to be on the same network. The order of the parameters in these # do not matter, it's permissble to give name,adddress and MAC in any order +dhcp-host=de:ad:be:ef:co:ff,hoge,192.168.0.10,infinite +dhcp-host=ee:vi:mi:st:he:be,fuga,192.168.0.11,infinite +dhcp-host=st:te:xt:ed:it:or,piyo,192.168.0.12,infinite + + # Always allocate the host with ethernet address 11:22:33:44:55:66 # The IP address 192.168.0.60 #dhcp-host=11:22:33:44:55:66,192.168.0.60 @@ -253,12 +276,16 @@ # are some options which are recommended, they are detailed at the # end of this section. +# DNS server +dhcp-option=option:dns-server,192.168.0.10,192.168.0.1 + # Override the default route supplied by dnsmasq, which assumes the # router is the same machine as the one running dnsmasq. #dhcp-option=3,1.2.3.4 # Do the same thing, but using the option name #dhcp-option=option:router,1.2.3.4 +dhcp-option=option:router,192.168.0.1 # Override the default route supplied by dnsmasq and send no default # route at all. Note that this only works for the options sent by @@ -268,6 +295,10 @@ # Set the NTP time server addresses to 192.168.0.4 and 10.10.0.5 #dhcp-option=option:ntp-server,192.168.0.4,10.10.0.5 +# +#ntp.nict.jp. 3600 IN A 133.243.238.163 +#ntp.ring.gr.jp. 1610 IN A 133.243.237.36 +dhcp-option=option:ntp-server,133.243.238.163,133.243.237.36 # Set the NTP time server address to be the same machine as # is running dnsmasq @@ -447,6 +478,7 @@ # Set the cachesize here. #cache-size=150 +cache-size=0 # If you want to disable negative caching, uncomment this. #no-negcache
DHCPサーバ自身に静的IPを割り振る
同じくDHCPサーバは自分自身のIPは管理できない(要出典)。
DHCPサーバ(dnsmasq)を立ち上げるにはIPを取得して通信できる状態でないとダメ(のような気がする(未検証))なのでDHCPサーバ自身は静的IPにする必要がある。ツッコミ待ち。
なので/etc/network/interfacesに以下の設定を書く。
auto eth0 iface eth0 inet static address 192.168.0.10 network 192.168.0.0 netmask 255.255.255.0 broadcast 192.168.0.255 gateway 192.168.0.1
自分はLXCを動かしたりしていてbridgeを使ってるので以下の設定を書いた(キリッ
ごめんなさいbridgeよくわかってません。ツッコミ待ち。
auto br0 iface br0 inet static bridge_ports eth0 bridge_fd 0 bridge_maxwait 0 address 192.168.0.10 network 192.168.0.0 netmask 255.255.255.0 broadcast 192.168.0.255 gateway 192.168.0.1
bridge_ports, bridge_fd, bridge_maxwait以外は同じですね。
自身を/etc/hostsに載せる
hypervisorのみなぜか引けなかったので/etc/hostsに追加。
# for dnsmasq: # * Do not distribute 127.0.0.1 as hypervisor. # * Distribute hypervisor's IP and hostname # because only hypervisor can't be looked up...(why?) #127.0.0.1 localhost hypervisor 127.0.0.1 localhost 192.168.0.10 hypervisor
ルータ(BBR-4MG)のDHCP機能をオフる
dnsmasqを起動
$ sudo service dnsmasq start
移行完了
ごめんなさい、途中順序微妙に入れ替わってる部分とかあるので正直ステップ通りに行くか自信が(ry
まぁおおむねうまくいくんじゃないでしょうか。
うまくいかなかったらコメント欄で言ってください。
でも罵倒されるとあまりのショックにEmacs使うかもしれないので優しく指摘してくれればうれしいです。