⇧ amazing...
そして、悲報...
⇧ Ubuntuのアップデートが必要ですかね...
WSL 2(Windows SubSystem for Linux 2)は動的IPアドレス
WSL 2(Windows SubSystem for Linux 2)は、起動の度にIPアドレスが変わってしまう困ったちゃんでありますと。
一応、
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).
⇧ localhostでアクセスできるとは言ってるけども。
Avahiを導入すれば、WSL 2(Windows SubSystem for Linux 2)でhostnameで接続できるらしい
Avahiなるものの存在を、
⇧ 上記サイト様で知ったのですが、
Avahiはオープンソースソフトウェアとしてリリースされています。Ubuntuではデフォルトでインストールされます。Ubuntuを起動すると自動で起動し、
⇧ Ubuntuだとデフォルトでインストールされるものらしい。
公式の説明を見てみたものの、
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").
⇧ うむ、サッパリ分からん...
とりあえず、UbuntuにAvahiがインストールされてるのか確認
WSL 2(Windows SubSystem for Linux 2)のUbuntuを起動。
そしたらば、インストールされてるか確認。
⇧ 上記サイト様を参考に。
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)のUbuntuへSSHも試してみます。rootユーザーでログインする場合、事前に、
⇧ 上記サイト様によりますと、「/etc/ssh/sshd_config」に「PermitRootLogin yes
」の設定を追加すれば良い模様。本当は、「公開鍵認証」にした方が良いんだろうけど...
で、SSHのサービスを再起動しておく。
で、ホスト名でのSSH接続を試す。
⇧ 「WSL 2(Windows SubSystem for Linux 2)」のUbuntuのホスト名で接続できました。
次回は、「WSL 2(Windows SubSystem for Linux 2)」のUbuntuにPostgreSQL をインストールして、Ubuntuのホスト名で接続できるか確認してみますかね。
毎度モヤモヤ感が半端ない...
今回はこのへんで。