使用 Wireshark 在 Ubuntu 22.04 上抓包分析网络流量

Ubuntu 22.04 上安装和使用 Wireshark,按照以下步骤操作:


1. 安装 Wireshark

方式 1:使用 APT 安装(推荐)

Wireshark 在 Ubuntu 的官方仓库中,你可以直接使用 apt 安装:

bash 复制代码
sudo apt update
sudo apt install wireshark -y

安装完成后,检查 Wireshark 版本:

bash 复制代码
wireshark --version

2. 运行 Wireshark

方式 1:GUI(图形界面)运行

如果你想在桌面环境下运行 Wireshark,可以在终端输入:

bash 复制代码
wireshark

或者,在应用菜单中搜索 Wireshark 并点击运行。

方式 2:CLI(命令行模式)运行

如果你想在命令行模式下运行 Wireshark(类似 tcpdump),可以使用:

bash 复制代码
tshark

例如,监听 eth0 接口的流量:

bash 复制代码
sudo tshark -i eth0

3. 让非 root 用户使用 Wireshark

默认情况下,Wireshark 需要 root 权限才能抓包。如果你想让当前用户无 root 权限也能使用 Wireshark:

bash 复制代码
sudo dpkg-reconfigure wireshark-common

选择 "Yes" ,然后将当前用户加入 wireshark 组:

bash 复制代码
sudo usermod -aG wireshark $(whoami)

注销并重新登录 (或者执行 newgrp wireshark 使更改生效)。


4. 启动抓包

方式 1:使用 GUI 抓包

  1. 打开 Wireshark
  2. 选择一个网络接口(如 eth0wlan0
  3. 点击 Start 开始抓包

方式 2:使用 tshark 命令行抓包

列出可用网络接口
bash 复制代码
tshark -D

示例输出:

复制代码
1. eth0
2. wlan0
3. lo
抓取特定接口的流量

抓取 eth0 接口的数据:

bash 复制代码
sudo tshark -i eth0

抓取并保存到文件:

bash 复制代码
sudo tshark -i eth0 -w capture.pcap
使用过滤器

抓取 特定端口 的流量(如 443 HTTPS 流量):

bash 复制代码
sudo tshark -i eth0 port 443

抓取 特定 IP 地址 的流量:

bash 复制代码
sudo tshark -i eth0 host 192.168.1.1

5. 使用 Wireshark 过滤数据

Wireshark 支持多种过滤规则,常见的过滤器如下:

过滤器 说明
ip.addr == 192.168.1.1 过滤指定 IP 地址的数据包
tcp.port == 443 仅查看 HTTPS(端口 443)流量
http 仅显示 HTTP 流量
tls 仅显示 TLS(HTTPS)流量
udp.port == 53 仅显示 DNS 查询(UDP 53 端口)

6. 卸载 Wireshark

如果你不再需要 Wireshark,可以卸载:

bash 复制代码
sudo apt remove --purge wireshark -y
sudo apt autoremove -y

总结

  • 安装 Wiresharksudo apt install wireshark
  • 非 root 用户使用sudo usermod -aG wireshark $(whoami)
  • GUI 运行wireshark
  • CLI 运行tshark -i eth0
  • 常用过滤器ip.addr == x.x.x.xtcp.port == 443http
相关推荐
Run Freely93716 小时前
postman-Newman插件
测试工具·postman
Run Freely9371 天前
接口测试-postman-全局变量与环境变量
测试工具·postman
我的xiaodoujiao1 天前
从 0 到 1 搭建 Python 语言 Web UI自动化测试学习系列 8--基础知识 4--常用函数 2
前端·python·测试工具·ui
程序员小远1 天前
常用的测试用例
自动化测试·软件测试·python·功能测试·测试工具·职场和发展·测试用例
一只积极向上的小咸鱼1 天前
Windows中通过wsl运行Ubuntu
linux·运维·ubuntu
嵌入式分享1 天前
嵌入式分享#41:RK3576改UART波特率【精简版】
linux·嵌入式硬件·ubuntu·嵌入式
Cyan_RA92 天前
Linux 远程Ubuntu服务器本地部署大模型 EmoLLM 中常见的问题及解决方案 万字详解
linux·运维·服务器·ubuntu·大模型·远程部署·emollm
~光~~2 天前
【环境配置 升级gcc】RK3588 Ubuntu20.04 gcc9升级为gcc10
ubuntu·gcc
你疯了抱抱我2 天前
【SSH】同一局域网下windows使用Xshell SSH连接另一台 ubuntu 22.04 电脑
运维·ubuntu·ssh
2301_818411552 天前
Ubuntu之apt更新源
linux·运维·ubuntu