0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

【サーバ構築メモ】ローカルサーバでのmDNS活用方法

0
Last updated at Posted at 2026-02-16

1. はじめに

 ローカルネットワークでの小規模サーバ運用で冗長化を考えた際、mDNSでの名前解決を利用するとバックアップへの切り替えがスムーズにできるようになります。以前の記事に盛り込んだ内容ですが、単独の記事として切り出すことにします。

本記事では以下のOSで動作確認を行っています。

以前の記事はこちらです。

2. 運用のイメージ

 今回はサーバに以下の名前を付けて運用する手順を説明します。.local 以外の部分は環境に合わせて自由に改変してください。

項目 設定値
ホスト名 untied-srv.local
サービス名 Untied Server

 Gitサーバの場合は以下のようなURLで接続するイメージです。

URL
http://untied-srv.local/git/my-first-git
ssh://user@untied-srv.local/srv/git/my-first-git
user@untied-srv.local:/srv/git/my-first-git

3. mDNSの利用方法

3.1 Linux環境での利用方法

 一般的なLinux環境はこちらです。avahi-publish が使用できるので、迷わずこちらを選択しましょう。以下の一連のコマンドでサービスを開始できます。

Linux Mint
MDNS_HOST=untied-srv.local
MDNS_SRV="Untied Server"
MDNS_IP="$(ifconfig | grep -o '192\.168\.[0-9.]*' | head -n 1)"
nohup avahi-publish \
  -aR "$MDNS_HOST" "$MDNS_IP" > /dev/null 2>&1 &
nohup avahi-publish \
  -s "$MDNS_SRV" _http._tcp 80 --host="$MDNS_HOST" > /dev/null 2>&1 &

 サービスの稼働状況は以下のコマンドで確認できます。

Linux Mint
avahi-browse _http._tcp

 以下のコマンドを実行するとサービスを終了します。

Linux Mint
pkill -f "$MDNS_HOST"

3.2 Termux環境での利用方法

 Termux環境では avahi-daemon が動いていないためAvahi系のツールが使用できません。Pythonの zeroconf やGoの mdns ライブラリも試しましたが進展なし。Androidはアプリからのマルチキャスト通信を制限している模様。

 そこで、手近なLinux機に代理で avahi-publish してもらうことにします。SSH接続のセットアップは別途実施してください。

Termux SSH
MDNS_HOST=untied-srv.local
MDNS_SRV="Untied Server"
MDNS_IP="$(ifconfig | grep -o '192\.168\.[0-9.]*' | head -n 1)"
ssh agency-ssh "
  nohup avahi-publish \\
    -aR '$MDNS_HOST' '$MDNS_IP' > /dev/null 2>&1 &
  nohup avahi-publish \\
    -s '$MDNS_SRV' _http._tcp 80 --host='$MDNS_HOST' > /dev/null 2>&1 &"

 サービスの稼働状況は以下のコマンドで確認できます。

Termux SSH
pkg install mdns-scan
mdns-scan

 以下のコマンドを実行するとサービスを終了します。

Termux SSH
ssh agency-ssh "pkill -f '$MDNS_HOST'"

3.3 Windows環境での利用方法

 Windows環境では dns-sd コマンドを使用します。Bonjourが必要となりますので、以下からダウンロードしてインストールしてください。

Windows PC ダウンロード
Bonjour Print Services for Windows - https://support.apple.com/ja-jp/106380

 以下の一連のコマンドでサービスを開始します。

Windows PC
$mdnsHost = "untied-srv.local"
$mdnsSrv = "Untied Server"
$mdnsIP = (Get-NetIPAddress -IPAddress "192.168.*")[0].IPAddress
$mdnsArgs = @("-P", "`"$mdnsSrv`"", "_http._tcp", ".", "80", $mdnsHost, $mdnsIP)
$mdnsProc = Start-Process dns-sd -ArgumentList $mdnsArgs -PassThru

 サービスの稼働状況は以下のコマンドで確認できます。

Windows PC
dns-sd -B "_http._tcp" "."

 以下のコマンドを実行するとサービスを終了します。

Windows PC
Stop-Process -Id $mdnsProc.Id

4. おわりに

 以前の記事でのマウントもそうでしたが、非rootのAndroidスマホは制約がいくつもあって単体でのサーバ完結は現実的に難しいところ。限定された用途と運用なら使えないこともないのですが。次回は、力業でのmDNSの名前解決を予定しています。

◀️ 前の記事 次の記事 ▶️
【開発環境構築メモ】SQLもはじめました 【サーバ構築メモ】mDNSの名前解決を手動で行う方法
0
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
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?