How-To Determine Programs Using Open Port?

Posted by JD 01/03/2014 at 16:03

How can I determine which program is using an open port?

This question comes up all the time on forums and at LUG meetings. As usual, with Linux there are 100 different, correct answers. Here are two more of different capability.

lsof

sudo lsof -l -P|grep LISTEN

lsof – list open files. Requires admin-level access. Running it without sudo will show this.
grep – look for specific things in the output.

On most desktop systems, I’d expect to see only ntpd, sshd and cupsd in the list. Might see smbd and rpc.statd (NFS) too if those were setup.

netstat

Another option:

netstat --all --program|egrep -v unix|more

Shows much of the same information, just in a different format, but it also shows live connections outbound. Since this shows outbound connections, email, browser, IM and any socket connection within the same machine will show up too. Might need to use sudo on the netstat to see some programs, but at least most of the output does not need root.

So, how else can we find which programs are using open ports?