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?

どこでも動くDebianサーバを手に入れよう!スマホからのWindows PC接続を改善する。

0
Last updated at Posted at 2026-01-19

1. はじめに

 前回の記事で、Windows PCに additional-name.local を名乗らせようと dns-sd コマンドを使用した訳ですが、Androidからの名前解決がまるで安定しませんでした。Linux PCの avahi-publish が安定しているだけに、何というか妙にくやしい。

 そこで今回は、Pythonの python-zeroconf ライブラリを試して…WindowsとAndroidの相性が悪すぎてどうにもならんかった。なので、力技で捻じ伏せることにします。

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

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

2. 具体的な方策

 スマホからは mdns-scan コマンドでサービス名までは見えるので、サービス名にIPアドレスを埋め込むという原始的な手段で強引に解決します。サービス名からIPアドレスを抽出して ~/.ssh/config を更新した後に、SSH接続を行います。

3. IPアドレスの埋め込み

 まずは、サービス名にIPアドレスを埋め込むための細工をします。QEMU起動スクリプトの該当箇所を以下で置き換えてください。

Linux Mint xed ~/qemu/debian-amd64/qemu-launcher.sh
#!/bin/bash
AVAHI_IP="$(ifconfig | grep -o '192\.168\.[0-9.]*' | head -n 1)"
AVAHI_SRV="Wraith Server($AVAHI_IP)"
avahi-publish -aR wraith-srv.local "$AVAHI_IP" &
avahi-publish -s "$AVAHI_SRV" _http._tcp 8080 --host=wraith-srv.local &

# ここでQEMUを起動

pkill avahi-publish
Windows PC notepad "C:/qemu/debian-amd64/qemu-launcher.ps1"
$avahiIP = (Get-NetIPAddress -IPAddress "192.168.*")[0].IPAddress
$avahiSrv = '"Wraith Server(' + $avahiIP + ')"'
$avahiArgs = @('-P', $avahiSrv, '_http._tcp', '.', '8080',
  'wraith-srv.local', $avahiIP)
$avahiProc = Start-Process dns-sd -ArgumentList $avahiArgs -PassThru

# ここでQEMUを起動

Stop-Process -Id $avahiProc.Id

4. Termuxのスクリプト

 .bashrc に、mdns-scan コマンドでサービス名を取得して ~/.ssh/config を更新するコードを仕込みます。sshd コマンドの直後に以下を挿入してください。

Termux SSH
pkg install mdns-scan
Termux SSH nano ~/.bashrc
  SSH_IP="$(timeout 5s mdns-scan 2>&1 | grep -m 1 'Wraith Server' |
    tee /dev/tty | grep -o '192\.168\.[0-9.]*')"
  if [ -n "$SSH_IP" ]; then
    sed -i '/ HostName /s/ [^ ]*$/ '"$SSH_IP"'/' ~/.ssh/config
  fi

5. おわりに

 mDNSに対応していないAndroid 10スマホでも、mDNSの名前解決が擬似的にできるようになりました。これは思わぬ副産物ですw


◀️ 前の記事 次の記事 ▶️
どこでも動くDebianサーバを手に入れよう!DHCPでも設定変更なしでスマホと連携する。 PCツナイデント(パラレル版)はES-DE + RetroArchでも問題なく使用できます。
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?