使用 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
相关推荐
集成显卡9 小时前
PlayWright | 初识微软出品的 WEB 应用自动化测试框架
前端·chrome·测试工具·microsoft·自动化·edge浏览器
藥瓿亭10 小时前
K8S认证|CKS题库+答案| 3. 默认网络策略
运维·ubuntu·docker·云原生·容器·kubernetes·cks
Gaoithe10 小时前
ubuntu 端口复用
linux·运维·ubuntu
互联网杂货铺10 小时前
完美搭建appium自动化环境
自动化测试·软件测试·python·测试工具·职场和发展·appium·测试用例
Mike_66614 小时前
win10安装WSL2、Ubuntu24.04
windows·ubuntu·wsl2
SilentCodeY14 小时前
Ubuntu 系统通过防火墙管控 Docker 容器
linux·安全·ubuntu·系统防火墙
测试老哥16 小时前
Jmeter如何进行多服务器远程测试?
自动化测试·软件测试·功能测试·测试工具·jmeter·测试用例·性能测试
鱼鱼说测试18 小时前
postman基础
测试工具·postman
超级土豆粉21 小时前
从0到1写一个适用于Node.js的User Agent生成库
linux·ubuntu·node.js
程序员杰哥21 小时前
Postman常见问题及解决方法
自动化测试·软件测试·python·测试工具·职场和发展·测试用例·postman