Display established TCP connections inside the terminal.
Use the following command to check established TCP connections using Debian based distribution:
$ ss -o state established -t -p
Recv-Q Send-Q Local Address:Port Peer Address:Port 0 0 127.0.0.1:6379 127.0.0.1:55548 users:(("redis-server",pid=18324,fd=9)) timer:(keepalive,3min56sec,0) 0 0 192.168.88.240:44062 216.58.215.110:https users:(("chrome",pid=1131,fd=108)) timer:(keepalive,33sec,0) 0 0 192.168.88.240:59212 64.233.164.188:5228 users:(("chrome",pid=1131,fd=149)) timer:(keepalive,512ms,0) 0 0 192.168.88.240:38948 192.168.88.106:https users:(("firefox",pid=4015,fd=59)) timer:(keepalive,1.352ms,0) 0 0 192.168.88.240:58036 34.241.31.108:https users:(("chrome",pid=1131,fd=144)) timer:(keepalive,39sec,0) 0 0 127.0.0.1:55548 127.0.0.1:6379 users:(("python",pid=1744,fd=3)) 0 0 192.168.88.240:52300 52.30.45.198:https users:(("chrome",pid=1131,fd=284)) timer:(keepalive,7.560ms,0) 0 0 192.168.88.240:47432 34.214.70.161:https users:(("firefox",pid=4015,fd=50)) timer:(keepalive,6min22sec,0)
If you want nice-looking output, then use a longer version with printf, awk, and sed:
$ printf "%-15.15s %5s %20s %7.7s\n" "Process" "PID" "Destination IP" "Port" && \
sudo ss -o state established -t -p | \
sed -e 1d -e 's/^[0-9]*[ ]*[0-9]*[ ]*[0-9.]*:[a-z0-9]*[ ]*\([0-9.]*\):\([a-z0-9]*\).*users:(("\(.*\)",pid=\([0-9]*\),.*/\3\t\4\t\1\t\2/' | \
awk '{printf "%-15.15s %5s %20s %7.7s\n",$1,$2,$3,$4}'
Example output:
Process PID Destination IP Port
redis-server 18324 127.0.0.1 55548
chrome 1131 216.58.215.110 https
chrome 1131 64.233.164.188 5228
firefox 4015 192.168.88.106 https
chrome 1131 34.241.31.108 https
python 1744 127.0.0.1 6379
chrome 1131 52.30.45.198 https
firefox 4015 34.214.70.161 https
Simple as that.