Anyone know an easy way to ask Linux to "display every internet packet to/from google chrome" or "display every internet packet to/from telnet process with PID 10275"?
The telnet example is not too useful, since I can just use wireshark or tcpdump to see all TCP conversations involving port 23. That and nobody uses telnet anymore. But sniffing all packets to/from complex applications which use many ports seems like a useful thing.
I found some related answers exploring different ways to corroborate ports and PIDs (or programs names) and such, but nothing about packets
Looks like someone might have been willing to pay for this answer a while back:
NetHogs is useful for quickly seeing what programs are creating traffic over an interface, but it doesn't have a way to capture packets.
To capture network traffic, you can use tcpdump. This is a packet sniffer that can observe and record network traffic on an interface. In the following example, we capture 1,000 packets using tcpdump. An easier way to analyze network traffic is to use an actual network traffic analyzer, such as Wireshark.
Using the command lineWinDump will automatically capture traffic on the first network interface it finds. If you need to select a different interface, use "windump -D" to see all your system's network adapters and then use the name with the "-i" switch. In all cases, you can interrupt the capture with Control-C.
Steps to capture network traffic in Linux:Launch terminal. Identify the network interface that you want to capture the network traffic packets. Install tcpdump for your Linux distribution if it's not already installed. Run tcpdump against the network interface that you've selected.
Not directly a tcpdump, but can give you info about the network traffic, check https://bytefreaks.net/gnulinux/how-to-capture-all-network-traffic-of-a-single-process
strace -f -e trace=network -s 10000 <PROCESS WITH ARGUMENTS>;
If the process is already started and you know its PID you can use the following 1
strace -f -e trace=network -s 10000 -p <PID>;
Another alternative is more complex, using network namespaces, check the above link or use the tool nsntrace, but either can only work on new process, you can not change existent process network namespaces (AFAIK)
UPDATE: you can also install the tool bpfcc-tools (search for your distro, many have it included already) and use the command sudo tcptracer-bpfcc -v -p (PID)
While this will not show the packets, it will list network connections for that pid. You can remove the -p (PID)
to list all connections per process. This may be useful for those tracking short live connections, not the network payload.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With