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
28
votes
7 answers

How do I interpret 'netstat -a' output

Some things look strange to me: What is the distinction between 0.0.0.0, 127.0.0.1, and [::]? How should each part of the foreign address be read (part1:part2)? What does a state Time_Wait, Close_Wait mean? etc. Could someone give a quick overview…
Dane O'Connor
  • 75,180
  • 37
  • 119
  • 173
24
votes
2 answers

When using Docker, ESTABLISHED connections don't appear in netstat

I have a docker container running on RHEL 7 with Docker 1.7.0. The program which running in this container listens for TCP connections on port 5000. In my Dockerfile I put the sentence EXPOSE 5000 and I run the container with the following…
user1272178
  • 243
  • 1
  • 2
  • 5
24
votes
2 answers

Address already in use but nothing in netstat or lsof

I try to start the Python SimpleHTTPServer on port 7054 : $ sudo python -m SimpleHTTPServer 7054 ... socket.error: [Errno 98] Address already in use So, I ran the following commands : $ sudo netstat -ntpu | grep 7054 $ sudo lsof -i -n -P | grep…
pgmillon
  • 361
  • 1
  • 2
  • 6
22
votes
1 answer

TCP connection owned by pid zero

I'm trying to ensure that a Windows service program (running on top of .NET) is properly releasing its network connections. When running the service locally I know that it will create a lot of HTTP connections to localhost on port 57300. I'm using…
Mårten Wikström
  • 11,074
  • 5
  • 47
  • 87
21
votes
1 answer

Node.js server only listening on ipv6

I am running a node.js server on port 5403. I can telent to the private ip on this port but cannot telnet to the public ip on the same port. I assume the cause of this is because node.js is only listening on ipv6. This is the result of netstat…
codeyard
  • 327
  • 1
  • 2
  • 10
21
votes
1 answer

How do I access netstat data in Python?

I'm trying to need to access/parse all outgoing connections on a particular port number on a Linux machine using a Python script. The simplest implementation seems to be to open a subprocess for netstat and parse its stdout. I imagine someone…
Andrey Fedorov
  • 9,148
  • 20
  • 67
  • 99
19
votes
2 answers

Tracking an application's network statistics (netstats) using ADB

I have a feeling this is possible, I'm just not quite sure where the information is held. I want to get the up/down statistics for specific applications, but I want to do it using ADB and not wireshark or netty. I know I can see the vmData using…
Nefariis
  • 3,451
  • 10
  • 34
  • 52
17
votes
1 answer

netstat -na : udp and state established?

In an application (voip rtp media server), netstat -na on the server (172.16.226.3 bound to udp port 1286) gives the following line : udp 0 0 172.16.226.3:1286 172.25.14.11:10000 ESTABLISHED As an udp connection can not be really "established", it…
KWA
  • 858
  • 1
  • 7
  • 10
16
votes
1 answer

Network Activity Monitoring on iPhone

I've been working for 5 days trying to learn and implement Network monitor on the iPhone. I looked into netstat code from apple, and i lost like 25% of my hair. I found links for JB Devices but i need it to execute on a non JB device. (Irrespective…
Shrey
  • 1,959
  • 2
  • 21
  • 44
13
votes
5 answers

Process started from system command in C inherits parent fd's

I have a sample application of a SIP server listening on both tcp and udp ports 5060. At some point in the code, I do a system("pppd file /etc/ppp/myoptions &"); After this if I do a netstat -apn, It shows me that ports 5060 are also opened for…
Elison Niven
  • 236
  • 3
  • 12
13
votes
1 answer

What could cause so many TIME_WAIT connections to be open?

So, I have application A on one server which sends 710 HTTP POST messages per second to application B on another server, which is listening on a single port. The connections are not keep-alive; they are closed. After a few minutes, application A…
vmayer
  • 985
  • 2
  • 9
  • 18
13
votes
1 answer

How to kill the application that is using a TCP port in C#?

I want to free a TCP port during startup of my application (asking confirmation to user), how to get the PID number and then, if the user confirm, kill it? I know I can get this information by netstat, but how to do it in a script or better in a C#…
Tobia
  • 9,165
  • 28
  • 114
  • 219
13
votes
2 answers

listing multicast sockets

I am trying to list all opened multicast sockets on a linux system? netstat -g lists the groups joined though. Is there any other utility that I can use for this sake? Thanks a lot for the help.
13
votes
2 answers

How to find port number for a particular process id in unix?

In UNIX OS, how can I find the port number when i know the process name or pid ?
user1857216
  • 147
  • 1
  • 1
  • 3
12
votes
4 answers

What are the differences between lsof and netstat on linux?

I encounted a problem today: When I started HDP docker container, an error occured: listen tcp 0.0.0.0:8086: bind: address already in use According to error message, I know that port 8086 was already in use, so I tried some commands to determine…
Alec.Zhou
  • 417
  • 2
  • 4
  • 11
1
2
3
36 37