跳到主內容

在Windows 11安裝WLS

安裝WLS

開啟 PowerShell(以系統管理員身分)

wsl --install -d Ubuntu-24.04

安裝後會詢問要使用什麼帳密,可直接用目前登入windows用的帳密會比較好記

 

關聯port

進入UbuntuLinux後,會看到IP是隨機的net (外面不能連入)

假設我在 Ubuntu 裝好 nginx port 用 80,我在本機輸入隨機IP 172.26.94.32,就能看到Nginx的畫面

我想要讓外面的連入,要這樣做

使用 PowerShell(以系統管理員身分)

netsh interface portproxy add v4tov4 listenport=81 listenaddress=0.0.0.0 connectport=80 connectaddress=172.26.94.32

確認建立規則

netsh interface portproxy show all

開通 81 PORT 防火牆

netsh advfirewall firewall add rule name="WSL2 Port 81" dir=in action=allow protocol=TCP localport=81

移除WLS

使用 PowerShell(以系統管理員身分)

列出

wsl -l -v

  NAME              STATE           VERSION
* Ubuntu-24.04      Running         2
  docker-desktop    Running         2

移除

wsl --unregister Ubuntu-24.04