How to check established TCP connections

To check established TCP connections using Ubuntu enter command:

ss  -o state established -t -p

If you want nice looking output then use longer version with printf, awk and sed:

printf "%-15.15s %5s %20s %7.7s\n" "Process" "PID" "Destination IP" "Port"&& ss  -o state established -t -p  | \
sed -e 1d -e 's/[0-9]*[\ ]\{2,10\}[0-9]*[\ ]\{2,20\}.*:[0-9]*[\ ]\{2,20\}\(.*\):\(.*\)[\ ]\{2,20\}.*:(("\(.*\)",\(.*\),[0-9]*))/\3\t\4\t\1\t\2/g' | \
awk '{printf "%-15.15s %5s %20s %7.7s\n",$1,$2,$3,$4}'

Example output:

Process           PID       Destination IP    Port
firefox          2495        74.125.79.120   https
firefox          2495       173.194.65.138     www
firefox          2495       213.241.88.216     www
firefox          2495        74.125.79.102   https
firefox          2495        74.125.79.132   https
firefox          2495        173.194.65.99   https
firefox          2495       173.194.65.147   https
firefox          2495       173.194.65.102     www
kio_http         5332       213.241.88.216     www
firefox          2495       173.194.65.147   https
firefox          2495       213.241.88.216     www
firefox          2495        74.125.79.120   https
kio_ftp          5341       89.161.173.250     ftp
Milosz Galazka's Picture

About Milosz Galazka

Milosz is a system administrator working for a successful Polish company and a long time supporter of Free Software Foundation and Debian operating system.

Gdansk, Poland https://sleeplessbeastie.eu