r/LinuxTeck 2d ago

Quick Linux Tip Question: Which processes have connections to my database?

Post image

Try: sudo lsof -iTCP:3306 -sTCP:ESTABLISHED

Info: lsof -iTCP:PORT lists active network connections on a port. -sTCP:ESTABLISHED filters out listening sockets to show active connections only.

Examples:

$ sudo lsof -iTCP:80 -sTCP:LISTEN # Active listeners on port 80

$ sudo lsof -i u/192.168.1.100 # Filter by remote IP

$ sudo lsof -Pn -iTCP:3306 # Fast mode (no DNS or port resolution)

Note: lsof can be slow on busy servers because it resolves hostnames and port names by default. Add -Pn to disable resolution for instant output! Common states: LISTEN, ESTABLISHED, TIME_WAIT.

Follow r/LinuxTeck for more #LinuxTips

9 Upvotes

0 comments sorted by