1
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

Ubuntu20 on RasPi 3B を使って内部向けDNSを用意した

Last updated at Posted at 2020-07-03

Ubuntu 20.04 LTSをインストールしたRasPi 3Bを使って内部向けDNSを用意した.

自分用の備忘録として,簡単に記述します.

実現したいこと

以下の内部向けDNS環境を構築する.

ドメイン

Domain name Network address
home.rkarsnk.jp 192.168.100.0/24

DNSサーバ

Name server IP address
raspi3.home.rkarsnk.jp 192.168.100.3

名前解決したいホスト

Host name IP address
router.home.rkarsnk.jp 192.168.100.1
raspi3.home.rkarnsk.jp 192.168.100.3

CNAMEレコード

Canonical name Host name
www.home.rkarsnk.jp raspi3.home.rkarsnk.jp

dnsmasqの導入

aptを使ってdnsmasqをインストールする.

sudo apt install dnsmasq

設定ファイル

/etc/dnsmasq.conf
port=53
domain-needed
# プライベートIPの逆引きを上位DNSに転送しない
bogus-priv

# ①上位の名前解決をするネームサーバを指定する(resolv.dnsmasq.conf).
resolv-file=/etc/dnsmasq.d/resolvconf/resolv.dnsmasq.conf

strict-order

# ゾーン設定
server=/home.rkarsnk.jp/192.168.100.3
server=/100.168.192.in-addr.arpa/192.168.100.3

#ローカルドメイン設定
local=/home.rkarsnk.jp/

# ②名前解決をするホストを指定する(hosts.dnsmasq).
addn-hosts=/etc/dnsmasq.d/data/hosts.dnsmasq

# ホスト名で問い合わせたとき,指定されたドメインで補完
expand-hosts
domain=home.rkarsnk.jp

# CNAMEレコードの設定
cname=www.home.rkarsnk.jp,raspi3.home.rkarsnk.jp

①,②を指定しない場合,システムの/etc/{resolv.conf,hosts}が参照される.

/etc/dnsmasq.d/resolvconf/resolv.dnsmasq.conf
8.8.8.8
8.8.4.4

ここでは,上位の名前解決にはGoogle Public DNSを利用する.

/etc/dnsmasq.d/data/hosts.dnsmasq
router.home.rkarsnk.jp        192.168.100.1
raspi3.home.rkarsnk.jp        192.168.100.3

サービスの起動

% sudo systemctl start dnsmasq.service

確認

# digで確認
% dig raspi3 @192.168.100.3
; <<>> DiG 9.10.6 <<>> raspi3 @192.168.100.3
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 38381
;; flags: qr aa rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 1

;; OPT PSEUDOSECTION:
; EDNS: version: 0, flags:; udp: 4096
;; QUESTION SECTION:
;raspi3.				IN	A

;; ANSWER SECTION:
raspi3.			0	IN	A	192.168.100.3

;; Query time: 1 msec
;; SERVER: 192.168.100.3#53(192.168.100.3)
;; WHEN: Fri Jul 03 13:37:50 JST 2020
;; MSG SIZE  rcvd: 51

# hostで確認
% host raspi3
raspi3.home.rkarsnk.jp has address 192.168.100.3

# CNAME設定の確認
% host www
www.home.rkarsnk.jp is an alias for raspi3.home.rkarsnk.jp.
raspi3.home.rkarsnk.jp has address 192.168.100.3

# 上位の名前解決が正常に動作するか確認
% host www.yahoo.co.jp
host www.yahoo.co.jp
www.yahoo.co.jp is an alias for edge12.g.yimg.jp.
edge12.g.yimg.jp has address 183.79.250.251
1
3
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
1
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?