tcpconnect [-h] [-c] [-t] [-p PID] [-P PORT] [--cgroupmap MAPPATH] [--mntnsmap MAPPATH]
This tool traces active TCP connections (eg, via a connect() syscall; accept() are passive connections). This can be useful for general troubleshooting to see what connections are initiated by the local server.
All connection attempts are traced, even if they ultimately fail.
This works by tracing the kernel tcp_v4_connect() and tcp_v6_connect() functions using dynamic tracing, and will need updating to match any changes to these functions.
Since this uses BPF, only the root user can use this tool.
CONFIG_BPF and bcc.
Print usage message.
Include a timestamp column.
Count connects per src ip and dest ip/port.
- -p PID
Trace this process ID only (filtered in-kernel).
- -P PORT
Comma-separated list of destination ports to trace (filtered in-kernel).
- --cgroupmap MAPPATH
Trace cgroups in this BPF map only (filtered in-kernel).
Include a UID column.
- -u UID
Trace this UID only (filtered in-kernel).
- Trace all active TCP connections:
- Trace all TCP connects, and include timestamps:
# tcpconnect -t
- Trace PID 181 only:
# tcpconnect -p 181
- Trace ports 80 and 81 only:
# tcpconnect -P 80,81
- Trace all TCP connects, and include UID:
# tcpconnect -U
- Trace UID 1000 only:
# tcpconnect -u 1000
- Count connects per src ip and dest ip/port:
# tcpconnect -c
- Trace a set of cgroups only (see special_filtering.md from bcc sources for more details):
# tcpconnect --cgroupmap /sys/fs/bpf/test01
- Trace a set of mount namespaces only (see special_filtering.md from bcc sources for more details):
# tcpconnect --mntnsmap /sys/fs/bpf/mnt_ns_set
Time of the call, in seconds.
IP address family (4 or 6)
Source IP address.
Destination IP address.
Accumulated active connections since start.
This traces the kernel tcp_v_connect functions and prints output for each event. As the rate of this is generally expected to be low (< 1000/s), the overhead is also expected to be negligible. If you have an application that is calling a high rate of connect()s, such as a proxy server, then test and understand this overhead before use.
This is from bcc.
Also look in the bcc distribution for a companion _examples.txt file containing example usage, output, and commentary for this tool.
Unstable - in development.
tcptracer(8), tcpaccept(8), funccount(8), tcpdump(8)