Today's article has you using 'netstat' to figure out which application is listening on a particular port...

KGIII

Super Moderator
Staff member
Gold Supporter
Joined
Jul 23, 2020
Messages
11,843
Reaction score
10,421
Credits
97,948
It's a pretty important thing to know. This almost could have fit in the security section of the site, 'cause you shouldn't have open ports unless you know why they're open. Of course, most open ports are benign, useful, and intended - you still need to be able to identify what is running on what port.


Feedback is awesome.
 


I use netstat for this a lot, because it's usually installed by default on most distro's.
But I also use...
lsof -i
to do this sometimes.
 
I use Debian 11, I installed netstat but the commands you give are not working, the cursor just go to the next line
 

I might cover that in a future article. There are a few ways to do this, and I just covered the one.

I use Debian 11, I installed netstat but the commands you give are not working, the cursor just go to the next line

You're doing something wrong - probably with the copy/paste part and then changing it to suit your computer. (You may first need to find out which open ports you have.)

For example, here's a non-generic command:

Code:
sudo netstat -ptnl | grep -w ':22'

If that's not the problem, this is probably it:

I think if it comes out blank, it means you don't have anything open on that port. I think... I just tried it with a port that has nothing running and it comes out blank.

So, if you used the command with port 22 and you don't actually have SSH (or something else on that port) running, you'll not get any data from stdout. Try it with a port you have that's open.

See:

 
I tried *** without '':'' and it returned the following:

Code:
~$ sudo netstat -ptnl | grep -w '***'
tcp        *      *********             **********               LISTEN
***/cupsd    
tcp6       *                        ****                    LISTEN

Is it OK to post this information or I will be hacked?
edit:God knows how I gonna survive in this world
 
Last edited:
@KGIII -- I have been meaning to get into this. Timely to do so, now. Thanks for your three linked and related articles on the topic! Very understandable and informative.
 
Is it OK to post this information or I will be hacked?

Post away. An open port doesn't mean easy ingress. But, that's cups - your printing port.

Very understandable and informative.

Happy to help. That's kinda why I do it. I also do it to save time - sorta... I'll often write stuff that I think might answer a question. Then, when someone asks that question, I have a link ready instead of typing it all out over and over again. It's largely me getting my notes online, in other words.
 

Members online


Top