※当サイトの記事には、広告・プロモーションが含まれます。

Avahiを導入すれば、WSL 2(Windows SubSystem for Linux 2)でhostnameで接続できるらしい

front-row.jp

⇧ amazing...

そして、悲報...

news.mynavi.jp

Ubuntuのアップデートが必要ですかね...

WSL 2(Windows SubSystem for Linux 2)は動的IPアドレス

WSL 2(Windows SubSystem for Linux 2)は、起動の度にIPアドレスが変わってしまう困ったちゃんでありますと。

一応、

learn.microsoft.com

Accessing Linux networking apps from Windows (localhost)

If you are building a networking app (for example an app running on a NodeJS or SQL server) in your Linux distribution, you can access it from a Windows app (like your Edge or Chrome internet browser) using localhost (just like you normally would).

https://learn.microsoft.com/en-us/windows/wsl/networking

localhostでアクセスできるとは言ってるけども。

Avahiを導入すれば、WSL 2(Windows SubSystem for Linux 2)でhostnameで接続できるらしい

Avahiなるものの存在を、

zenn.dev

⇧ 上記サイト様で知ったのですが、

gihyo.jp

Avahiオープンソースソフトウェアとしてリリースされています。Ubuntuではデフォルトでインストールされます。Ubuntuを起動すると自動で起動し、インストールされているソフトウェアが提供するサービスをネットワークに配信するほか、同一ネットワークにあるBonjour対応ノードからの通知を受け付けて、その情報をキャッシュします。

第216回 Avahiとローカルエリアネットワーク | gihyo.jp

Ubuntuだとデフォルトでインストールされるものらしい。

公式の説明を見てみたものの、

www.avahi.org

What is Avahi?

Avahi is a system which facilitates service discovery on a local network via the mDNS/DNS-SD protocol suite. This enables you to plug your laptop or computer into a network and instantly be able to view other people who you can chat with, find printers to print to or find files being shared. Compatible technology is found in Apple MacOS X (branded "Bonjour" and sometimes "Zeroconf").

https://www.avahi.org/

⇧ うむ、サッパリ分からん...

とりあえず、UbuntuにAvahiがインストールされてるのか確認

WSL 2(Windows SubSystem for Linux 2)のUbuntuを起動。

そしたらば、インストールされてるか確認。

news.mynavi.jp

qiita.com

⇧ 上記サイト様を参考に。

dpkg -l | grep '^ii' | grep avahi    

⇧ う~む、インストールされてるのか分からん...。

ホスト名を設定

とりあえず、/etc/wsl.conf の[network]にhostnameを追加。

再起動しておきます。

Avahiと必要なライブラリをインストール

Avahiと必要なライブラリがインストールされとるか分からんので、インストール。

sudo apt install -y avahi-daemon libnss-mdns    

エラー。アップデートしてみる。

改めて。

今度は、上手くインストールされたっぽい。

ホスト名での接続を確認する

ホスト名で解決できる模様。

WindowsからWSL 2(Windows SubSystem for Linux 2)のUbuntuSSHも試してみます。rootユーザーでログインする場合、事前に、

askubuntu.com

⇧ 上記サイト様によりますと、「/etc/ssh/sshd_config」に「PermitRootLogin yes」の設定を追加すれば良い模様。本当は、「公開鍵認証」にした方が良いんだろうけど...

で、SSHのサービスを再起動しておく。

で、ホスト名でのSSH接続を試す。

⇧ 「WSL 2(Windows SubSystem for Linux 2)」のUbuntuのホスト名で接続できました。

次回は、「WSL 2(Windows SubSystem for Linux 2)」のUbuntuPostgreSQL をインストールして、Ubuntuのホスト名で接続できるか確認してみますかね。

毎度モヤモヤ感が半端ない...

今回はこのへんで。