0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

WSL Tips

Last updated at Posted at 2025-04-26

外部からwsl上のサービスにアクセスする方法

  1. wsl上のIPアドレス確認
    $ ifconfig
    eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1472
            inet 172.20.177.100  netmask 255.255.240.0  broadcast 172.20.191.255
    
  2. powershell(管理者権限で実行)でポートフォワーディング設定
    ※外部の全アドレスからの2222ポートアクセスを172.20.177.100の22ポートに送る
    netsh interface portproxy add v4tov4 listenaddress=* listenport=2222 connectaddress=172.20.177.100 connectport=22
    
    netsh interface portproxy show all
    
    ipv4 をリッスンする:         ipv4 に接続する:
    
    Address         Port        Address         Port
    --------------- ----------  --------------- ----------
    *               2222        172.20.177.100  22
    
  3. windowsのファイアウォール設定で2222ポートをあける
    <Windows10・11>ファイアウォールのポートの開放参照

vscodeでデフォルトアタッチするユーザ指定

  1. wsl2内で、以下を設定
    /etc/wsl.conf
    [user]
    default=<ユーザ名>
    
  2. 以下で一度停止させ、vscodeでアタッチ
    wsl -t <ディストリビューション名>
    

参考

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?