If I want to tcpdump DNS requests by clients (on an OpenWrt 10.04 router), then I
root@ROUTER:/etc# tcpdump -n -i br-lan dst port 53 2>&1
tcpdump: verbose output suppressed, use -v or -vv for full protocol decode
listening on br-lan, link-type EN10MB (Ethernet), capture size 96 bytes
22:29:38.989412 IP 192.168.1.200.55919 > 192.168.1.1.53: 5697+ A? foo.org. (25)
22:29:39.538981 IP 192.168.1.200.60071 > 192.168.1.1.53: 17481+ PTR? 150.33.87.208.in-addr.arpa. (44)
^C
2 packets captured
3 packets received by filter
0 packets dropped by kernel
That's fully ok. But. Why can't I pipe the tcpdumps output in realtime?
root@ROUTER:/etc# tcpdump -n -i br-lan dst port 53 2>&1 | awk '/\?/ {print $3}'
^C
root@ROUTER:/etc#
If I awk, etc. anything after tcpdump, I don't get ANY output. Why is that? Why can't I process the output of tcpdump with pipelining in realtime? (so that e.g.: in the example in only outputs the 3rd column)
Are there any solutions for this?
man tcpdump
this supports both-l
and--immediate-mode
but in reality it doesn't seem to work even with both of those added. – Mikko Rantalainen Aug 06 '20 at 08:43--immediate-mode -l -n
works correctly with tcpdump version 4.9.3. If your DNS server cannot cope with the packet flow your output will be delayed unless you pass-n
in addition to-l
or--immediate-mode
because without the-n
the output will be buffered until DNS resolution has been completed or timeout occurs. – Mikko Rantalainen Aug 06 '20 at 09:30