This seems to be quite a trivial problem, but after some searching I can't stil figure out the answer. One can run tcpdump using "any" as the interface description, ie:
# tcpdump -i any -n host 192.168.0.1
Is there any way to force tcpdump to show on which interface displayed packet was captured?
Update:
As more people confirmed this is probably not possible with vanilla tcpdump, can someone propose a solution to mentioned problem? Perhaps different sniffer?
General issue is as follows: On a system with 50 interfaces determine what is inbound interface for packets coming from specific ip address.
I hope somebody is still interested in the solution to the problem. ;) We had the same issue in our company and I started writing a script for this.
I wrote a blog post about it with the source code and a screenshot.
I've also shared it below...
And the code: (Be sure to check my site for future updates)
You can use the -e option to print the ethernet headers, then you can correlate the src/dst MAC addresses with your network interfaces ;).
Just a note, tcpdump 4.99 now displays the interface name/direction in the output:
interface br-ex, above.
To add to Sebastian Haas's great bash script. I had to simplify his script since it failed in this line
tcpdump -l $@ | sed 's/^/[Interface:'"${BASH_REMATCH[0]:2}"'] /' &
.While it is not as flexible as the original script, it is more likely to run in stripped down linux system.
You may also be interested in the current github issue ticket regarding this feature omission in https://github.com/the-tcpdump-group/tcpdump/issues/296 .
If you are running on Mac, there is a
-k
option totcpdump
if you are using pktap interface, which dumps interface name among other useful metadata.I don't know of any answer to that either. I find no option for it, can't recall ever seeing one, and am rather certain that the tcpdump format doesn't include an interface identifier. I think you'll have to start one tcpdump instance for each interface and log to respective files.
Assuming this is on Linux, you could add an iptables rule to match the packet you are looking for and log it. Iptables log includes ingress and egress interfaces, among other things.
Adjust -c as needed.
by modifying the interface detection line, you can eliminate the alias-address interfaces in linux. sample below..
changes to