Recent from talks
Nothing was collected or created yet.
Netstat
View on WikipediaThis article needs additional citations for verification. (August 2012) |
| netstat | |
|---|---|
The netstat command in Linux | |
| Developers | Various open-source and commercial developers |
| Initial release | 1983 |
| Written in | Plan 9: C |
| Operating system | Unix, Unix-like, Plan 9, Inferno, OS/2, Microsoft Windows, ReactOS |
| Platform | Cross-platform |
| Type | Command |
| License | OS/2, Windows: Proprietary commercial software net-tools, ReactOS: GPLv2 Plan 9: MIT License |
In computing, netstat is a command-line network utility that displays open network sockets, routing tables, and a number of network interface (network interface controller or software-defined network interface) and network protocol statistics. It is available on Unix, Plan 9, Inferno, and Unix-like operating systems including macOS, Linux, Solaris and BSD. It is also available on IBM OS/2 and on Microsoft Windows NT-based operating systems including Windows XP, Windows Vista, Windows 7, Windows 8 and Windows 10.
It is used for finding problems in the network and to determine the amount of traffic on the network as a performance measurement.[1] On Linux this program is mostly obsolete, although still included in many distributions.
On Linux, netstat (part of "net-tools") is superseded by ss (part of iproute2). The replacement for netstat -r is ip route, the replacement for netstat -i is ip -s link, and the replacement for netstat -g is ip maddr, all of which are recommended instead.[2][3][4][5]
Statistics provided
[edit]Netstat provides statistics for the following:
- Proto – The name of the protocol (TCP, UDP, etc.). On some systems, the protocol name may be followed by "4" or "6", depending on whether the protocol is running over IPv4 or IPv6.
- 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
-nparameter 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 corresponds to the IP address and the port are shown unless the
-nparameter 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.
Parameters
[edit]Parameters used with this command must be prefixed with a hyphen (-) rather than a slash (/). Some parameters are not supported on all platforms.
| Name | Description | Windows | ReactOS | macOS | BSD | NetBSD | FreeBSD | Linux | Solaris | OS/2 |
|---|---|---|---|---|---|---|---|---|---|---|
| -a | Displays all active connections and the TCP and UDP ports on which the computer is listening. | Yes | Yes | Yes | Yes | Yes | Yes | |||
| -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). | Yes | No | No | ||||||
| -b | Causes -i to report the total number of bytes of traffic. | No | Yes | Yes | No | |||||
| -e | Displays ethernet statistics, such as the number of bytes and packets sent and received. This parameter can be combined with -s. | Yes | Yes | No | ||||||
| -f | Displays fully qualified domain names <FQDN> for foreign addresses (only available on Windows Vista and newer operating systems). | Yes | No | No | ||||||
| -f Address Family | Limits display to a particular socket address family, unix, inet, inet6 | No | Yes | No | ||||||
| -g | Displays multicast group membership information for both IPv4 and IPv6 (may only be available on newer operating systems) | No | No | Yes | ||||||
| -i | Displays network interfaces and their statistics | No | No | Yes | Yes | Yes | Yes | Yes | ||
| -m | Displays the memory statistics for the networking code (STREAMS statistics on Solaris). | No | No | Yes | Yes | Yes | Yes | Yes | ||
| -n | Displays active TCP connections, however, addresses and port numbers are expressed numerically and no attempt is made to determine names. | Yes | Yes | Yes | Yes | Yes | Yes | Yes | Yes | |
| -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.[6] | Yes | No | No | ||||||
| -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. | Yes | Yes | Yes | Yes | Yes | Yes | |||
| -p | Show which processes are using which sockets (similar to -b under Windows) (you must be root to do this) | No | No | Yes | ||||||
| -P protocol | Shows connections for the protocol specified by protocol. In this case, protocol can be ip, ipv6, icmp, icmpv6, igmp, udp, tcp, or rawip. | No | No | Yes | ||||||
| -r | Displays the contents of the IP routing table. (This is equivalent to the route print command under Windows.) | Yes | Yes | Yes | Yes | Yes | Yes | Yes | Yes | Yes |
| -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. | Yes | Yes | Yes | Yes | Yes | Yes | Yes | Yes | |
| -t | Display only TCP connections. | No | Yes | Yes | ||||||
| -u | Display only UDP connections. | No | No | Yes | Yes | |||||
| -W | Display wide output - doesn't truncate hostnames or IPv6 addresses | No | No | Yes | No | |||||
| -x | Displays NetworkDirect connections, listeners, and shared endpoints. | Yes | ||||||||
| -y | Displays the TCP connection template for all connections.Cannot be combined with the other options. | Yes | ||||||||
| -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. | Yes | No | No | ||||||
| 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. | Yes | Yes | No | ||||||
| -h | Displays help at the command prompt. | Yes | No | Yes | Yes | Yes | Yes | Yes | Yes | No |
| -? | Displays help at the command prompt. | Yes | No | No | No | No | No | No | No | Yes |
| /? | Displays help at the command prompt. | Yes | Yes | No | No | No | No | No | No | No |
Examples
[edit]Cross platform
[edit]On macOS, BSD systems, Linux distributions, and Microsoft Windows:
To display the statistics for only the TCP or UDP protocols, type one of the following commands:
netstat -sp tcp
netstat -sp udp
Unix-like
[edit]On Unix-like systems:
To display all ports open by a process with id pid:
netstat -aop | grep "pid"
To continuously display open TCP and UDP connections numerically and also which program is using them on Linux:
netstat -nutpacw
Windows
[edit]On Microsoft Windows:
To display active TCP connections and the process IDs every 5 seconds, type the following command (works on NT based systems only, or Windows 2000 with hotfix):
netstat -o 5
To display active TCP connections and the process IDs using numerical form, type the following command (works on NT based systems only, or Windows 2000 with hotfix):
netstat -no
*nix
[edit]| Command | Explanation |
|---|---|
netstat -a |
Shows all sockets, both listening and non-listening, all protocols like TCP, UDP etc. |
netstat -at |
Shows only TCP connections (-au shows only UDP connections) |
netstat -ant |
Shows all TCP connections with no DNS resolution (show IP addresses instead). |
netstat -al |
Shows only listening sockets. |
netstat -aep |
Also show PID and to which program each socket belongs, e adds extra info like the user. Run as root to see all PIDs. |
netstat -s |
Shows network statistics. |
netstat -r |
Shows kernel routing information. This is the same output as route -e. |
netstat -i |
Displays a table of all network interfaces. Add -e to get output similar to ifconfig. |
netstat -ct |
Displays TCP connections continuously. |
netstat -g
|
Display multicast group membership information for IPv4 and IPv6. |
netstat -lntu
|
Display all services listening for TCP and UDP, all free open ports on the local machine. |
netstat -atnp | grep ESTA
|
Displays all currently "established" TCP connections. |
Wildcards
[edit]Netstat uses an asterisk * as a wildcard which means "any". An example would be
Example output:
....Local Address Foreign Address State
... *:smtp *:* LISTEN
Under "Local Address" *, in *:smtp, means the process is listening on all of the network interfaces the machine has for the port mapped as smtp (see /etc/services for service resolution). This can also be shown as 0.0.0.0.
The first *, in *:*, means connections can come from any IP address, and the second *, in *:*, means the connection can originate from any port on the remote machine.
Caveats
[edit]Some versions of netstat lack explicit field delimiters in their printf-generated output, leading to numeric fields running together and thus corrupting the output data.
Platform specific remarks
[edit]
netstat command
netstat commandUnder Linux, raw data can often be obtained from the /proc/net/dev to work around the printf output corruption arising in netstat's network interface statistics summary, netstat -i, until such time as the problem is corrected.[citation needed]
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 the Windows platform running Remote Desktop Services (formerly Terminal Services) it will only show connections for the current user, not for the whole computer.
On macOS, the /System/Library/CoreServices/Applications folder (or /Applications/Utilities in OS X Mountain Lion and earlier) contains a network GUI utility called Network Utility, the Netstat tab of which runs the netstat command and displays its output in the tab.
See also
[edit]References
[edit]- ^ "IBM Systems Information Center". ibm.com. 8 May 2007.
- ^ "net-tools". linuxfoundation.org. Archived from the original on 2016-06-11. Retrieved 2014-08-02.
- ^ "Arch Linux". archlinux.org. 8 June 2011.
- ^ "Deprecated Linux networking commands and their replacements". Doug Vitale Tech Blog. 21 December 2011.
- ^ "netstat man page (notes section)". Retrieved 2 August 2014.
This program is obsolete. Replacement for netstat is ss. Replacement for netstat -r is ip route. Replacement for netstat -i is ip -s link. Replacement for netstat -g is ip maddr.
- ^ "The netstat command can now display process IDs that correspond to active TCP or UDP connections in Windows 2000". Archived from the original on 24 August 2007.
Further reading
[edit]- Dyson, Peter (1995). Mastering OS/2 Warp. Sybex. ISBN 978-0782116632.
- Stanek, William R. (2008). Windows Command-Line Administrator's Pocket Consultant, 2nd Edition. Microsoft Press. ISBN 978-0735622623.
External links
[edit]- – Linux Programmer's Manual – Administration and Privileged Commands from Manned.org
- – FreeBSD General Commands Manual
- – Solaris 11.4 System Administration Commands Reference Manual
- – Inferno General commands Manual
- Microsoft Learn: Netstat – documentation for the Windows netstat.exe command-line program
- net-tools project page on SourceForge
- Netstat Command Archived 2022-01-15 at the Wayback Machine: WindowsCMD.com Archived 2022-01-11 at the Wayback Machine
Netstat
View on Grokipedia-r flag reveals the IP routing table, including destinations, gateways, and interface details.[1] In Windows environments, netstat supports interval-based refreshes for continuous monitoring and can identify executables responsible for network usage, aiding in security audits and performance optimization.[2] Although netstat remains widely used for its simplicity and broad compatibility, modern alternatives like the ss command in Linux have emerged for more efficient querying, reflecting evolving network management needs.[1]
Overview
Description
Netstat is a command-line utility that displays network connections (both active and passive), routing tables, interface statistics, and multicast memberships. On Unix-like systems such as Linux, it also shows masquerade connections.[4] On Unix-like systems such as Linux, it is part of the net-tools package, a collection of legacy networking utilities.[5] On Windows, netstat is a built-in command available in the Command Prompt.[2] The tool plays a key role in network diagnostics by allowing users to monitor active sockets, examine protocol statistics, and identify potential connectivity issues, such as open ports or routing problems.[6] It enables administrators and users to inspect the state of network interfaces and connections without needing specialized hardware.[7] Netstat originated in early Unix systems, introduced as a new program in the 4.2BSD release in 1983 to display network statistics and active connections.[8] It has since evolved into a widely adopted tool across various Unix-like operating systems. Operating at the user level, netstat queries kernel data structures via system calls, and its basic output requires no root privileges, though certain advanced options may do so.[1]History
netstat was first introduced in the 4.2BSD release of Unix in August 1983, as a utility to display network-related data structures, particularly in conjunction with the new Berkeley sockets interface for interprocess communication over networks.[9] This implementation provided essential visibility into active sockets, protocol statistics, and routing tables, supporting the growing adoption of TCP/IP in academic and research environments during the early 1980s.[10] It was later adopted in other Unix-like systems, including System V derivatives and modern BSD variants like FreeBSD and macOS. In the Linux ecosystem, netstat became available through the net-tools package, which originated from the NET-2 networking distribution and was integrated into Linux distributions starting in the early 1990s to manage the kernel's evolving networking subsystem.[11] The package, including netstat, arp, and ifconfig, was maintained as a standard set of utilities for Linux kernel versions from 2.0 onward, with compatibility extending to kernel 2.2 in 1999, though limitations emerged with advanced features like IPv6.[12] By the 2010s, amid discussions on modernization, the Linux Foundation and distributions began deprecating net-tools in favor of iproute2 utilities, citing outdated code and performance issues, though netstat remained installable as a legacy tool.[13] Microsoft incorporated netstat into its TCP/IP protocol suite with the release of Windows NT 3.1 on July 27, 1993, enabling administrators to monitor connections and statistics on enterprise workstations and servers.[2] Subsequent Windows versions, including NT 4.0, Windows 2000, and modern releases like Windows 10 and 11, retained and enhanced netstat, integrating it with evolving networking stacks while introducing alternatives such as PowerShell cmdlets (e.g., Get-NetTCPConnection, available since PowerShell 3.0 in 2012) for more scriptable network diagnostics.[14] As of 2025, netstat continues to be a bundled utility in Windows environments, providing cross-platform consistency with its Unix roots despite the rise of specialized tools.[2]Functionality
Statistics Provided
Netstat retrieves and displays a range of network-related statistics, focusing on active connections, routing information, interface performance, and additional protocol details. These statistics offer insights into the current state of network activity, helping administrators monitor connectivity, traffic flow, and potential issues without delving into lower-level kernel data.[1][2] Active internet connections form one of the core outputs, enumerating TCP and UDP sockets in various states. For TCP connections, it shows established sessions, listening ports, and transient states like SYN_SENT (indicating outgoing connection attempts), along with local and remote addresses, ports, and connection states such as ESTABLISHED or LISTEN. UDP sockets, being connectionless, display only local addresses and ports, without states. This data aids in identifying open ports and active communications.[1][2][15] The routing table output lists IP routes, including the destination network, gateway (next hop), interface used, and flags denoting route properties—such as U for active (up) routes and G for those requiring a gateway. This provides a snapshot of the system's forwarding paths for traffic.[1][2] Interface statistics detail per-network-interface metrics, such as total bytes and packets received and transmitted, along with error counts (e.g., input/output errors) and collision rates for Ethernet interfaces like eth0. These counters accumulate over time, reflecting overall interface health and utilization.[1][7][2] Additional data includes Unix domain sockets, which show local inter-process communications with fields like reference count, type (e.g., stream), state, and socket paths; IP multicast group memberships, listing interfaces joined to multicast addresses; masquerade connections, which display network address translation (NAT) details such as original and reply addresses when using options like -M on Linux systems; and protocol-specific statistics, such as ICMP message counts including errors like destination unreachable. When invoked with appropriate parameters, netstat can include the process ID (PID) and program name for socket-owning applications, facilitating identification of resource consumers.[1][15]Output Formats
The output of the netstat command is primarily presented in human-readable text format, consisting of tabular displays with headers and columns that vary depending on the specified options, such as active connections, routing tables, or interface statistics.[1] These formats are designed for manual inspection by network administrators, with columns aligned for readability in terminal environments.[16] For active Internet connections (typically invoked with options like -t for TCP or -u for UDP), the standard output format features the following columns:| Column | Description |
|---|---|
| Proto | The protocol in use, such as tcp, udp, or raw.[1] |
| Recv-Q | The receive queue size in bytes (for established connections) or the SYN backlog queue (for listening sockets).[1] |
| Send-Q | The send queue size in bytes (for established connections) or the maximum SYN backlog (for listening sockets).[1] |
| Local Address:Port | The local IP address and port number, separated by a colon (e.g., 0.0.0.0:80).[1] |
| Foreign Address:Port | The remote IP address and port number for the connection (e.g., 192.168.1.1:12345), or : for listening sockets.[1] |
| State | The connection state, such as LISTEN (waiting for incoming connections), ESTABLISHED (active data transfer), SYN_SENT (connection initiation), or TIME_WAIT (closing phase).[1] |
| Column | Description |
|---|---|
| Destination | The destination network or host (e.g., 192.168.1.0 or default).[17] |
| Gateway | The gateway address for routing packets, or * if directly connected.[17] |
| Genmask | The netmask (e.g., 255.255.255.0).[17] |
| Flags | Route flags, such as U (route is up), G (uses gateway), H (target is host), or D (dynamically installed).[17] |
| MSS | Maximum segment size for TCP (e.g., 1500).[17] |
| Window | TCP window size (e.g., 32768).[17] |
| irtt | Initial round-trip time estimate in milliseconds (e.g., 100).[17] |
| Iface | The outgoing network interface (e.g., eth0).[17] |
| Column | Description |
|---|---|
| Iface | The interface name (e.g., lo or eth0).[16] |
| MTU | Maximum transmission unit in bytes (e.g., 1500).[16] |
| RX-OK | Packets received without errors.[16] |
| RX-ERR | Packets received with errors.[16] |
| RX-DRP | Packets dropped during reception (e.g., due to buffer overflow).[16] |
| TX-OK | Packets transmitted successfully.[16] |
| TX-ERR | Packets transmitted with errors.[16] |
| TX-DRP | Packets dropped during transmission.[16] |
| Type | The interface hardware type (e.g., ethernet or loopback), though not always displayed in basic output.[16] |
Usage
Common Parameters
The netstat command supports several parameters that are widely shared across Unix-like systems and Windows, enabling users to customize output for network diagnostics. These options control the scope of displayed information, such as connections, routing, and statistics, and are typically case-sensitive on Unix-like systems.[1][2] The-a parameter displays all sockets, including both listening and non-listening ones, providing a complete view of active and potential network endpoints.[1] On Unix-like systems, it shows detailed socket states; on Windows, it includes all TCP connections and listening UDP ports.[2]
The -r parameter outputs the kernel routing table, listing routes for network traffic forwarding.[1] This is equivalent to the route command's verbose output and is consistent across platforms, showing destination, gateway, and interface details.[2]
The -i parameter presents interface statistics, including a table of network interfaces with packet counts, errors, and transmission metrics.[1] It is primarily used on Unix-like systems, where it helps monitor interface performance.[19]
The -n parameter enforces numeric output, displaying addresses, ports, and hosts as numbers without attempting DNS resolution, which speeds up execution and avoids resolution delays.[1] This option is standard on both Unix-like systems and Windows for precise, hostname-free results.[2]
On Unix-like systems, -t limits output to TCP sockets, -u to UDP sockets, -l to listening sockets only, and -p to include the process ID (PID) and program name associated with each socket, requiring elevated privileges for full visibility.[1] These protocol and process filters enhance targeted analysis.[19]
The -s parameter generates per-protocol statistics summaries, detailing metrics like packets sent, received, and errors for protocols such as TCP, UDP, and IP.[1] It provides aggregated data without individual connection details and is available on Windows as well.[2]
An interval option, such as netstat -i 1 on Unix-like systems, enables continuous updates by redisplaying the selected statistics (e.g., interface data) every specified seconds, useful for real-time monitoring until interrupted.[1] On Windows, a similar effect is achieved by appending a number directly, like netstat -s 1.[2]
Parameters on Unix-like systems are case-sensitive, distinguishing uppercase variants like -A from lowercase, and can be combined for refined queries, such as netstat -anp to show all numeric TCP/UDP sockets with associated processes.[1] Platform-specific extensions, like additional filters on Windows, build upon these core options.[2]
Platform-Specific Options
On Unix-like systems such as Linux and BSD derivatives, netstat includes options that leverage kernel-specific networking features like IP masquerading and multicast handling. The -M option lists masquerade connections, useful for inspecting NAT translations in firewall configurations.[1] The -g option displays multicast group memberships for both IPv4 and IPv6 addresses, aiding in the diagnosis of group communication issues.[1] Additionally, the -e option extends the output with details like user IDs and inode numbers for sockets, which can be invoked twice for fuller information.[1] The -c option runs netstat in continuous mode, refreshing output every second to monitor dynamic network changes.[1] In modern Linux distributions, netstat from the deprecated net-tools package often issues warnings recommending alternatives like ss or ip from iproute2.[1] Windows implementations of netstat provide options optimized for its Winsock API and TCP/IP stack, emphasizing process association and hardware-level metrics. The -e option outputs Ethernet interface statistics, such as total bytes and packets transmitted or received, which can combine with -s for protocol-specific breakdowns.[2] The -f option resolves foreign addresses to fully qualified domain names where possible, enhancing readability for DNS-integrated environments.[2] The -o option appends the process ID (PID) owning each TCP connection, facilitating identification of applications using network resources.[2] The -b option reveals the full path to executables involved in connections or listening ports, though it requires elevated privileges and may slow execution due to its depth.[2] The -p option filters by protocol, such as TCP or UDP (including IPv6 variants like TCPv6), allowing targeted views of traffic types.[2] The -x option delivers extended TCP/IP statistics, including connection offload states for network adapter hardware.[2] On macOS, derived from BSD, netstat emphasizes per-interface monitoring and IPv6 integration, with options that align closely with FreeBSD behaviors. The -s option generates comprehensive per-protocol statistics, repeatable to omit zeroed counters, and pairs effectively with -f inet6 for IPv6-focused output that highlights address-specific metrics.) Combining -a (all sockets) and -n (numeric addresses) with -p tcp yields detailed TCP connection states without name resolution, suitable for performance-sensitive diagnostics.[20] The -I option, followed by an interface name like en0, reports traffic counters for that interface alone, and when used with -s, breaks down protocol usage per interface to isolate bottlenecks.)Examples
Cross-Platform Commands
Thenetstat utility provides several command options that function similarly across major operating systems, including Unix-like systems (such as Linux and FreeBSD) and Windows, enabling portable network diagnostics without platform-specific adjustments. These shared options focus on displaying connections, routing, interfaces, and protocol statistics, though output formatting—such as column order and flag notations—may differ slightly to align with system conventions. This portability makes netstat valuable for scripting and cross-environment troubleshooting, where consistent syntax yields comparable insights into network activity.[1][2]
The -a option lists all active connections, including both established TCP sessions and listening UDP/TCP ports, revealing the full scope of network endpoints on the system. On Unix-like systems, the output typically includes columns for protocol, local and foreign addresses with ports, and connection state (e.g., ESTABLISHED or LISTENING), while Windows presents similar data with Proto, Local Address, Foreign Address, and State columns, though the order may vary. For example:
Proto Recv-Q Send-Q Local Address Foreign Address State
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN
tcp 0 0 192.168.1.10:12345 203.0.113.5:80 ESTABLISHED
Proto Recv-Q Send-Q Local Address Foreign Address State
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN
tcp 0 0 192.168.1.10:12345 203.0.113.5:80 ESTABLISHED
-n option allows resolution of IP addresses to hostnames where possible.[1][2]
The -r option displays the system's routing table, showing how packets are forwarded based on destinations, gateways, and interfaces. Unix-like implementations use flags like U (route is up) and G (uses a gateway), with output columns including Destination, Gateway, Genmask, Flags, Metric, Ref, Use, and Iface, whereas Windows formats it with Network Destination, Netmask, Gateway, Interface, and Metric columns for a tabular view akin to the route print command. A representative Unix-like output might appear as:
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
0.0.0.0 192.168.1.1 0.0.0.0 UG 0 0 0 en0
192.168.1.0 0.0.0.0 255.255.255.0 U 0 0 0 en0
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
0.0.0.0 192.168.1.1 0.0.0.0 UG 0 0 0 en0
192.168.1.0 0.0.0.0 255.255.255.0 U 0 0 0 en0
-i (or -I on FreeBSD for a specific interface) option to report per-interface metrics, such as input/output packets, errors, and collisions, in a table with columns like Iface, MTU, RX-OK, RX-ERR, TX-OK, TX-ERR, and Flags. In contrast, Windows uses -e to summarize total Ethernet statistics across all adapters, including bytes and packets sent/received, without per-interface breakdown. An example Unix-like -i output:
Kernel Interface table
Iface MTU Met RX-OK RX-ERR RX-DRP RX-OVR TX-OK TX-ERR TX-DRP TX-OVR Flg
en0 1500 0 12345 0 0 0 67890 0 0 0 BMRU
lo0 65536 0 100 0 0 0 100 0 0 0 LRU
Kernel Interface table
Iface MTU Met RX-OK RX-ERR RX-DRP RX-OVR TX-OK TX-ERR TX-DRP TX-OVR Flg
en0 1500 0 12345 0 0 0 67890 0 0 0 BMRU
lo0 65536 0 100 0 0 0 100 0 0 0 LRU
-i offering granularity on Unix and -e providing aggregated Ethernet insights on Windows.[1][2]
The -s option generates per-protocol summaries for TCP, UDP, ICMP, and IP (including IPv6 where supported), detailing segments or datagrams sent/received, along with error counts like retransmissions or checksum failures. Output is structured as indented sections per protocol on all platforms, with Unix-like systems showing active connections and Windows including similar counters but potentially grouped differently. For instance, a TCP summary might include:
Tcp:
123 active connections openings (0 passive)
5 failed connection attempts
4564 segments sent out
7890 segments received
Tcp:
123 active connections openings (0 passive)
5 failed connection attempts
4564 segments sent out
7890 segments received
-a with -n (as in netstat -an) suppresses DNS name resolution for addresses and ports, displaying numeric values (e.g., 192.168.1.10:80 instead of hostnames) to accelerate execution and reduce overhead, which is particularly beneficial in automated scripts or high-volume monitoring. This numeric mode integrates seamlessly with the -a output format while maintaining portability.[1][2]
Unix-like Systems
In Unix-like systems such as Linux and BSD variants, netstat provides detailed insights into network connections, sockets, and routing, often used for troubleshooting server configurations and connectivity issues.[1] The tool is particularly valuable in environments where administrators need to inspect listening services, protocol statistics, and local communication via Unix domain sockets, with options tailored to display process identifiers (PIDs) and numeric addresses for precise diagnostics.[6] A common command for identifying active listening TCP ports and associated processes isnetstat -tlnp, where -t specifies TCP, -l filters for listening sockets, -n shows numeric ports and addresses without name resolution, and -p reveals the PID and program name owning each socket.[21] This is essential for verifying services like web servers; for instance, running the command might output lines such as:
tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 1234/nginx
tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 1234/nginx
netstat -u -an lists all UDP sockets in numeric format, showing bound addresses and states without resolving hostnames.[23] An example output could include:
udp 0 0 0.0.0.0:123 0.0.0.0:*
udp 0 0 224.0.0.251:5353 0.0.0.0:*
udp 0 0 0.0.0.0:123 0.0.0.0:*
udp 0 0 224.0.0.251:5353 0.0.0.0:*
netstat -rn displays kernel routing information without hostname lookups.[25] Typical output might show:
Kernel IP routing table
Destination Gateway Genmask Flags MSS Window irtt Iface
0.0.0.0 192.168.1.1 0.0.0.0 UG 0 0 0 eth0
192.168.1.0 0.0.0.0 255.255.255.0 U 0 0 0 eth0
Kernel IP routing table
Destination Gateway Genmask Flags MSS Window irtt Iface
0.0.0.0 192.168.1.1 0.0.0.0 UG 0 0 0 eth0
192.168.1.0 0.0.0.0 255.255.255.0 U 0 0 0 eth0
netstat -s | [grep](/page/Grep) errors, which prints per-protocol statistics and filters for error counters like checksum failures or retransmits.[1] For example, in TCP statistics, it might highlight "retransmigs: 5" or UDP "bad checksums: 2," aiding script-based alerting for network anomalies in automated troubleshooting setups.[27]
On Linux distributions, netstat is provided by the net-tools package, which may need explicit installation via package managers like apt or yum if not present by default.[28] Additionally, including the -x option displays Unix domain sockets for inter-process communication analysis; an example output could be:
unix 2 [ ] STREAM CONNECTED 5678 /tmp/.X11-unix/X0
unix 2 [ ] STREAM CONNECTED 5678 /tmp/.X11-unix/X0
Windows Systems
On Windows systems, netstat integrates closely with the TCP/IP protocol stack to provide detailed insights into network activity, including active connections, listening ports, and associated processes, which aids in troubleshooting connectivity issues and monitoring system performance.[2] The command supports protocol-specific filtering and process identification, distinguishing it from implementations on other platforms through features like executable binding and elevated privilege requirements for certain outputs.[2] Thenetstat -an -p TCP command displays all active TCP connections in numerical format, including connection states such as TIME_WAIT, which indicates ports temporarily reserved after closure to handle potential delayed packets.[2] This output lists local and foreign addresses with ports, helping administrators identify lingering connections that might contribute to resource exhaustion in high-traffic environments. For instance, excessive TIME_WAIT states can signal port exhaustion when the system's ephemeral port range is depleted.[31]
To associate network activity with specific processes, netstat -b reveals the executable names involved in each connection or listening port, requiring administrator privileges for execution due to access restrictions on process information.[2] This option is particularly useful for security audits, as it maps traffic to applications like svchost.exe or third-party services, enabling quick identification of unauthorized or anomalous behavior.[32]
For performance monitoring, netstat -e -s combines Ethernet interface statistics—such as bytes and packets sent or received—with per-protocol breakdowns for TCP, UDP, ICMP, and IP, offering a comprehensive view of network utilization.[2] Administrators often use this to assess overall throughput and detect bottlenecks, for example, by observing packet discard rates in the IP statistics section.[2]
The netstat -rn command outputs the IP routing table in numerical format, displaying active routes including persistent ones configured via the route add command, which helps in diagnosing routing misconfigurations or gateway issues.[2] This reveals default gateways, network routes, and interface metrics without symbolic name resolution.
