05
Sep
07

netstat: the indispensable tool!

One of my best ever troubleshooting tool, sometimes I stuck in many difficult situations that are related to remote access or internal services/daemons healthiness. You can easily figure out what the problem is from this straightforward command.

netstat-an.png

As you can see, If you have many connections on you PC it will be very difficult to maintain all the result. Fortunately, you can paginate the results using “more” command.

netstat -an | more

In the preceding example, the FTP service runs on a TCP port 21. This means that the service is waiting for a connection request from any remote TCP.

You can also filter the given results using either find or findstr. By the way, findstr is much better than find since you can provide a regular expression for your search.

Checking a certain port number

So, let’s start with a simple scenario. I need to check the MS SQL Server default TCP port (1433):

netstat -an | find “1433″

Find command will filter the results from the netstat command and grabs only the specified string.

PID Concatenation

A serious problem arises from unknown ports, sometimes you modify a port number for a certain service “SSH for example” and after awhile you forgot what that port is, though you can open the *.conf file and snatch the actual values, I really prefer techie and neat solutions. In this case, I usually display the associated process ID with each connection.

netstat-ano.png

Now, you can easily seize that process and figure out where that hidden process is. Simply, by matching the same PID in the Windows Task Manager “taskmgr.exe”. Another good-looking idea is to use the tasklist in the command prompt:

tasklist /svc | find “3306″

This is not all about netstat, there are many other ideas. Grouping the statistics per-protocol, or listing for the new requests.


2 Responses to “netstat: the indispensable tool!”


  1. 1 Alawi Albr
    February 21, 2008 at 4:31 pm

    Good exploration of netstat by you geek. I though you’re developer and not Net Admin ;)

    Add to these netstat switches this one: netstat -bn. This will show you the process name (application binary) and its related connections (instead of the PID switch -o) so you can decide what to do to annoying processes immediately.

    Cheers,

    Alawi

  2. 2 geek
    February 22, 2008 at 9:57 am

    @Alawi:

    Thanks for the tip! really great, you know that I’m always inspired by a guru like you!

    I also prefer adding “-v” to the process name switch “-b”, by this, you will be able to trace each connection that is initiated by any process on the spot “you may check how many spywares you’ve got in your machine ;) ”.

    -Saleh


Leave a Reply