使用 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
相关推荐
7ACE4 小时前
Wireshark TS | 发送数据超出接收窗口
网络协议·tcp/ip·wireshark
风吹落叶花飘荡6 小时前
Ubuntu系统 系统盘和数据盘扩容具体操作
linux·运维·ubuntu
贾斯汀玛尔斯8 小时前
ubuntu/centos系统ping 不通域名的解决方案
linux·ubuntu·centos
软件测试-阿涛9 小时前
【性能测试】Jmeter+Grafana+InfluxDB+Prometheus Windows安装部署教程
测试工具·jmeter·性能优化·压力测试·grafana·prometheus
翟天保Steven11 小时前
Ubuntu-安装Epics教程
linux·ubuntu·epics
Tipriest_17 小时前
离线进行apt安装的过程(在只能本地传输的ubuntu主机上使用apt安装)
linux·运维·ubuntu·apt·install·deb
QMCY_jason17 小时前
Ubuntu 1804 编译ffmpeg qsv MediaSDK libva 遇到的问题记录
linux·ubuntu·ffmpeg
惜.己1 天前
pytest中使用skip跳过某个函数
开发语言·python·测试工具·pytest
站住前面的二哈1 天前
Cartographer安装测试与模块开发(三)--Cartographer在Gazebo仿真环境下的建图以及建图与定位阶段问题(实车也可参考)
学习·ubuntu