第一步:首先可以通过tcpdump命令的--list-interfaces选项,列出系统中的所有网络接口(这个与ip addr列出的还有略有点点差异)
-D --list-interfaces Print the list of the network interfaces available on the system and on which tcpdump can capture packets. For each network interface, a number and an interface name, possibly followed by a text description of the interface, is printed. The interface name or the number can be supplied to the -i flag to specify an inter‐ face on which to capture. This can be useful on systems that don't have a command to list them (e.g., Windows systems, or UNIX systems lacking ifconfig -a); the number can be useful on Windows 2000 and later systems, where the interface name is a somewhat complex string. The -D flag will not be supported if tcpdump was built with an older version of libpcap that lacks the pcap_findalldevs() function.
因为建议还是直接使用 tcpdump --list-interfaces 进行查询,查询使用普通用户都是可以的,结果类似下图所示
第二步,就是抓包时,需要指定网络接口了,此操作默认只有root特权账号才可以使用tcpdump进行抓包,说明如下
-i interface --interface=interface Listen on interface. If unspecified, tcpdump searches the system interface list for the lowest numbered, con‐ figured up interface (excluding loopback), which may turn out to be, for example, ``eth0''. On Linux systems with 2.2 or later kernels, an interface argument of ``any'' can be used to capture packets from all interfaces. Note that captures on the ``any'' device will not be done in promiscuous mode. If the -D flag is supported, an interface number as printed by that flag can be used as the interface argu‐ ment, if no interface on the system has that number as a name.
可以看出可以指定any,但是有个说明(没有完全理解到),Note that captures on the ``any'' device will not be done in promiscuous mode.
因此笔者推荐抓包时还是指定具体的网络接口,此操作默认情况只有root用户才有权限执行,如需要抓取所有与eth0网络接口相关的的数据包
tcpdump -i eth0
当然命令的输出会非常多,也可以继续指定条件,笔者将在后续的文章中单独说明,更加详细的使用方法
其他说明:tcpdump 如果需要指定网卡,笔者没有发现指定多张网卡的方法,尝试过使用 使用如下命令进行抓包
tcpdump -i eth0 -i eth1 icmp
也能抓取到icmp相关的数据包,但是实际生效的也只是最后-i选项指定的eth1
尊重别人的劳动成果 转载请务必注明出处: https://www.cnblogs.com/5201351/p/17355035.html
作者:一名卑微的IT民工
出处:https://www.cnblogs.com/5201351
本博客所有文章仅用于学习、研究和交流目的,欢迎非商业性质转载。
由于博主的水平不高,文章没有高度、深度和广度,只是凑字数,不足和错误之处在所难免,希望大家能够批评指出。
博主是利用读书、参考、引用、复制和粘贴等多种方式打造成自己的文章,请原谅博主成为一个卑微的IT民工!
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】凌霞软件回馈社区,博客园 & 1Panel & Halo 联合会员上线
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】博客园社区专享云产品让利特惠,阿里云新客6.5折上折
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· [翻译] 为什么 Tracebit 用 C# 开发
· Deepseek官网太卡,教你白嫖阿里云的Deepseek-R1满血版
· 2分钟学会 DeepSeek API,竟然比官方更好用!
· .NET 使用 DeepSeek R1 开发智能 AI 客户端
· 刚刚!百度搜索“换脑”引爆AI圈,正式接入DeepSeek R1满血版
2021-04-26 关于vmware虚拟机的ova/ovf转换成aws上的AMI镜像