RaspberryPiにBonjourをインストールしてみる

RaspberryPiにBonjourをインストールしてみる

前々から気にはなっていたんですが、別途ソフトのインストールが必要だったので尻込みしていたのですが、Windows10の最近のビルドではデフォルトでBonjourに対応している様です。そこで固定IP以外で、名前でもホスト指定できるようにしようと思います。

以下のブログを参考にさせていただきました。(実質、Windows10側は何も設定しなくても大丈夫でした)

moguno.hatenablog.jp

virtnote.blogspot.jp

Windows10側の設定の確認

Windows10はBonjourは対応しているのですが、ファイアウォールの設定でアクセスできないこともあるので内容の確認をしておきます。

【コントロールパネル】を開き、

f:id:ueponx:20170820142033p:plain

その中の【システムとセキュリティ】をクリックし、

f:id:ueponx:20170820142646p:plain

更に【WindowsDefenderファイアウォール】をクリックします。

f:id:ueponx:20170820143341p:plain

ウインドウの左側のペインから【詳細設定】をクリックします。

f:id:ueponx:20170820143515p:plain

クリック後に表示されるファイアウォール設定のウインドウの左側のペインから【受信の規則】を選択すると、

f:id:ueponx:20170820144154p:plain

中にBonjourの設定があるのがわかると思います。 Bounjourの設定が複数ありますが、TCPUDPなどの細かい設定の違いがあるようです。 複数あるなかに以下のような設定のあるものがあれば問題はなさそうです。

f:id:ueponx:20170820152314p:plain

  • プロトコルの種類:UDP
  • ローカルポート:全てのポート
  • リモートポート:全てのポート

ポートは5353に制限してもいいかなとは思いますが今回はそのままにしています。

RaspberryPi側の設定

Windows側の設定が確認できたので次はRaspberryPiの設定になります。設定するのはBonjourではありますが、パッケージ名はavahi-deamonとなります。 Avahi はBonjourのZeroconf仕様の実装とのことです。

参考:Avahi - Wikipedia

インストールは以下でOKです。

$ sudo apt-get install avahi-daemon
パッケージリストを読み込んでいます... 完了
依存関係ツリーを作成しています
状態情報を読み取っています... 完了
avahi-daemon はすでに最新バージョン (0.6.32-2) です。
アップグレード: 0 個、新規インストール: 0 個、削除: 0 個、保留: 2 個。

既に最新版がインストールされていました。調べてみるとRasbian jessie以降にはデフォルトでインストールされているようです。

動作確認

これでhostnameをつかってpingSSHなどを行うことができます。

RaspberryPi上からの自ホストへのping

$ ping raspberrypi.local
PING raspberrypi.local (192.168.0.8) 56(84) bytes of data.
64 bytes from 192.168.0.8 (192.168.0.8): icmp_seq=1 ttl=64 time=0.109 ms
64 bytes from 192.168.0.8 (192.168.0.8): icmp_seq=2 ttl=64 time=0.102 ms
64 bytes from 192.168.0.8 (192.168.0.8): icmp_seq=3 ttl=64 time=0.099 ms
64 bytes from 192.168.0.8 (192.168.0.8): icmp_seq=4 ttl=64 time=0.096 ms
64 bytes from 192.168.0.8 (192.168.0.8): icmp_seq=5 ttl=64 time=0.098 ms
64 bytes from 192.168.0.8 (192.168.0.8): icmp_seq=6 ttl=64 time=0.092 ms
64 bytes from 192.168.0.8 (192.168.0.8): icmp_seq=7 ttl=64 time=0.095 ms
^C
--- raspberrypi.local ping statistics ---
7 packets transmitted, 7 received, 0% packet loss, time 6231ms
rtt min/avg/max/mdev = 0.092/0.098/0.109/0.012 ms

RaspberryPi上からのWindows10へのping

Windows10側のホストネームはUindows10にしています。

$ ping UINDOWS10.local
PING UINDOWS10.local (192.168.0.5) 56(84) bytes of data.
64 bytes from 192.168.0.5 (192.168.0.5): icmp_seq=1 ttl=128 time=1.67 ms
64 bytes from 192.168.0.5 (192.168.0.5): icmp_seq=2 ttl=128 time=1.61 ms
64 bytes from 192.168.0.5 (192.168.0.5): icmp_seq=3 ttl=128 time=4.54 ms
64 bytes from 192.168.0.5 (192.168.0.5): icmp_seq=4 ttl=128 time=8.80 ms
64 bytes from 192.168.0.5 (192.168.0.5): icmp_seq=5 ttl=128 time=5.97 ms
64 bytes from 192.168.0.5 (192.168.0.5): icmp_seq=6 ttl=128 time=4.56 ms
^C
--- UINDOWS10.local ping statistics ---
6 packets transmitted, 6 received, 0% packet loss, time 5008ms
rtt min/avg/max/mdev = 1.612/4.529/8.801/2.482 ms

