1
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?

WSL2でClaude Codeが「ETIMEDOUT」で繋がらない時の解消法

1
Posted at

概要

WSL2(Ubuntu)環境で Claude Code を起動した際、Failed to connect to api.anthropic.com: ETIMEDOUT となり、通信がタイムアウトする問題が発生した。

原因は WindowsファイアウォールによるWSL2の通信ブロック。これをPowerShellから力技で解決する手順をメモしておく。

現象

Claude Code 起動時に以下のエラーで止まる。

Unable to connect to Anthropic services
Failed to connect to api.anthropic.com: ETIMEDOUT
Please check your internet connection and network settings.

WSL側から curl を叩いても反応がない(固まる)。

curl -I https://api.anthropic.com
# 返答がなく、数分後にタイムアウトする

解決策

WSL2が使用する内部IPアドレス範囲に対して、Windowsファイアウォールの「受信」と「送信」の両方に許可ルールを追加する。

1. 受信ルール(Inbound)の追加

管理者権限のPowerShellで以下を実行。

New-NetFirewallRule -DisplayName "Allow WSL2 Traffic (IP Based)" `
    -Direction Inbound `
    -Action Allow `
    -RemoteAddress 172.16.0.0/12,192.168.0.0/16

2. 送信ルール(Outbound)の追加

同じくPowerShellで以下を実行。

New-NetFirewallRule -DisplayName "Allow WSL2 Outbound (IP Based)" `
    -Direction Outbound `
    -Action Allow `
    -LocalAddress 172.16.0.0/12,192.168.0.0/16

疎通確認

設定完了後、WSLのターミナルで以下のコマンドを実行し、疎通を確認する。

curl -I https://api.anthropic.com

成功時のレスポンス:

HTTP/2 404
server: cloudflare
...

HTTP/2 404 (または200など)が返ってくれば、通信の壁を突破できている。

補足:なぜこれで直るのか

WSL2は「vEthernet (WSL)」という仮想ネットワークアダプタ経由で通信している。Windowsのアップデートや環境の変化で、このアダプタからの「外へ行く通信」が未定義(デフォルトブロック)になることがある。

特定のアプリ(node.exeなど)を許可するよりも、WSLが使うIPセグメントをまとめて許可する方が、IPが変動するWSL環境では確実だ。

まとめ

  • 繋がらない時はまず curl -I で疎通確認。
  • 固まるならファイアウォールを疑え。
  • PowerShellで「受信」と「送信」の両方に許可を入れればOK。
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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?