使用 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
相关推荐
fangeqin3 小时前
ubuntu源码安装python3.13遇到Could not build the ssl module!解决方法
linux·python·ubuntu·openssl
风口上的吱吱鼠6 小时前
Armbian 25.5.1 Noble Gnome 开启远程桌面功能
服务器·ubuntu·armbian
笑衬人心。7 小时前
Ubuntu 22.04 + MySQL 8 无密码登录问题与 root 密码重置指南
linux·mysql·ubuntu
生如夏花℡7 小时前
HarmonyOS学习记录3
学习·ubuntu·harmonyos
星宸追风9 小时前
Ubuntu更换Home目录所在硬盘的过程
linux·运维·ubuntu
BD_Marathon9 小时前
Ubuntu下的Tomcat服务器部署
服务器·ubuntu·tomcat
巴里巴气12 小时前
对selenium进行浏览器和驱动进行配置Windows | Linux
selenium·测试工具
好奇的菜鸟21 小时前
如何在 Ubuntu 24.04 (Noble) 上使用阿里源
linux·运维·ubuntu
好奇的菜鸟1 天前
如何在Ubuntu上检查MySQL是否启动并放开3306端口
mysql·ubuntu·adb
ZPC82101 天前
ubuntu 6.8.0 安装xenomai3.3
linux·运维·ubuntu