How to find which program or process is listening on a certain port in Linux?

My program reports that the port is already used.

How to find which program or process is listening on a certain port in Linux?

asked Mar 5, 2015 by Eric Z Ma (41,910 points)

1 Answer

 
Best answer

You can use netstat to do this. netstat can print network connections.

For example, to find which program is listing on port 9999

netstat -pln | grep 9999

You will need to use sudo to get more details, such as process names that are now owned by you.

sudo netstat -pln | grep 9999

Here, p makes netstat print process name, 'l' means "listening" and 'n' means numerical addresses instead of trying to determine symbolic host, port or user names.

If you are sure that the programming is using TCP or UDP, you can also add option t or u to filter out only TCP and UDP connections like

sudo netstat -ptln | grep 9999
sudo netstat -puln | grep 9999

For more details, please check netstat manual.

answered Mar 5, 2015 by Eric Z Ma (41,910 points)

Please log in or register to answer this question.

Copyright © SysTutorials. User contributions licensed under cc-wiki with attribution required.
Hosted on Dreamhost

...