Try   HackMD

設定wsl為bridge模式

wsl網卡預設為NAT模式

欲設定為橋接模式,須把Hyper-V平台與管理工具打開

Image Not Showing Possible Reasons
  • The image was uploaded to a note which you don't have access to
  • The note which the image was originally uploaded to has been deleted
Learn More →

先開啟wsl,使其建立虛擬網卡
再開啟powershell,使用

get-netadapter

查詢要設定的網卡名稱

下圖例,使用Wi-Fi網卡作為橋接卡

Image Not Showing Possible Reasons
  • The image was uploaded to a note which you don't have access to
  • The note which the image was originally uploaded to has been deleted
Learn More →

接著設置wsl要使用的網卡(上圖利,網卡名稱為Wi-Fi)

set-vmswitch wsl -netadaptername Wi-Fi

Image Not Showing Possible Reasons
  • The image was uploaded to a note which you don't have access to
  • The note which the image was originally uploaded to has been deleted
Learn More →

接著回到wsl刪除原網卡設定

sudo ip addr del $(ip addr show eth0 | grep 'inet\b' | awk '{print $2}' | head -n 1) dev eth0

Image Not Showing Possible Reasons
  • The image was uploaded to a note which you don't have access to
  • The note which the image was originally uploaded to has been deleted
Learn More →

設定固定IP(這裡以192.168.8.120,gateway192.168.8.1為例)

sudo ip addr add 192.168.8.120/24 broadcast 192.168.8.255 dev eth0

Image Not Showing Possible Reasons
  • The image was uploaded to a note which you don't have access to
  • The note which the image was originally uploaded to has been deleted
Learn More →

設定路由與gateway

sudo ip route add 0.0.0.0/0 via 192.168.8.1 dev eth0

Image Not Showing Possible Reasons
  • The image was uploaded to a note which you don't have access to
  • The note which the image was originally uploaded to has been deleted
Learn More →

接著更新DNS(更改resolv.conf檔案中的nameserver)

sudo nano /etc/resolv.conf

Image Not Showing Possible Reasons
  • The image was uploaded to a note which you don't have access to
  • The note which the image was originally uploaded to has been deleted
Learn More →

Image Not Showing Possible Reasons
  • The image was uploaded to a note which you don't have access to
  • The note which the image was originally uploaded to has been deleted
Learn More →

更改後如下:

Image Not Showing Possible Reasons
  • The image was uploaded to a note which you don't have access to
  • The note which the image was originally uploaded to has been deleted
Learn More →

取消橋接模式

進入powershell模式,輸入以下命令

set-vmswitch wsl -switchtype internal

接著關掉wsl,在重啟wsl即可