Centos7 tcpdump -w 时遇到 Permission denied

一、问题

使用tcpdump抓包并写入文件时出现 Permission denied,权限不足。

bash 复制代码
[root@storm03 tcpdumpTest]# tcpdump -i em4 udp and host 225.1.2.5 and port 10111 -G 60 -w %Y_%m%d_%H%M_%S.pcap
tcpdump: listening on em4, link-type EN10MB (Ethernet), capture size 65535 bytes
tcpdump: 2024_0422_1602_51.pcap: Permission denied

二、分析

既然提示权限不足,咱们就去看权限,使用如下命令查看当前目录的权限:

bash 复制代码
[root@storm03 tmp]# ll
总用量 10031100
drwxr-xr-x 2 root    root          4096 4月  22 16:04 tcpdumpTest

可以看到目录所有者root用户具有读、写和执行权限,所属组和其他用户只具有读和执行权限,没有w写权限;

而tcpdump抓包写入的文件所属组和用户一般为tcpdump,如下所示:

bash 复制代码
[root@storm03 tmp]# ll
总用量 10031128
-rw-r--r-- 1 tcpdump tcpdump  767743134 4月  19 10:44 last_test1.cap
-rw-r--r-- 1 tcpdump tcpdump  449740452 4月  19 09:13 last_test.cap

那就很清楚了,为当前目录的其他用户也设置w写权限即可解决问题。

三、解决方案

使用如下命令为当前目录开放所有权限:

bash 复制代码
[root@storm03 tmp]# chmod 777 tcpdumpTest/
[root@storm03 tmp]# ll
drwxrwxrwx 2 root    root          4096 4月  22 16:04 tcpdumpTest

再次使用tcpdump抓包,正常:

bash 复制代码
[root@storm03 tcpdumpTest]# tcpdump -i em4 udp and host 225.1.2.5 and port 10111 -G 10 -Z root -w %Y_%m%d_%H%M_%S.pcap
tcpdump: listening on em4, link-type EN10MB (Ethernet), capture size 65535 bytes
^C61846 packets captured
62143 packets received by filter
0 packets dropped by kernel
[root@storm03 tcpdumpTest]# ll
总用量 82996
-rw-r--r-- 1 root root 22404468 4月  22 16:34 2024_0422_1634_46.pcap
-rw-r--r-- 1 root root 22877124 4月  22 16:35 2024_0422_1634_56.pcap
-rw-r--r-- 1 root root 22753464 4月  22 16:35 2024_0422_1635_06.pcap
-rw-r--r-- 1 root root 16941444 4月  22 16:35 2024_0422_1635_16.pcap
相关推荐
网络研究院7 天前
2026年网络安全
网络·安全·法律·法规·趋势·发展
酣大智7 天前
ARP代理--工作原理
运维·网络·arp·arp代理
treesforest7 天前
AI安全系统如何识别异常访问?IP风险识别正在成为关键能力
网络·人工智能·tcp/ip·安全·web安全
shushangyun_7 天前
2026年快消品B2B系统推荐:支持终端门店订货、促销政策自动化的工具?
java·运维·网络·数据库·人工智能·spring·自动化
2601_961845157 天前
粉笔行测题库|系统班|刷题
网络·百度·微信·微信公众平台·facebook·新浪微博
程序猿阿伟7 天前
《Chrome离线扩展安装的底层逻辑与场景落地指南》
服务器·网络·chrome
InHand云飞小白7 天前
无人值守站点网络困境?工业级路由器IR315破解连接难题
网络·物联网·4g·工业路由器·4g路由器·iiot·蜂窝路由器
森G7 天前
75、服务器源码解析---------云视频服务项目
linux·服务器·网络·c++·qt
江华森7 天前
TCP/IP 协议栈实战 — 7 个实验详解
网络·tcp/ip·智能路由器
程序员小远7 天前
自动化测试基础知识总结
自动化测试·软件测试·python·selenium·测试工具·职场和发展·测试用例