RaspberryPi上からの自ホストへのssh

$ ssh pi@raspberrypi.local
Linux raspberrypi 4.9.41-v7+ #1023 SMP Tue Aug 8 16:00:15 BST 2017 armv7l

The programs included with the Debian GNU/Linux system are free software;
the exact distribution terms for each program are described in the
individual files in /usr/share/doc/*/copyright.

Debian GNU/Linux comes with ABSOLUTELY NO WARRANTY, to the extent
permitted by applicable law.
Last login: Sun Aug 20 14:48:22 2017 from 192.168.0.8

$ exit
ログアウト
Connection to raspberrypi.local closed.
$

Windows10上からの自ホストへのSSH

PS C:\> ping UINDOWS10.local

Pinging UINDOWS10.local [XXXX::XXXX:XXXX:42ea:XXXX%11] with 32 bytes of data:
Reply from XXXX::XXXX:XXXX:42ea:XXXX%11: time<1ms
Reply from XXXX::XXXX:XXXX:42ea:XXXX%11: time<1ms
Reply from XXXX::XXXX:XXXX:42ea:XXXX%11: time<1ms
Reply from XXXX::XXXX:XXXX:42ea:XXXX%11: time<1ms

Ping statistics for XXXX::XXXX:XXXX:42ea:XXXX%11:
    Packets: Sent = 4, Received = 4, Lost = 0 (0% loss),
Approximate round trip times in milli-seconds:
    Minimum = 0ms, Maximum = 0ms, Average = 0ms
PS C:\>

Windows10上からのRaspberryPiへのping

PS C:> hostname
UINDOWS10
PS C:\Users\uepon> ping raspberrypi.local

Pinging raspberrypi.local [XXXX::XXXX:XXXX:aa9:XXXX%37] with 32 bytes of data:
Reply from XXXX::XXXX:XXXX:aa9:XXXX%37: time=4ms
Reply from XXXX::XXXX:XXXX:aa9:XXXX%37: time=4ms
Reply from XXXX::XXXX:XXXX:aa9:XXXX%37: time=6ms
Reply from XXXX::XXXX:XXXX:aa9:XXXX%37: time=4ms

Ping statistics for XXXX::XXXX:XXXX:aa9:XXXX%37:
    Packets: Sent = 4, Received = 4, Lost = 0 (0% loss),
Approximate round trip times in milli-seconds:
    Minimum = 4ms, Maximum = 6ms, Average = 4ms

Windows10上からのRaspberryPiへのSSHTeratermから)

HOST設定にraspberrypi.localを設定する点だけが変更点になります。

f:id:ueponx:20170820160529p:plain

無事接続できています。

f:id:ueponx:20170820160652p:plain

Windows10上からRaspberryPiへのSSHBash On Ubuntu On Windowsから)

Bash On Ubuntu On WindowsではSSHがあるので同様にできそうなのですが…

$ sudo apt-get install avahi-daemon
$ sudo service avahi-daemon start
initctl: Unable to connect to Upstart: Failed to connect to socket /com/ubuntu/upstart: 接続を拒否されました
 * Starting Avahi mDNS/DNS-SD Daemon avahi-daemon
$ ssh pi@raspberrypi.local
ssh: Could not resolve hostname raspberrypi.local: Name or service not known

名前解決ができないため、アクセス出来ないようです。 もちろん、IPアドレス直接であれば問題なくアクセスはできています。

ググってみると同様の現象がでているようです。

github.com

github.com

Dbusというdeamonも影響しているようです。ちょっと残念ですが、今後修正されていくことでしょう。

おわりに

今回はほとんど何も設定していませんでしたが…。 Windows10でもデフォルトでBonjourのサービスが含まれたので特別にアプリケーションをインストールすることなく、Bonjourを使うことができました。それも容易です。IPが変わる可能性のある環境だとこちらのほうが圧倒的にいいのかもしれません。

食わず嫌いだったということですかね、やっぱり。

/* -----codeの行番号----- */