tcpdump(三)选项进阶

本文深入探讨了TCPDump的高级使用技巧,包括如何利用-t选项去除时间戳,使用-v选项获取更详细的协议信息,以及如何通过-F选项指定过滤表达式文件。这些技巧对于网络监控和故障排查极为关键。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

-t 选项 :输出时不打印时间戳

  • 没有使用 -t 选项时
[root@test ~]# tcpdump -i ens39 -c 1
tcpdump: verbose output suppressed, use -v or -vv for full protocol decode
listening on ens39, link-type EN10MB (Ethernet), capture size 262144 bytes
15:36:50.707284 IP 192.168.146.6.netbios-ns > 192.168.146.255.netbios-ns: NBT UDP PACKET(137): QUERY; REQUEST; BROADCAST
1 packet captured
41 packets received by filter
0 packets dropped by kernel
  • 使用了-t 选项时
[root@test ~]# tcpdump -i ens39 -c 1 -t
tcpdump: verbose output suppressed, use -v or -vv for full protocol decode
listening on ens39, link-type EN10MB (Ethernet), capture size 262144 bytes
IP test.bootpc > 192.168.146.254.bootps: BOOTP/DHCP, Request from 00:0c:29:bb:96:75 (oui Unknown), length 300
1 packet captured
2 packets received by filter
0 packets dropped by kernel

我们可以看到,使用了-t 选项之后,’15:36:50.707284‘消失了,这就是抓包的时间戳信息,至于为什么会精确到小数点后6位,这是因为tcpdump默认情况下就是按照微妙(microsecond)来计时的,其实,tcpdump还支持按纳秒计时呢,开启的方法是使用 --time-stamp-precision=nano 选项。


-v 选项:输出更详细的信息

加了 -v 选项之后,在原有输出内容的基础之上,我们还会看到tos值,ttl值,ID值,总长度,检验值。

没有使用 -v 选项输出的信息

[root@test ~]# tcpdump -i ens39 -c 1
tcpdump: verbose output suppressed, use -v or -vv for full protocol decode
listening on ens39, link-type EN10MB (Ethernet), capture size 262144 bytes
15:59:56.419206 IP 192.168.146.6.mdns > 224.0.0.251.mdns: 0 A (QM)? wpad.local. (28)
1 packet captured
27 packets received by filter
0 packets dropped by kernel

使用 -v 选项输出的信息

[root@test ~]# tcpdump -i ens39 -c 1 -v
tcpdump: listening on ens39, link-type EN10MB (Ethernet), capture size 262144 bytes
16:01:05.714829 IP (tos 0x0, ttl 1, id 55148, offset 0, flags [none], proto UDP (17), length 56)
    192.168.146.6.mdns > 224.0.0.251.mdns: 0 A (QM)? wpad.local. (28)
1 packet captured
37 packets received by filter
0 packets dropped by kernel

-F选项:指定过滤表达式所在的文件

我们当初存储的过滤条件

[root@test ~]# cat filter.txt 
port 22

使用-F选项来指定要读取的文件

[root@test ~]# tcpdump -i ens39 -c 1 -t -F filter.txt 
tcpdump: verbose output suppressed, use -v or -vv for full protocol decode
listening on ens39, link-type EN10MB (Ethernet), capture size 262144 bytes
IP 192.168.146.6.51804 > 192.168.146.131.ssh: Flags [F.], seq 2883813072, ack 608134279, win 4105, length 0
1 packet captured
3 packets received by filter
0 packets dropped by kernel

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值