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
相关推荐
demodashi6662 小时前
Linux下ag搜索命令详解
linux·运维·windows
無识2 小时前
Linux-第四章web服务
linux·运维·服务器
一叶知秋yyds2 小时前
Centos 安装 Docker教程
linux·docker·centos
fie88892 小时前
在CentOS 7上集成cJSON库的方法
linux·运维·centos
带土12 小时前
5. Unix/Linux 系统常用类型别名清单
linux·unix
爱吃橘的橘猫2 小时前
如何解决VMware虚拟机中Linux系统终端不显示ens33 inet IP地址的问题
linux·运维·服务器·虚拟机
梁正雄3 小时前
linux服务-Bonding网卡绑定工具
linux·运维·linux bonding·网卡绑定
云边有个稻草人3 小时前
Windows 里用 Linux 不卡顿?WSL + cpolar让跨系统开发变简单
linux·运维·服务器·cpolar
打不了嗝 ᥬ᭄3 小时前
【Linux】网络层协议
linux·网络·c++·网络协议·http