Program that can log network traffic by the process and domain names

monitoringnetworking

I would like to figure out which processes are communicating with which websites over a period of time. All what I found programs like ss that list the connections that open this instant and then exit.

What I, actually, want is something like wireshark, but one that would log process names.

Is there really no such a program?

Best Answer

If you have a recent kernel (preferably at least 4.9, but apparently some things work at 4.2), then you can take advantage of the new dtrace facility that allows you to intercept every tcp connect() call in the kernel and show the process id, remote ip address and port.

Since this does not poll, you will not miss any short-lived connections. From the Brendan Gregg blog of 2016 typical output is

# tcpconnect
PID    COMM    IP SADDR            DADDR            DPORT
1479   telnet  4  127.0.0.1        127.0.0.1        23
1469   curl    4  10.201.219.236   54.245.105.25    80
1469   curl    4  10.201.219.236   54.67.101.145    80
1991   telnet  6  ::1              ::1              23
2015   ssh     6  fe80::2000:bff:fe82:3ac fe80::2000:bff:fe82:3ac 22

Further examples are in the bcc-tools package source. Built packages to install are available for several distributions or you can follow the compilation instructions.

Related Question