1tcpconnect(8)               System Manager's Manual              tcpconnect(8)
2
3
4

NAME

6       tcpconnect  -  Trace  TCP  active  connections  (connect()). Uses Linux
7       eBPF/bcc.
8

SYNOPSIS

10       tcpconnect [-h] [-c] [-t]  [-p  PID]  [-P  PORT]  [-L]  [-u  UID]  [-U]
11       [--cgroupmap MAPPATH] [--mntnsmap MAPPATH] [-d]
12

DESCRIPTION

14       This  tool  traces active TCP connections (eg, via a connect() syscall;
15       accept() are passive connections). This can be useful for general trou‐
16       bleshooting to see what connections are initiated by the local server.
17
18       All connection attempts are traced, even if they ultimately fail.
19
20       This  works by tracing the kernel tcp_v4_connect() and tcp_v6_connect()
21       functions using dynamic tracing, and will need updating  to  match  any
22       changes to these functions.
23
24       When  provided  with the -d or --dns option, this tool will also corre‐
25       late connect calls with the most recent DNS query that matches  the  IP
26       connected.   This  feature  works  by  tracing the kernel udp_recvmsg()
27       function to collect DNS responses.
28
29       Since this uses BPF, only the root user can use this tool.
30

REQUIREMENTS

32       CONFIG_BPF and bcc.
33
34       If using the -d or --dns option, you  must  have  the  dnslib  and  ca‐
35       chetools  python packages installed.  You can install them with pip3 or
36       with apt on Ubuntu 18.04+  using  the  python3-dnslib  and  python3-ca‐
37       chetools packages.
38

OPTIONS

40       -h     Print usage message.
41
42       -t     Include a timestamp column.
43
44       -c     Count connects per src ip and dest ip/port.
45
46       -p PID Trace this process ID only (filtered in-kernel).
47
48       -P PORT
49              Comma-separated list of destination ports to trace (filtered in-
50              kernel).
51
52       -L     Include a LPORT column.
53
54       -U     Include a UID column.
55
56       -u UID Trace this UID only (filtered in-kernel).
57
58       --cgroupmap MAPPATH
59              Trace cgroups in this BPF map only (filtered in-kernel).
60
61       --mntnsmap  MAPPATH
62              Trace mount namespaces in this BPF map  only  (filtered  in-ker‐
63              nel).
64
65       -d     Shows  the  most recent DNS query for the IP address in the con‐
66              nect call.  This is likely related to the TCP connection details
67              in the other columns, but is not guaranteed.  This feature works
68              by tracing the udp_recvmsg kernel function and tracking DNS  re‐
69              sponses  received by the server.  It only supports UDP DNS pack‐
70              ets up to 512 bytes in length.  The python code keeps a cache of
71              10k DNS responses in memory for up 24 hours.
72
73              If  the  time difference in milliseconds between when the system
74              received a DNS response and when a connect  syscall  was  traced
75              using  an  IP  in  that DNS response is greater than 100ms, this
76              tool will report this  delta  after  the  query.   These  deltas
77              should  be relatively short for most applications.  A long delay
78              between the response and connect could be either  anomalous  ac‐
79              tivity  or  indicate  a  misattribution between the DNS name re‐
80              quested and the IP that the connect syscall is using.
81
82              The -d option may not be used with the count feature (option -c)
83

EXAMPLES

85       Trace all active TCP connections:
86              # tcpconnect
87
88       Trace all TCP connects, and include timestamps:
89              # tcpconnect -t
90
91       Trace all TCP connects, and include most recent matching DNS query  for
92       each connected IP
93              # tcpconnect -d
94
95       Trace PID 181 only:
96              # tcpconnect -p 181
97
98       Trace ports 80 and 81 only:
99              # tcpconnect -P 80,81
100
101       Trace all TCP connects, and include LPORT:
102              # tcpconnect -L
103
104       Trace all TCP connects, and include UID:
105              # tcpconnect -U
106
107       Trace UID 1000 only:
108              # tcpconnect -u 1000
109
110       Count connects per src ip and dest ip/port:
111              # tcpconnect -c
112
113       Trace  a set of cgroups only (see special_filtering.md from bcc sources
114       for more details):
115              # tcpconnect --cgroupmap /sys/fs/bpf/test01
116
117       Trace a set of mount namespaces only (see special_filtering.md from bcc
118       sources for more details):
119              # tcpconnect --mntnsmap /sys/fs/bpf/mnt_ns_set
120

FIELDS

122       TIME(s)
123              Time of the call, in seconds.
124
125       UID    User ID
126
127       PID    Process ID
128
129       COMM   Process name
130
131       IP     IP address family (4 or 6)
132
133       SADDR  Source IP address.
134
135       LPORT  Source port
136
137       DADDR  Destination IP address.
138
139       DPORT  Destination port
140
141       CONNECTS
142              Accumulated active connections since start.
143
144       QUERY  Shows  the  most recent DNS query for the IP address in the con‐
145              nect call.  This is likely related to the TCP connection details
146              in the other columns, but is not guaranteed.
147

OVERHEAD

149       This  traces  the  kernel tcp_v[46]_connect functions and prints output
150       for each event. As the rate of this is generally expected to be low  (<
151       1000/s), the overhead is also expected to be negligible. If you have an
152       application that is calling a high rate of connect()s, such as a  proxy
153       server, then test and understand this overhead before use.
154
155       If  you  are  using the -d option to track DNS requests, this tool will
156       trace the udp_recvmsg function and generate an event  for  any  packets
157       from  UDP  port  53.   This  event  contains up to 512 bytes of the UDP
158       packet payload.  Typical applications do not extensively  use  UDP,  so
159       the  performance overhead of tracing udp_recvmsg is expected to be neg‐
160       ligible,   However, if you have an application that receives  many  UDP
161       packets,  then  you  should test and understand the overhead of tracing
162       every received UDP message.  Furthermore, performance overhead of  run‐
163       ning  this  tool  on a DNS server is expected to be higher than average
164       because all DNS response packets will be copied to userspace.
165

SOURCE

167       This is from bcc.
168
169              https://github.com/iovisor/bcc
170
171       Also look in the bcc distribution for a  companion  _examples.txt  file
172       containing example usage, output, and commentary for this tool.
173

OS

175       Linux
176

STABILITY

178       Unstable - in development.
179

AUTHOR

181       Brendan Gregg
182

SEE ALSO

184       tcptracer(8), tcpaccept(8), funccount(8), tcpdump(8)
185
186
187
188USER COMMANDS                     2020-02-20                     tcpconnect(8)
Impressum