---
title: "使用 tcpdump 抓包 - 开发者中心 ODC V4.3.3 | OceanBase 文档中心"
description: "使用 tcpdump 抓包 本文档旨在介绍如何使用 tcpdump 抓包。 ODC 容器内默认不包含 tcpdump 抓包工具，因此需要通过宿主机来对容器进行抓包。 步骤 1：获取容器的 Pid # 获取 container-id docker ps | grep odc # 获取容器的 PID，假设 ODC con…"
---
切换语言

- 中文站 - 简体中文
- International - English
- 日本站 - 日本語

文档反馈![](https://mdn.alipayobjects.com/huamei_22khvb/afts/img/A*lqS5SYzz_YEAAAAAAAAAAAAADiGDAQ/original) 开发者中心 ODCV 4.3.3

# 使用 tcpdump 抓包

更新时间：2026-04-13 15:30:59

[编辑](https://github.com/oceanbase/odc-doc/edit/V4.3.3/zh-CN/1300.troubleshooting/200.collect-message/900.use-tcpdump-to-capture-packets.md)  

本文档旨在介绍如何使用 tcpdump 抓包。

ODC 容器内默认不包含 tcpdump 抓包工具，因此需要通过宿主机来对容器进行抓包。

## 步骤 1：获取容器的 Pid

```shell
# 获取 container-id
docker ps | grep odc

```

![1](https://obbusiness-private.oss-cn-shanghai.aliyuncs.com/doc/img/odc/KB/2.database-connection/9.use-tcpdump-to-capture-packets/1.png)

```shell
# 获取容器的 PID，假设 ODC container-id 为 `dceb`
docker inspect dceb | grep Pid

```

![2](https://obbusiness-private.oss-cn-shanghai.aliyuncs.com/doc/img/odc/KB/2.database-connection/9.use-tcpdump-to-capture-packets/1.png)

## 步骤 2：进入容器的命名空间

通过 `nsenter` 命令进入容器进程的网络命名空间。

```shell
# 假设 ODC 容器的 Pid 为 84139
sudo nsenter -t 84139 -n

```

使用 `ifconfig` 命令查看该容器的网卡信息。

![3](https://obbusiness-private.oss-cn-shanghai.aliyuncs.com/doc/img/odc/KB/2.database-connection/9.use-tcpdump-to-capture-packets/3.png)

## 步骤 3：使用 tcpdump 抓包

参考命令：

```shell
tcpdump tcp -i eth0 -c 1000 -vvv and port 80 and src net ***.***.*.*/24 -w ./target.cap

```

参数说明：

| 参数 | 说明 |
| --- | --- |
| tcp | 只监听 tcp 协议的数据包。 |
| -i eth0 | 只抓取经过网卡 eth0 的数据包。 |
| -c 1000 | 只抓取 1000 个数据包。 |
| -vvv | 显示详细信息。 |
| port | 监听端口。   #### 注意    需要使用容器的内部端口。例如：容器通过 `-p 8080:80` 进行端口绑定，则需要监听 80 端口，而非 8080 端口。 |
| scr net ***.***.*.*/24 | 数据包的源地址为 ***.***.*.*/24。 |
| -w ./target.cap | 保存成 cap 文件，方便用 wireshark 分析。 |

 上一篇 下一篇 ![有帮助](https://gw.alipayobjects.com/mdn/ob_asset/afts/img/A*y6ocSqN8cqsAAAAAAAAAAAAAARQnAQ)![无帮助](https://gw.alipayobjects.com/mdn/ob_asset/afts/img/A*BG9IQJyLHF8AAAAAAAAAAAAAARQnAQ)![反馈](https://gw.alipayobjects.com/mdn/ob_asset/afts/img/A*eTWdQKCRKHwAAAAAAAAAAAAAARQnAQ)[AI](https://www.oceanbase.com/obi) 咨询热线
