はじめに
WSL2で、ネットワークがミラーモードだとUSB IPを使ったUSB接続ができない。USBデバイスの接続については、こちらを参照。
現状、私の環境での対策としてはネットワークモードをNATに変更するしかない(2025年1月22日時点)。
動作確認環境
- Windows 11 23H2
- WSL2
WSL バージョン: 2.3.26.0 カーネル バージョン: 5.15.167.4-1 WSLg バージョン: 1.0.65 MSRDC バージョン: 1.2.5620 Direct3D バージョン: 1.611.1-81528511 DXCore バージョン: 10.0.26100.1-240331-1435.ge-release Windows バージョン: 10.0.22631.4751
- Ubuntu (18.04/20.04/22.04)
- usbip
4.3.0-70+Branch.master.Sha.701757afaea0ed252dd541f290decafe807970a5.701757afaea0ed252dd541f290decafe807970a5
エラーの確認
WSLでネットワークモードをミラーにする。WSLの設定については、こちらを参照。
.wslconfig
[wsl2]
networkingMode=mirrored
USB IPでUSBデバイスをWSL2のUbuntuに接続(アタッチ)する際に、下記のようにファイアウォールのエラーが発生する。私の環境では、ホストのファイアウォールを無効化してもエラーは発生した。
usbipd.exe attach --wsl --busid=2-13 --auto-attach
usbipd: info: Using WSL distribution 'Ubuntu' to attach; the device will be available in all WSL 2 distributions.
usbipd: info: Using IP address 127.0.0.1 to reach the host.
usbipd: warning: A firewall appears to be blocking the connection; ensure TCP port 3240 is allowed.
usbipd: info: Starting endless attach loop; press Ctrl+C to quit.
WSL usbip: error: tcp connect
エラーの回避策
私の環境では、ネットワークモードをNATにすると上記エラーは解消された。ミラーモードのままでエラーを回避する方法はまだ見つけられていない。
.wslconfig
[wsl2]
networkingMode=NAT
まとめ
WSL2で、ネットワークがミラーモードだとUSB IPを使ったUSB接続ができない事象を紹介した。ネットワークモードをNATに変更することでエラーを回避できる。引き続きミラーモードでUSB接続ができる方法がないか調査を継続する。
参考