Questions tagged [netstat]

netstat (network statistics) is a command-line tool that displays network connections (both incoming and outgoing), routing tables, and a number of network interface statistics. It is available on Unix, Unix-like, and Windows NT-based operating systems.

netstat

netstat (network statistics) is a command-line tool that displays network connections (both incoming and outgoing), routing tables, and a number of network interface statistics. It is available on Unix, Unix-like, and Windows NT-based operating systems. It is used for finding problems in the network and to determine the amount of traffic on the network as a performance measurement.

Parameters

Parameters used with this command must be prefixed with a hyphen (-) rather than a slash (/).

  • -a : Displays all active connections and the TCP and UDP ports on which the computer is listening.
  • -b : Displays the binary (executable) program's name involved in creating each connection or listening port. (Windows XP, 2003 Server and newer Windows operating systems (not Microsoft Windows 2000 or other non-Windows operating systems)) On Mac OS X when combined with -i, the total number of bytes of traffic will be reported.
  • -e : Displays ethernet statistics, such as the number of bytes and packets sent and received. This parameter can be combined with -s.
  • -f : Displays fully qualified domain names for foreign addresses (only available on Windows Vista and newer operating systems).
  • -g : Displays multicast group membership information for both IPv4 and IPv6 (may only be available on newer operating systems)
  • -i : Displays network interfaces and their statistics (not available under Windows)
  • -m : Displays the STREAMS statistics.
  • -n : Displays active TCP connections, however, addresses and port numbers are expressed numerically and no attempt is made to determine names.
  • -o : Displays active TCP connections and includes the process ID (PID) for each connection. You can find the application based on the PID on 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, 2003 Server (and Windows 2000 if a hotfix is applied).[2]
  • -p Windows and BSD: Protocol : Shows connections for the protocol specified by Protocol. In this case, the 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.
  • -p Linux: Process : Show which processes are using which sockets (similar to -b under Windows) (you must be root to do this)
  • -P Solaris: Protocol : Shows connections for the protocol specified by Protocol. In this case, the Protocol can be ip, ipv6, icmp, icmpv6, igmp, udp, tcp, or rawip.
  • -r : Displays the contents of the IP routing table. (This is equivalent to the route print command under Windows.)
  • -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.
  • -t Linux: Displays only TCP connections.
  • -v : When used in conjunction with -b it will display the sequence of components involved in creating the connection or listening port for all executables.
  • Interval : Redisplays the selected information every Interval seconds. Press CTRL+C to stop the redisplay. If this parameter is omitted, netstat prints the selected information only once.
  • -h (unix) /? (windows): Displays help at the command prompt.

Statistics Provided

Netstat provides statistics for the following:

Protocol - 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. 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 corresponds 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.

Examples

To display the statistics for only the TCP or UDP protocols, type one of the following commands:

netstat -sp tcp
netstat -sp udp

To display active TCP connections and the process IDs every 5 seconds, type the following command (On Microsoft Windows, works on XP and 2003 only, or Windows 2000 with hotfix):

netstat -o 5

Mac OS X version:

netstat -w 5

To display active TCP connections and the process IDs using numerical form, type the following command (On Microsoft Windows, works on XP and 2003 only, or Windows 2000 with hotfix):

netstat -no

To display all ports open by a process with id pid:

netstat -aop | grep "pid"

Platform specific remarks

On the Windows platform, netstat information can be retrieved by calling the GetTcpTable and GetUdpTable functions in the IP Helper API, or IPHLPAPI.DLL. Information returned includes local and remote IP addresses, local and remote ports, and (for GetTcpTable) TCP status codes. In addition to the command-line netstat.exe tool that ships with Windows, GUI-based netstat programs are available.

On the Windows platform, this command is available only if the Internet Protocol (TCP/IP) protocol is installed as a component in the properties of a network adapter in Network Connections.

On Mac OS X 10.5, the above option "-o" is not available. With Mac OS X 10.5, the /Applications/Utilities folder contains a network utility called: Network Utility, see tab Netstat for these stats presented in a gui application, along with Ping, Lookup, Traceroute, Whois, Finger and Port Scan.

Wikipedia Entry for netstat

548 questions
0
votes
3 answers

Netstat TCP status data logging script

I have a script that performs netstat -an calls to show TCP status for two ports (8080 and 5555). I have it print it out onto one row into a log file every minute. This is all fine and dandy but due to the nature of the traffic the status values…
Lawrence
  • 25
  • 1
  • 6
0
votes
0 answers

get the process name/id of the port number in netstat

I am using nestat command to check the port is free or not. netstat -alp | grep For a root user i am getting process name on which the port is used. I have logged in as test user and am using netstat command to check the port. But i am…
Shriram
  • 4,343
  • 8
  • 37
  • 64
