Building Bash Muscle (2)

I’ve been writing quite a bit of PowerShell code. The huge difference between PowerShell and Bash is that when executing a command, PowerShell returns collections of objects not just texts. That said, I still need to build my Bash muscle because Bash is useful after all in Linux world.

Today, I’m going to see what process is listening to which port on the local machine. It’s really critical to know this when you are troubleshooting a service that’s having a problem. Execute the following command.

$ sudo netstat -tlup

-t means –tcp. -u means –udp. -l means –listening and -p means –program. Let me show you the actual screenshot of the result.

As you can see, it lists all the processes (programs) that are listening on the machine. If you grep this result, you will be able to narrow down the result more to find the process that’s listening to certain port. Let’s see what’s up with ssh.

$ netstat -tulp | grep ssh

It’s listening the port “ssh”. Well, ssh usually listens to the port 22 so translate that in your head. I wonder if there is a way to actually show 22… I don’t know right now.

When something is not working, the first thing you should do is if a process is even listening to the expected port. This command will help you troubleshoot any service that may be serving people.

Leave a Reply

Your email address will not be published.