【Raspberry pi 3B】DNSサーバ構築

前回、小規模向けのWebアプリケーションフレームワークの「Flask(※1)」を用いて、ラズベリーパイにWebサーバを構築しました。
今回「dnsmasq」を用いて、ラズベリーパイにDNSサーバを構築していきます。
前々回のアクセスポイント構築時に「dnsmasq(※1)」をインストール及び設定をしているので、上書きで設定を行います。
※1:概要欄にリンクを張っています。



概要欄

【Raspberry pi 3B】Webサーバ構築
【Raspberry pi 3B】アクセスポイント構築

ソフトウェア

dnsmasq
「DNS Server / DHCP Server」の機能を構築できるOSS

構成図

デバイス情報

・ノートPC(OS: Windows11)
・Raspberry Pi 3 model B(OS: Raspberry pi OS)
 ※マイクロSD 128GB(32GBでも可)
・無線LANアダプタ(WN-G300UA)
・ルータ
・LANケーブル

DNSサーバ構築

DNS + FQDN 設定

◇ dnsmasq.conf ファイルを確認
ls -l /etc/dnsmasq.conf*

◇ バックアップ取得、確認
cp -p /etc/dnsmasq.conf /etc/dnsmasq.conf_`date "+%Y%m%d"_1`
ls -l /etc/dnsmasq.conf*

◇ dnsmasq.conf ファイルを編集
vim /etc/dnsmasq.conf

以下はコメントアウトを削除
-------------------------------------
ドット(.)やドメイン名のない名前解決は上位DNSに転送しない
# Never forward plain names (without a dot or domain part)
domain-needed

プライベートIPアドレスでの逆引きを上位DNSに転送しない
# Never forward addresses in the non-routed address spaces.
bogus-priv

domain= で指定されたドメインで補完
# 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=/testapwifi.com/

「expand-hosts」で指定するドメイン
# 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=thekelleys.org.uk
domain=testapwifi.com


◇ 差分チェック
diff /etc/dnsmasq.conf /etc/dnsmasq.conf_`date "+%Y%m%d_1"`

◇ hostsファイルを確認
ls -l /etc/hosts*

◇ バックアップ取得、確認
cp -p /etc/hosts /etc/hosts_`date "+%Y%m%d"`
ls -l /etc/hosts*

◇ ネットワークインターフェース状況の確認
※WebサーバのIPアドレスをメモする
ifconfig

◇ hostsファイルを編集
vim /etc/hosts
※末尾に記載

<テンプレート>
WebIPaddress FQDN

------------------------------------------

<例>
192.168.76.250  www.testapwifi.com testapwifi.com


◇ dnsmasq サービスを再読込み
systemctl reload dnsmasq
systemctl status dnsmasq

FQDNでサイトにアクセス

◇ 確認事項
・正引きができる
・アクセスポイントに付与されたIPアドレスになってる
・GETメソッドでブラウザからサイト閲覧できる

FQDN:www.testapwifi.com


FQDN:testapwifi.com