blob: 6d2f8f8f4419f12d7ef7fdce198e31b2c8bca7cb [file] [log] [blame]
Brendan Greggf06d3b42015-10-15 17:21:32 -07001Demonstrations of tcpconnect, the Linux eBPF/bcc version.
2
3
4This tool traces the kernel function performing active TCP connections
5(eg, via a connect() syscall; accept() are passive connections). Some example
6output (IP addresses changed to protect the innocent):
7
Alexei Starovoitovbdf07732016-01-14 10:09:20 -08008# ./tcpconnect
Brendan Greggf06d3b42015-10-15 17:21:32 -07009PID COMM IP SADDR DADDR DPORT
Alexei Starovoitovbdf07732016-01-14 10:09:20 -0800101479 telnet 4 127.0.0.1 127.0.0.1 23
111469 curl 4 10.201.219.236 54.245.105.25 80
121469 curl 4 10.201.219.236 54.67.101.145 80
Brendan Gregg9e0b0872016-03-28 12:11:45 -0700131991 telnet 6 ::1 ::1 23
142015 ssh 6 fe80::2000:bff:fe82:3ac fe80::2000:bff:fe82:3ac 22
Brendan Greggf06d3b42015-10-15 17:21:32 -070015
16This output shows four connections, one from a "telnet" process, two from
17"curl", and one from "ssh". The output details shows the IP version, source
18address, destination address, and destination port. This traces attempted
19connections: these may have failed.
20
Brendan Greggf06d3b42015-10-15 17:21:32 -070021The overhead of this tool should be negligible, since it is only tracing the
22kernel functions performing connect. It is not tracing every packet and then
23filtering.
24
25
26The -t option prints a timestamp column:
27
28# ./tcpconnect -t
29TIME(s) PID COMM IP SADDR DADDR DPORT
3031.871 2482 local_agent 4 10.103.219.236 10.251.148.38 7001
3131.874 2482 local_agent 4 10.103.219.236 10.101.3.132 7001
3231.878 2482 local_agent 4 10.103.219.236 10.171.133.98 7101
3390.917 2482 local_agent 4 10.103.219.236 10.251.148.38 7001
3490.928 2482 local_agent 4 10.103.219.236 10.102.64.230 7001
3590.938 2482 local_agent 4 10.103.219.236 10.115.167.169 7101
36
37The output shows some periodic connections (or attempts) from a "local_agent"
38process to various other addresses. A few connections occur every minute.
39
40
41USAGE message:
42
43# ./tcpconnect -h
chantra52938052016-09-10 09:44:50 -070044usage: tcpconnect [-h] [-t] [-p PID] [-P PORT]
Brendan Greggf06d3b42015-10-15 17:21:32 -070045
46Trace TCP connects
47
48optional arguments:
49 -h, --help show this help message and exit
50 -t, --timestamp include timestamp on output
51 -p PID, --pid PID trace this PID only
chantra52938052016-09-10 09:44:50 -070052 -P PORT, --port PORT
53 comma-separated list of destination ports to trace.
Brendan Greggf06d3b42015-10-15 17:21:32 -070054
55examples:
56 ./tcpconnect # trace all TCP connect()s
57 ./tcpconnect -t # include timestamps
58 ./tcpconnect -p 181 # only trace PID 181
chantra52938052016-09-10 09:44:50 -070059 ./tcpconnect -P 80 # only trace port 80
60 ./tcpconnect -P 80,81 # only trace port 80 and 81