tcpdump 抓到 icmp 包,但是抓不到 tcp 包??

网络环境

  1. windows 11 作为宿主机,wsl 作为开发环境;

问题

  1. 在 wsl 使用了 claude code 进行 vibe coding,但是发现 claude code 网络 api.minimaxi.com 请求不出

目标

  1. 解决网络问题,让 claude code 可以正常请求。

结果

【顺利解决】

根本原因:因为本地的 env 配置 http_proxy(192.168.3.xxx),导致 claude 的请求走了 http_proxy 的链路。

主要内容

  1. 分析这个网络问题,记录解决步骤,

1. 逐层测试 TCP/IP 协议栈的可达性

IP 层

  1. ping api.minimaxi.com
bash 复制代码
$ ping api.minimaxi.com
PING lb-ali.minimaxi.com (8.130.45.254) 56(84) bytes of data.
64 bytes from 8.130.45.254 (8.130.45.254): icmp_seq=1 ttl=88 time=45.7 ms
64 bytes from 8.130.45.254 (8.130.45.254): icmp_seq=2 ttl=88 time=45.7 ms
64 bytes from 8.130.45.254 (8.130.45.254): icmp_seq=3 ttl=88 time=44.5 ms

TCP 层

bash 复制代码
$ dig +short api.minimaxi.com
lb-ali.minimaxi.com.
8.130.49.194 # 目标主机的 ip
8.130.45.254

$ sudo tcpdump -i any 'host 8.130.45.254 or host 8.130.49.194' -v

# 新开终端
$ export CLAUDE_ENDPOINT="https://api.minimaxi.com/anthropic/v1/messages"
$ curl -X POST "$CLAUDE_ENDPOINT" \
  -H "Content-Type: application/json" \
  -H "x-api-key: YOUR_API_KEY" \
  -H "anthropic-version: 2023-06-01" \
  -d '{
    "model": "claude-3-haiku-20240307",
    "max_tokens": 100,
    "messages": [
      {"role": "user", "content": "Hello, Claude"}
    ]
  }'
{"type":"error","error":{"type":"authentication_error","message":"login fail: Please carry the API secret key in the 'Authorization' field of the request header"},"request_id":"055df91249b0f5d119ff78a51be71488"}

问题点:tcpdump 没有捕捉到 tcp 的数据包。问题在 TCP/IP 或者更加上层,并在出现在 wsl 的配置中。

2. 本机出现了请求成功,但没有抓到包。从代理角度分析

bash 复制代码
export | grep -i proxy

嗯,果然是设置了 HTTP_PROXY 代理,是此前自己做测试的时候留下的。去除掉就可以了。

相关命令

  1. dig
  2. tcpdump
  3. ping
  4. export
相关推荐
chlk12314 小时前
Linux文件权限完全图解:读懂 ls -l 和 chmod 755 背后的秘密
linux·操作系统
舒一笑14 小时前
Ubuntu系统安装CodeX出现问题
linux·后端
改一下配置文件15 小时前
Ubuntu24.04安装NVIDIA驱动完整指南(含Secure Boot解决方案)
linux
深紫色的三北六号1 天前
Linux 服务器磁盘扩容与目录迁移:rsync + bind mount 实现服务无感迁移(无需修改配置)
linux·扩容·服务迁移
SudosuBash1 天前
[CS:APP 3e] 关于对 第 12 章 读/写者的一点思考和题解 (作业 12.19,12.20,12.21)
linux·并发·操作系统(os)
哈基咪怎么可能是AI2 天前
为什么我就想要「线性历史 + Signed Commits」GitHub 却把我当猴耍 🤬🎙️
linux·github
十日十行2 天前
Linux和window共享文件夹
linux
木心月转码ing3 天前
WSL+Cpp开发环境配置
linux
崔小汤呀4 天前
最全的docker安装笔记,包含CentOS和Ubuntu
linux·后端
何中应4 天前
vi编辑器使用
linux·后端·操作系统