使用 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
相关推荐
高峰聚焦24 分钟前
【Ubuntu】Netplan静态网络配置
linux·运维·ubuntu
冯一川38 分钟前
Arm核的Ubuntu系统上安装Wireshark
linux·ubuntu·wireshark
Jerry&Louis43 分钟前
【Ubuntu】fcitx5 + Rime(中州韵)好用的Linux中文输入法
linux·ubuntu
o0o_-_44 分钟前
【瞎折腾/mi50 32G/ubuntu】mi50显卡ubuntu运行大模型开坑(二)使用llama.cpp部署Qwen3系列
linux·ubuntu·llama
周之鸥6 小时前
Ubuntu 服务器管理命令笔记
服务器·笔记·ubuntu
冰激凌zz8 小时前
ubuntu nobel + qt5.15.2 设置qss语法识别正确
linux·qt·ubuntu
又逢乱世9 小时前
Ubuntu 安装 Docker
linux·ubuntu·docker
waves浪游11 小时前
论坛系统测试报告
测试工具·测试用例·bug·测试
hkNaruto18 小时前
【AI】Ubuntu 22.04 evalscope 模型评测 Qwen3-4B-FP8
人工智能·ubuntu·qwen3