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
相关推荐
invicinble3 小时前
对linux形成认识
linux·运维·服务器
小Pawn爷3 小时前
14.VMmare安装ubuntu
linux·运维·ubuntu
半桔3 小时前
【IO多路转接】高并发服务器实战:Reactor 框架与 Epoll 机制的封装与设计逻辑
linux·运维·服务器·c++·io
HABuo4 小时前
【linux文件系统】磁盘结构&文件系统详谈
linux·运维·服务器·c语言·c++·ubuntu·centos
Howrun7774 小时前
关于Linux服务器的协作问题
linux·运维·服务器
小白同学_C5 小时前
Lab3-page tables && MIT6.1810操作系统工程【持续更新】
linux·c/c++·操作系统os
十年磨一剑~6 小时前
Linux程序接收到sigpipe信号崩溃处理
linux
geshifei6 小时前
Sched ext回调3——select_cpu(linux 6.15.7)
linux·ebpf
代码游侠6 小时前
C语言核心概念复习——网络协议与TCP/IP
linux·运维·服务器·网络·算法
你真是饿了6 小时前
6.库制作与原理
linux·服务器