netstat command
Purpose
Shows network status.
Syntax
To display active sockets for each protocol or routing table information:
netstat [ -num ] [ -routtable ] [ -routinfo] [ -state ] [ -socket ] [ -protocol Protocol ] [ Interval ]
To display the contents of a network data structure:
netstat [ -stats | -cdlistats ] [ -protocol protocol ] [ Interval ]
To display the address resolution protocol:
netstat -arp
To clear all statistics:
netstat -clear
Description
The netstat command symbolically displays the contents of various network-related data structures for active connections.
Flags
Flag name | Description |
---|---|
-arp | Displays address resolution interfaces. |
-cdlistats | Shows statistics for CDLI-based communications adapters. |
-clear | Clears all statistics. |
-num | Shows network addresses as numbers. When this flag is not specified, the netstat command interprets addresses where possible and displays them symbolically. This flag can be used with any of the display formats. |
-protocol protocol | Shows statistics about the value specified for the protocol variable, which is either a well-known name for a protocol or an alias for it. A null response means that there are no numbers to report. The program report of the value specified for this variable is unknown if there is no statistics routine for it. |
-routinfo | Shows the routing tables, including the user-configured and current costs of each route. |
-routtable | Shows the routing tables. When used with the -stats flag, the -routtable flag shows routing statistics. See Routing Table Display. |
-socket | Displays the network sockets. |
-state | Shows the state of all configured interfaces. The
interface display format provides a table of cumulative statistics
for the following items:
The interface information that is displayed also provides the interface name, number, and address, as well as the maximum transmission units (MTUs). |
-stats | Shows statistics for each protocol. |
Interval | Continuously displays information, in seconds, regarding packet traffic on the configured network interfaces. |
Default Display
- Local and remote addresses
- Send and receive queue sizes (in bytes)
- Protocol
- Internal state of the protocol
Internet address formats are of the form host.port or network.port if a socket's address specifies a network but no specific host address. If the address can be resolved to a symbolic host name, the host address, as well as network addresses, are displayed symbolically.
NS addresses are 12-bytes in length, consisting of a 4-byte network number, a 6-byte host number and a 2-byte port number, all stored in network standard format. For VAX architecture, the word and byte are reversed.
If a symbolic name for a host is not known or if you specified the -num flag, the address is printed numerically, according to the address family. Unspecified addresses and ports appear as an * (asterisk).
Interface Display
- Errors
- Collisions Note: The collision count for Ethernet interfaces is not applicable.
- Packets transferred
The interface display also provides the interface name, number, and address as well as the maximum transmission units (MTUs).
Routing table display
The routing table display indicates the available routes and their statuses. Each route consists of a destination host or network and a gateway to use in forwarding packets.
A route is given in the format A.B.C.D/XX, which presents two pieces of information. A.B.C.D indicates the destination address and XX indicates the netmask associated with the route. The netmask is represented by the number of bits that are set. For example, the route 9.3.252.192/26 has a netmask of 255.255.255.192, which has 26 bits set.
Field | Description |
---|---|
Flags | The flags field in the routing table shows the
state of the route:
Direct routes are created for each interface attached to the local host. |
Gateway | Shows the address of the outgoing interface. |
Refs | Shows the current number of active uses for the route. Connection-oriented protocols hold on to a single route for the duration of a connection, while connectionless protocols obtain a route while sending to the same destination. |
Use | Provides a count of the number of packets sent using that route. |
PMTU | Lists the Path Maximum Transfer Unit (PMTU). |
Interface | Indicates the network interfaces utilized for the route. |
Exp | Displays the time (in minutes) remaining before the route expires. |
Groups | Provides a list of group IDs associated with that route. |
Netmasks | Lists the netmasks applied on the system. |
Route Tree for Protocol Family | Specifies the active address families for existing
routes. Values for this field are as follows:
|
When a value is specified for the Interval variable, the netstat command displays a running count of statistics related to network interfaces. This display contains two columns: a column for the primary interface (the first interface found during autoconfiguration) and a column summarizing information for all interfaces. The first line contains a summary of statistics accumulated since the system was last restarted. The subsequent lines of output show values accumulated over intervals of the specified length.
Exit Status
Examples
- To display routing table information for an Internet interface,
type the following command:
netstat -routtable
This produces the output similar to the following:
Routing tables Destination Gateway Flags Refs Use If PMTU Exp Groups Route tree for Protocol Family 2 (Internet): default 129.3.141.1 UGc 0 0 en0 - - 129.33.140/23 127.0.0.1 U 6 53 en0 - - 129.33.41.2 localhost UGHS 6 115 lo0 - - 129.45.41.2 129.3.41.1 UGHW 1 602 en0 1500 - dcefs100 129.31.41.1 UGHW 1 2 en0 - - 192.100.61 localhost U 7 14446 lo0 - - Route tree for Protocol Family 24 (Internet v6): ::1 ::1 UH 0 0 lo0 16896 -
- To display interface information for an Internet interface, type
the following command:
netstat -state
This produces the output similar to the following:
Name Mtu Network Address Ipkts Ierrs Opkts Oerrs Coll en0 1500 link#2 0.5.20.4.0.4e 874986 0 22494 0 0 en0 1500 90.34.14 hostname 874986 0 22494 0 0 lo0 16896 link#1 14581 0 14590 0 0 lo0 16896 129 localhost 14581 0 14590 0 0 lo0 16896 ::1 14581 0 14590 0 0
- To display network sockets, type the following
command:
netstat -socket