NETSTAT COMMAND

Last Edited

by

in

,

NETSTAT which stands for NETwork STATistics is a TCP/IP utility that displays the current TCP/IP connectivity status and statistics.

Netstat is available on a computer running Microsoft Windows if the TCP/IP protocol stack has been installed on that machine.

You can run netstat from the command prompt to get current TCP/IP statistics and connections for the local machine. You can also view statistics on a per-protocol basis for Transmission Control Protocol (TCP), User Datagram Protocol (UDP), Internet Protocol (IP), or Internet Control Message Protocol (ICMP).

netstat command

Netstat provides information on:

  • IP addresses and port numbers of TCP/IP connections, including client and server connections. Either host names or IP addresses can be displayed. For example, netstat -a displays all connections and listening ports (for TCP and UDP).
  • Ethernet statistics, including bytes sent and received, directed and broadcast frames sent and received, discards, and errors.
  • The routing table for the local machine.

The meaning of the output table

Proto: The name of the protocol (TCP or UDP).

Local Address: The IP address of the local computer and the port number being used. The name of the local computer that corresponds to the IP address and the name of the port is shown unless the -n parameter is specified. An asterisk (*) is shown for the host if the server is listening on all interfaces. If the port is not yet established, the port number is shown as an asterisk.

Foreign Address: The IP address and port number of the remote computer to which the socket is connected. The names that correspond to the IP address and the port are shown unless the -n parameter is specified. If the port is not yet established, the port number is shown as an asterisk (*).

State: Indicates the state of a TCP connection. The possible states are as follows: CLOSE_WAIT, CLOSED, ESTABLISHED, FIN_WAIT_1, FIN_WAIT_2, LAST_ACK, LISTEN, SYN_RECEIVED, SYN_SEND, and TIME_WAIT. For more information about the states of a TCP connection, see RFC 793.

NETSTAT command parameters

Netstat admits several parameters preceded by a hyphen (-). Some parameters are exclusives to one operating system. Here are the most common:

netstat -a : Displays all active connections and the TCP and UDP ports on which the computer is listening.

netstat -b : Displays the binary (executable) program’s name involved in creating each connection or listening port. (Windows XP, Windows Server 2003, and newer Windows operating systems; not Microsoft Windows 2000 or older).

netstat -e : Displays ethernet statistics, such as the number of bytes and packets sent and received. This parameter can be combined with -s.

netstat -f : Displays fully qualified domain names for foreign addresses (only available on Windows Vista and newer operating systems).

netstat -g : Displays multicast group membership information for both IPv4 and IPv6 (may only be available on newer operating systems).

netstat -i : Displays network interfaces and their statistics.

netstat -m : Displays the memory statistics for the networking code (STREAMS statistics on Solaris).

netstat -n : Displays active TCP connections, however, addresses and port numbers are expressed numerically and no attempt is made to determine names.

netstat -o : Displays active TCP connections and includes the process id (PID) for each connection. You can find the application based on the PID in the Processes tab in Windows Task Manager. This parameter can be combined with -a, -n, and -p. This parameter is available on Microsoft Windows XP, Windows Server 2003, and Windows 2000 if a hotfix is applied.

netstat -p [protocol] : Shows connections for the protocol specified by protocol. In this case, protocol can be tcp, udp, tcpv6, or udpv6. If this parameter is used with -s to display statistics by protocol, protocol can be tcp, udp, icmp, ip, tcpv6, udpv6, icmpv6, or ipv6.

netstat -p : Show which processes are using which sockets (similar to -b under Windows) (you must be root to do this).

netstat -r : Displays the contents of the IP routing table. (This is equivalent to the route print command under Windows.)

netstat -s : Displays statistics by protocol. By default, statistics are shown for the TCP, UDP, ICMP, and IP protocols. If the IPv6 protocol for Windows XP is installed, statistics are shown for the TCP over IPv6, UDP over IPv6, ICMPv6, and IPv6 protocols. The -p parameter can be used to specify a set of protocols.

netstat -h : Displays help (or netstat -?).

References

Search