2
0

More than 3 years have passed since last update.

Raspberry PiでDNS serverを立てる

Posted at

はじめに

Kuberentesを使用しているとIngress機能を使用して、名前したくなるので、
Raspberr Piを使用してDNSサーバーを立てたくなったので、構築する

DNSサーバー導入

Dnsmasqを使用して構築する
以下のコマンドで、インストールする

sudo apt install dnsmasq

インストール後/etc/dnsmasq.confがあるので有効状態を確認すると以下の通りになる。

$ cat /etc/dnsmasq.conf |grep -v "^#"|grep -v '^\s*$'
dhcp-mac=set:client_is_a_pi,B8:27:EB:*:*:*
dhcp-reply-delay=tag:client_is_a_pi,2

以下の通りに書き換える

#dhcp-mac=set:client_is_a_pi,B8:27:EB:*:*:*
#dhcp-reply-delay=tag:client_is_a_pi,2
domain-needed
bogus-priv
strict-order
local=/bookserver2.local/
server=8.8.8.8
server=8.8.4.4
domain=bookserver2.local
cache-size=15000

書き換え後、以下のコマンドを実行数

systemctl restart dnsmasq

後は、必要に応じてhostsファイルに追加する

/etc/hosts
127.0.0.1       localhost
::1             localhost ip6-localhost ip6-loopback
ff02::1         ip6-allnodes
ff02::2         ip6-allrouters

127.0.1.1               bookserver2
192.168.0.21    bookserver2 bookserver2.local

動作テスト

PCのIPアドレスでDNSを直接指定するか、ルーターのDNSの指定で、
サーバのIPを指定すれば、DNSを使用できる

dnsサーバー以外のPCでdigコマンドで動作確認できる

$ dig bookserver2

; <<>> DiG 9.16.1-Ubuntu <<>> bookserver2
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 44061
;; flags: qr rd ad; QUERY: 1, ANSWER: 2, AUTHORITY: 0, ADDITIONAL: 0
;; WARNING: recursion requested but not available

;; QUESTION SECTION:
;bookserver2.                   IN      A

;; ANSWER SECTION:
bookserver2.            0       IN      A       192.168.0.21
bookserver2.            0       IN      A       127.0.1.1

;; Query time: 10 msec
;; SERVER: 172.28.16.1#53(172.28.16.1)
;; WHEN: Thu May 27 21:19:21 JST 2021
;; MSG SIZE  rcvd: 72
2
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
0