0
votes
1 answer

Different processes showed as same PID within netstat

I spawn few processes using the Python multiprocessing module. However when I call netstat -nptl, each ip:port listeners listed under the same PID. I'm using Python 2.7 on Ubuntu 14.04. netstat -V >> net-tools 1.60 >> netstat 1.42…
triple fault
  • 13,410
  • 8
  • 32
  • 45
0
votes
1 answer

netstat -p flag not working

I'm trying to close some CLOSE_WAIT localhost processes, and so am trying to get their process id's using 'netstat -anp'. I've seen multiple posts recommending this, however, everytime I enter this command into terminal, i get this man page message:…
bgenchel
  • 3,739
  • 4
  • 19
  • 28
0
votes
1 answer

Python: Get data from netstat

Is there any module or easy way to access netstat data using Python script in Linux? I remember that in Perl you could just execute system("netstat -parameters") and save output into array, which isn't cleanest and finest way in my opinion. I…
user4839151
0
votes
2 answers

netstat command on a server (winform application)

I'm looking for how to recorgnize some server (windows in my case) network configuration (information we obtain using netstat dos command). I have the login and password of the target (server), and I developp with visual studio 2005 (c# or vB.NET…
bidak
  • 21
  • 7
0
votes
1 answer

Is it possible to deterministically trace how port 80 is forwarded and where the configuration is on a given system?

Is there a way to determine or trace how a port forwarding configuration is set up on a system running Ubuntu 14.04 LTS, on which there is a NodeJS service running and somehow accepting connections via port 80, although the service itself is running…
zealoushacker
  • 6,766
  • 5
  • 35
  • 44
0
votes
1 answer

netstat output differences from cygwin to mac

I was trying to parse the output of netstat on my mac today, and I used: netstat | egrep "*tcp*" It throws an error for for "operand invaliid", so I tried: netstat | egrep ".*tcp.*" ...which works great. Then I tried both of those commands in…
makansij
  • 9,303
  • 37
  • 105
  • 183
0
votes
0 answers

netstat -oe command with Recv-Q data (Linux)

I am seeing that the netstat -oe command shows that the column Recv-Q has some values in it long after the process that created it terminated. This connection is between IBM MDM Server (v10) and Oracle DB (v11). We have been running into the…
krish727
  • 303
  • 1
  • 3
  • 11
0
votes
2 answers

How does netstat determine symbolic hostname?

I was trying to understand what the --numeric/-n flag of netstat does? Manual says the following about --numeric/-n --numeric , -n Show numerical addresses instead of trying to determine symbolic host, port or user names. Following is a line of…
Karthick
  • 2,844
  • 4
  • 34
  • 55
0
votes
1 answer

why so many Avast listening processes show up on netstat?

I'm running Mac OSX. when I ran sudo lsof -i -P | grep -i "listen" I'm getting all these processes, is it normal? launchd 1 root 26u IPv6 0xc2e82557abee8b81 0t0 TCP localhost:631 (LISTEN) launchd 1 root…
SOU
  • 3
  • 1
0
votes
1 answer

Checking if a port is open through the firewall, that has no listener service actually listening

I have a Windows 2008 R2 server that will need to listen on a particular port (e.g. 1234) in order for an application upgrade to work, but currently the application doesn't have a listener service configured for port 1234. Our firewall is managed by…
Potatan
  • 29
  • 2
  • 8
0
votes
0 answers

How to inject statists of a "fake socket" so they will be seen by the user that run netstat

I have a userspace C library that transffers data using RDMA / Infiniband networks protocols. This data is not seen by netstat (and neither by IP layer in the kernel). However, my library holds a standard socket file descriptior as a "shadow…
avner
  • 775
  • 1
  • 8
  • 11
0
votes
2 answers

My express server says that ports 80 and 443 are in use, but `netstat -nlp` says otherwise

I try to run my Express server on ports 80 and 443, but I'm getting an error that they are already being used. EADDRINUSE err However, my Ubuntu server says that in fact ports 80 and 443 aren't busy: ubuntu@ip-182-47-78-432:~$ sudo netstat -nlp I…
bmpasini
  • 1,503
  • 1
  • 23
  • 43
0
votes
1 answer

Some odd TCP connections related to firefox

I run netstat -o in CMD and found Firefox has some TCP connection in my PC that are odd! There are two connection between 127.0.0.1(localhost) and Jessica-PC(my computer name) and I think they are equal ! (127.0.0.1 = Jessica-PC) I test netstat -a…
Jessica
  • 685
  • 1
  • 9
  • 23