Netstat Tutorial
Netstat Tutorial
http://www.securitydocs.com/library/3318
What is netstat?
Netstat is a versatile tool catered for the windows platform by means of the MS-DOS (now a days referred to as "Command
Prompt") command line. Netstat is also used in other platforms and operating systems apart from Windows such as Unix and
Linux. In the following thesis I will demonstrate the security-oriented uses for this basic DOS and bash command designed for
the newbie.
Note: To access Command Prompt on Windows platforms simply left click the start icon, click run, type “command” or
“cmd” (without quotations) in the text box and select open.
When a user enters a single netstat the output should be similar to the following.
Figure 1.0
http://www.securitydocs.com/link.php?action=detail&id=3318&headerfooter=no 5/25/2005
Introduction to Netstat Tutorial Page 2 of 6
This command gives you a generic look at what ports are open on your system. Upon further analyzation you can identify
which protocol is in usage along with the ports, your PCs name, TCP/IP network connections, foreign address, local address
and the status of connection.
The characters under the title "Proto" indicate the protocol type, in this case the only connections present include TCP which
means that you and the remote host are communicating via TCP.
The local address specifies the name of your computer on the network along with the port number you are using to recieve
connections which is randomly generated.
The foreign address lists the remote host's name and the port they are using to initiate the connection.
The state of the connection indicates exactly what it says, the state of the connection between a remote system and yours.
Below lists all of the possible states of connection.
http://www.securitydocs.com/link.php?action=detail&id=3318&headerfooter=no 5/25/2005
Introduction to Netstat Tutorial Page 3 of 6
With these main states of connectivity covered appropriately I can go on to talk about netstat's switches. The result you
recieve after typing "netstat /?" (without quotations) in DOS is as follows.
Figure 1.1
A Switch Summary
The first switch, a, is used as the syntax below:
This command lists all active connections including listening ports, which is easily defined in figure 1.1.
E Switch Summary
The e switch is a bit more complicated, this lists the statistics of your internet connection, including how many packets were
sent, recieved or how many bytes were recieved for example.
N Switch Summary
The n switch is also fairly easy to understand, this lists all connections and remote computers in numerical form, this being in
IP form. For example if you are connected to IRC and you would like to view the server in numerical form, for whatever reason
that may be, you can use the n switch and it will transform the web address of it into an IP.
O Switch Summary
This switch lists active connections, combined with its PID (Process Identification Number).
P Switch Summary
The p switch gives the user the ability to filter through protocols including TCP, UDP, IP, ICMP, TCPv6, UDPv6, IPv6 and
ICMPv6.
R Switch Summary
The r switch lists information for your ethernet card, netmask, gateway, network destination, etc.
S Switch Summary
http://www.securitydocs.com/link.php?action=detail&id=3318&headerfooter=no 5/25/2005
Introduction to Netstat Tutorial Page 4 of 6
The s switch prints statistics for each protocol including the mentioned ones in the p switch to the screen. This switch can be
combined with the p switch in order to display specific statistics for each specified protocol, such as the following:
which lists the statistics for the TCP protocol, plus lists its active connections. This query can be narrowed down to an even
more specific or broader range of connections which will be descibed shortly.
this lists all connections (switch a) in numeric form (switch n) and spaces each netstat command 20 seconds (interval (20)). If
you were to enter this into DOS you would obtain a list of connections every 20 seconds, so as you can see, you do not need
to enter the switch "interval", only the time (in seconds).
There is no limit on how many switches you use once they are compatible with each other, for example using the n switch with
the r switch will yield no more results than a standard r switch.
Figure 1.2
http://www.securitydocs.com/link.php?action=detail&id=3318&headerfooter=no 5/25/2005
Introduction to Netstat Tutorial Page 5 of 6
The above image illustrates a netstat command help menu (which can also be accessed by typing man netstat). You can see
linux has a much wider range of switches for the netstat command as opposed to windows, which is the case with virtually all
linux-based commands, which is why linux has gained so much appeal.
Figure 1.3
http://www.securitydocs.com/link.php?action=detail&id=3318&headerfooter=no 5/25/2005
Introduction to Netstat Tutorial Page 6 of 6
As was shown earlier, dealing with the Windows netstat, here is netstat (without arguments or switches) in operation within a
Linux shell.
http://www.softpedia.com/public/cat/10/7/10-7-68.shtml
http://techrepublic.com.com/5100-6263-5149569.html
http://www.securitydocs.com/link.php?action=detail&id=3318&headerfooter=no 5/25/2005