1
2

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 1 year has passed since last update.

ローカルメール環境構築(その1:DNSサーバー)

1
Posted at

ローカルメール環境構築:その1

SMTPサーバー、POPサーバー、DNSサーバーを設けて、ローカルメール環境を構築する。長くなるので3部作とした。

  1. DNSサーバー(dnsmasq)
  2. POPサーバー(dovecot)
  3. SMTPサーバー(postfix)+まとめ

利用するリソースとしては、軽量かつ容易にインストールできるものを選択(上記)。今回はDNSサーバーについて記載。

ネットワーク構成図

実機およびVM環境の数も限られていたため、下記のような構成とした。

構成図.png

  • 192.168.2.249: DNSサーバー(今回のお題)およびメールクライアントuser4@annecy2dc.com
  • 192.168.2.2: メールサーバーannecy2dc.com
  • 192.168.2.251: メールサーバーannecy1dc.com
  • 192.168.2.239: メールクライアントuser1@annecy1dc.com

dnsmasqによるDNSサーバー構築

インストール

$ sudo apt install dnsmasq

これだけで、dnsmasqが自動的に起動する。

ps ax

 1517 ?        S      0:00 /usr/sbin/dnsmasq -x /run/dnsmasq/dnsmasq.pid -u dnsmasq -r /run/dnsmasq/resolv.conf -7 /etc/dnsmasq.d,.dpkg-dist,.dpkg-old,.dpkg-new --local-service

用いたDistributionには、nslookupがインストールされていなかったため、下記も実施。

$ sudo apt-get install dnsutils

設定ファイル

メールサーバーのIPアドレスを登録。

/etc/hosts
192.168.2.2		mail.annecy2dc.com
192.168.2.251	mail.annecy1dc.com

MXレコードの登録。

/etc/dnsmasq.conf

mx-host=annecy1dc.com,mail.annecy1dc.com,10
mx-host=annecy2dc.com,mail.annecy2dc.com,10

ドメイン”annecy1dc.com”へのメールは、”mail.annecy1dc.com”へ転送する。もう一つのドメインも同様。”dnsmasq.conf”に設定する内容は、基本的にこれだけである。

検証

準備

事情があり、メールサーバーでのDNSサーバーのデフォルトは、今回用いるDNSサーバーとはなっていない。そこで、下記コマンドにより、一時的にDNSサーバーを変更する。

$ sudo resolvectl dns enp3s0f0 192.168.2.249

”enp3s0f0”はDNSサーバーを変更するネットワークインターフェース、”192.168.2.249”はDNSサーバーアドレスである。”resolvectl”により、ネットワークインターフェース”enp3s0f0”のDNS設定が変更されていることがわかる。

undeux3@aspero:~$ resolvectl
Global
         Protocols: -LLMNR -mDNS -DNSOverTLS DNSSEC=no/unsupported
  resolv.conf mode: stub

Link 2 (enp3s0f0)
    Current Scopes: DNS
         Protocols: +DefaultRoute -LLMNR -mDNS -DNSOverTLS DNSSEC=no/unsupported
Current DNS Server: 192.168.2.249
       DNS Servers: 192.168.2.249

Link 3 (wlp2s0)
    Current Scopes: DNS
         Protocols: +DefaultRoute -LLMNR -mDNS -DNSOverTLS DNSSEC=no/unsupported
Current DNS Server: 192.168.10.1
       DNS Servers: 192.168.10.1 yyyy:xxxx:yyyy:yyyy:xxxx:xxxx:fe92:9d52
        DNS Domain: flets-east.jp iptvf.jp

動作確認

MXレコード

nslookupを用いて確認。

$ nslookup -type=mx annecy1dc.com
Server:		127.0.0.53
Address:	127.0.0.53#53

Non-authoritative answer:
annecy1dc.com	mail exchanger = 10 mail.annecy1dc.com.

Authoritative answers can be found from:
mail.annecy1dc.com	internet address = 192.168.2.251

メールドメイン”annecy1dc.com”のホストが”mail.annecy1dc.com”、そのIPアドレスが”192.168.2.251”であることがわかる。Wiresharkで取得したデータは下記。

DNSのコピー.png

取得データはnslookupコマンドの結果に反映されている。もう一つのメールドメイン結果も掲載。

$ nslookup -type=mx annecy2dc.com
Server:		127.0.0.53
Address:	127.0.0.53#53

Non-authoritative answer:
annecy2dc.com	mail exchanger = 10 mail.annecy2dc.com.

Authoritative answers can be found from:
mail.annecy2dc.com	internet address = 192.168.2.2

Aレコード

上記のように、MXレコード確認時にAレコードも同時に取得していたので、nslookupであえて確認する必要はなくなった。よって、これにて、設定完了。

MXレコード設定をもう少々

ついでに深掘実施。DNSサーバーが動作しているホストでの動作確認である。まずはホスト名情報。

$ hostname
antix1
$ cat /etc/hostname
antix1

ホスト名は”antix1”である。”/etc/hosts”は下記の状態。

/etc/hosts
127.0.0.1	antix1

192.168.2.239	busterdog
192.168.2.249	antix

以降、dnsmasq.confの設定により、MXレコードの問い合わせ結果を確認する。

selfmx

# Return an MX record pointing to itself for all local machines.
selfmx

”/etc/hosts”に登録されているホストをMXレコードとして登録。結果は下記となる。

$ nslookup -type=mx busterdog
Server:		::1
Address:	::1#53

busterdog	mail exchanger = 1 busterdog.

$ nslookup -type=mx antix
Server:		::1
Address:	::1#53

antix	mail exchanger = 1 antix.

$ nslookup -type=mx antix1
Server:		::1
Address:	::1#53

antix1	mail exchanger = 1 antix1.

MXレコード=Aレコード、となっている。

localmxのみ

# Return an MX record pointing to the mx-target for all local
# machines.
localmx

通常、”mx-target”とともに使うようであるが、まずは、”localmx”単独での結果。

$ nslookup -type=mx busterdog
Server:		::1
Address:	::1#53

busterdog	mail exchanger = 1 antix1.

$ nslookup -type=mx antix
Server:		::1
Address:	::1#53

antix	mail exchanger = 1 antix1.

undeux3@antix1:/etc
$ nslookup -type=mx antix1
Server:		::1
Address:	::1#53

antix1	mail exchanger = 0 antix1.

”mx-target”が定義されていないと、すべてホスト名”antix1”を指すようだ。

mx-target+localmx

# Set the default target for MX records created using the localmx option.
mx-target=lyondc822.com

# Return an MX record pointing to the mx-target for all local
# machines.
localmx
$ nslookup -type=mx busterdog
Server:		::1
Address:	::1#53

busterdog	mail exchanger = 1 lyondc822.com.

$ nslookup -type=mx antix
Server:		::1
Address:	::1#53

antix	mail exchanger = 1 lyondc822.com.

$ nslookup -type=mx antix1
Server:		::1
Address:	::1#53

antix1	mail exchanger = 0 lyondc822.com.

すべて、mx-targetに設定した”lyondc822.com”を返す。

おまけ

今回、DNSサーバーを動作させたantiXというLinux Distributionでは、小生にはあまり馴染みのないConnmanというネットワークマネージャーが動作している。サーバーなので、固定IPアドレス設定がベター、そこで、旧式での設定方式を実施。

$ sudo service connman stop
$ sudo update-rc.d connman remove

上記により、Connmanを無効化し、下記を記載。

/etc/network/interfaces

iface eth0 inet static
  address 192.168.2.249
  netmask 255.255.255.0
  gateway 192.168.2.1

EOF

1
2
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
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?