LoginSignup
1
0

More than 1 year has passed since last update.

WSL2でlocalhostに接続できなくてはまったこと

Posted at

WSL2 (ubuntu)で起動したlocalhostアプリに接続できなかった。

原因は、ネットワークアダプタのipv6が有効なせいっぽい。
でも、ipv6をoffにする運用をするわけにはいかないので

WSLから起動しているubuntuのipv6を無効にすることで解決させた。
いろんな記事では、標準 or mntする機能をごにょごにょすることでコントロールできるとかいろいろあるんだけど全然うまくいかず。

結局

/etc/sysctl.conf

net.ipv6.conf.all.disable_ipv6 = 1
net.ipv6.conf.default.disable_ipv6 = 1
net.ipv6.conf.lo.disable_ipv6 = 1

を定義しておいて

/etc/profile.d/
の配下に

ipv4.sh

とか適当なシェルを作成して

#! /bin/bash
sudo sysctl -p

起動時に実行させる方法にした。

sudo netstat -tulpn | grep LISTEN

の結果が

127.0.0.1:8000          0.0.0.0:*

の状態にならないとつながらない。

127.0.0.1:8000          ::1

の状態は駄目だった。

補足: .wslconfigで指定しても無理。

localhostForwarding=true
1
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
1
0