NAME
netstat —
show network status and
statistics
SYNOPSIS
netstat- [
--libxo] [-46AaCLnPRSTWx] [-fprotocol_family |-pprotocol] [-Mcore] [-Nsystem] netstat-i|-Iinterface- [
--libxo] [-46abdhnW] [-faddress_family] [-Mcore] [-Nsystem] netstat-wwait- [
--libxo] [-Iinterface] [-46d] [-Mcore] [-Nsystem] [-qhowmany] netstat-s- [
--libxo] [-46sz] [-fprotocol_family |-pprotocol] [-Mcore] [-Nsystem] netstat-i|-Iinterface-s- [
--libxo] [-46s] [-fprotocol_family |-pprotocol] [-Mcore] [-Nsystem] netstat-m- [
--libxo] [-Mcore] [-Nsystem] netstat-B- [
--libxo] [-z] [-Iinterface] netstat-r- [
--libxo] [-46nW] [-Ffibnum] [-faddress_family] netstat-rs- [
--libxo] [-s] [-Mcore] [-Nsystem] netstat-g- [
--libxo] [-46W] [-faddress_family] netstat-gs- [
--libxo] [-46s] [-faddress_family] [-Mcore] [-Nsystem] netstat-Q- [
--libxo]
DESCRIPTION
Thenetstat command symbolically displays the contents
of various network-related data structures. There are a number of output
formats, depending on the options for the information presented.
netstat[-46AaCLnRSTWx] [-fprotocol_family |-pprotocol] [-Mcore] [-Nsystem]- Display a list of active sockets (protocol control blocks) for each
network protocol.
The default display for active sockets shows the local and remote addresses, send and receive queue sizes (in bytes), protocol, and the internal state of the protocol. Address formats are of the form “host.port” or “network.port” if a socket's address specifies a network but no specific host address. When known, the host and network addresses are displayed symbolically according to the databases hosts(5) and networks(5), respectively. If a symbolic name for an address is unknown, or if the
-noption is specified, the address is printed numerically, according to the address family. For more information regarding the Internet IPv4 “dot format”, refer to inet(3). Unspecified, or “wildcard”, addresses and ports appear as “*”.--libxo- Generate output via libxo(3) in a selection of different human and machine readable formats. See xo_parse_args(3) for details on command line arguments.
-4- Show IPv4 only. See GENERAL OPTIONS.
-6- Show IPv6 only. See GENERAL OPTIONS.
-A- Show the address of a protocol control block (PCB) associated with a socket; used for debugging.
-a- Show the state of all sockets; normally sockets used by server processes are not shown.
-c- Show the used TCP stack for each session.
-C- Show the congestion control algorithm and diagnostic information of TCP sockets.
-L- Show the size of the various listen queues. The first count shows the number of unaccepted connections, the second count shows the amount of unaccepted incomplete connections, and the third count is the maximum number of queued connections.
-n- Do not resolve numeric addresses and port numbers to names. See GENERAL OPTIONS.
-P- Display the log ID for each socket.
-R- Display the flowid and flowtype for each socket. flowid is a 32 bit
hardware specific identifier for each flow. flowtype defines which
protocol fields are hashed to produce the id. A complete listing is
available in sys/mbuf.h under
M_HASHTYPE_*. -S- Show network addresses as numbers (as with
-n) but show ports symbolically. -T- Display diagnostic information from the TCP control block. Fields include the number of packets requiring retransmission, received out-of-order, and those advertising a zero-sized window.
-W- Avoid truncating addresses even if this causes some fields to overflow.
-x- Display socket buffer and TCP timer statistics for each internet
socket.
The
-xflag causesnetstatto output all the information recorded about data stored in the socket buffers. The fields are:R-MBUFNumber of mbufs in the receive queue. S-MBUFNumber of mbufs in the send queue. R-CLUSNumber of clusters, of any type, in the receive queue. S-CLUSNumber of clusters, of any type, in the send queue. R-HIWAReceive buffer high water mark, in bytes. S-HIWASend buffer high water mark, in bytes. R-LOWAReceive buffer low water mark, in bytes. S-LOWASend buffer low water mark, in bytes. R-BCNTReceive buffer byte count. S-BCNTSend buffer byte count. R-BMAXMaximum bytes that can be used in the receive buffer. S-BMAXMaximum bytes that can be used in the send buffer. rexmtTime, in seconds, to fire Retransmit Timer, or 0 if not armed. persistTime, in seconds, to fire Retransmit Persistence, or 0 if not armed. keepTime, in seconds, to fire Keep Alive, or 0 if not armed. 2mslTime, in seconds, to fire 2*msl TIME_WAIT Timer, or 0 if not armed. delackTime, in seconds, to fire Delayed ACK Timer, or 0 if not armed. rcvtimeTime, in seconds, since last packet received. -fprotocol_family- Filter by protocol_family. See GENERAL OPTIONS.
-pprotocol- Filter by protocol. See GENERAL OPTIONS.
-M- Use an alternative core. See GENERAL OPTIONS.
-N- Use an alternative kernel image. See GENERAL OPTIONS.
netstat-i|-Iinterface [-46abdhnW] [-faddress_family] [-Mcore] [-Nsystem]- Show the state of all network interfaces or a single
interface which have been auto-configured
(interfaces statically configured into a system, but not located at boot
time are not shown). An asterisk
(“
*”) after an interface name indicates that the interface is “down”.When
netstatis invoked with-i(all interfaces) or-Iinterface, it provides a table of cumulative statistics regarding packets transferred, errors, and collisions. The network addresses of the interface and the maximum transmission unit (“mtu”) are also displayed.-4- Show IPv4 only. See GENERAL OPTIONS.
-6- Show IPv6 only. See GENERAL OPTIONS.
-a- Multicast addresses currently in use are shown for each Ethernet interface and for each IP interface address. Multicast addresses are shown on separate lines following the interface address with which they are associated.
-b- Show the number of bytes in and out.
-d- Show the number of dropped packets.
-h- Print all counters in human readable form.
-n- Do not resolve numeric addresses and port numbers to names. See GENERAL OPTIONS.
-W- Avoid truncating interface names even if this causes some fields to overflow. GENERAL OPTIONS.
-fprotocol_family- Filter by protocol_family. See GENERAL OPTIONS.
netstat-wwait [-Iinterface] [-46d] [-Mcore] [-Nsystem] [-qhowmany]- At intervals of wait seconds, display the
information regarding packet traffic on all configured network interfaces
or a single interface.
When
netstatis invoked with the-woption and a wait interval argument, it displays a running count of statistics related to network interfaces. An obsolescent version of this option used a numeric parameter with no option, and is currently supported for backward compatibility. By default, this display summarizes information for all interfaces. Information for a specific interface may be displayed with the-Iinterface option.-Iinterface- Only show information regarding interface
-4- Show IPv4 only. See GENERAL OPTIONS.
-6- Show IPv6 only. See GENERAL OPTIONS.
-d- Show the number of dropped packets.
-M- Use an alternative core. See GENERAL OPTIONS.
-N- Use an alternative kernel image. See GENERAL OPTIONS.
-q- Exit after howmany outputs.
netstat-s[-46sz] [-fprotocol_family |-pprotocol] [-Mcore] [-Nsystem]- Display system-wide statistics for each network protocol.
-4- Show IPv4 only. See GENERAL OPTIONS.
-6- Show IPv6 only. See GENERAL OPTIONS.
-s- If
-sis repeated, counters with a value of zero are suppressed. -z- Reset statistic counters after displaying them.
-fprotocol_family- Filter by protocol_family. See GENERAL OPTIONS.
-pprotocol- Filter by protocol. See GENERAL OPTIONS.
-M- Use an alternative core. See GENERAL OPTIONS.
-N- Use an alternative kernel image See GENERAL OPTIONS.
netstat-i|-Iinterface-s[-46s] [-fprotocol_family |-pprotocol] [-Mcore] [-Nsystem]- Display per-interface statistics for each network protocol.
-4- Show IPv4 only See GENERAL OPTIONS.
-6- Show IPv6 only See GENERAL OPTIONS.
-s- If
-sis repeated, counters with a value of zero are suppressed. -fprotocol_family- Filter by protocol_family. See GENERAL OPTIONS.
-pprotocol- Filter by protocol. See GENERAL OPTIONS.
-M- Use an alternative core See GENERAL OPTIONS.
-N- Use an alternative kernel image See GENERAL OPTIONS.
netstat-m[-Mcore] [-Nsystem]- Show statistics recorded by the memory management routines
(mbuf(9)). The network manages a private pool of memory buffers.
-M- Use an alternative core See GENERAL OPTIONS.
-N- Use an alternative kernel image See GENERAL OPTIONS.
netstat-B[-z] [-Iinterface]- Show statistics about
bpf(4) peers. This includes information like how many packets have
been matched, dropped and received by the bpf device, also information
about current buffer sizes and device states.
The bpf(4) flags displayed when
netstatis invoked with the-Boption represent the underlying parameters of the bpf peer. Each flag is represented as a single lower case letter. The mapping between the letters and flags in order of appearance are:pSet if listening promiscuously iBIOCIMMEDIATEhas been set on the devicefBIOCGHDRCMPLTstatus: source link addresses are being filled automaticallysBIOCGSEESENTstatus: see packets originating locally and remotely on the interface.aPacket reception generates a signal lBIOCLOCKstatus: descriptor has been lockedFor more information about these flags, please refer to bpf(4).
-z- Reset statistic counters after displaying them.
netstat-r[-46AnW] [-Ffibnum] [-faddress_family] [-Mcore] [-Nsystem]- Display the contents of routing tables.
When
netstatis invoked with the routing table option-r, it lists the available routes and their status. Each route consists of a destination host or network, and a gateway to use in forwarding packets. The flags field shows a collection of information about the route stored as binary choices. The individual flags are discussed in more detail in the route(8) and route(4) manual pages. The mapping between letters and flags is:1RTF_PROTO1Protocol specific routing flag #1 2RTF_PROTO2Protocol specific routing flag #2 3RTF_PROTO3Protocol specific routing flag #3 BRTF_BLACKHOLEJust discard pkts (during updates) bRTF_BROADCASTThe route represents a broadcast address DRTF_DYNAMICCreated dynamically (by redirect) GRTF_GATEWAYDestination requires forwarding by intermediary HRTF_HOSTHost entry (net otherwise) LRTF_LLINFOValid protocol to link address translation MRTF_MODIFIEDModified dynamically (by redirect) RRTF_REJECTHost or net unreachable SRTF_STATICManually added URTF_UPRoute usable XRTF_XRESOLVEExternal daemon translates proto to link address Direct routes are created for each interface attached to the local host; the gateway field for such entries shows the address of the outgoing interface. The refcnt field gives the current number of active uses of the route. Connection oriented protocols normally hold on to a single route for the duration of a connection while connectionless protocols obtain a route while sending to the same destination. The use field provides a count of the number of packets sent using that route. The interface entry indicates the network interface utilized for the route.
-4- Show IPv4 only. See GENERAL OPTIONS.
-6- Show IPv6 only. See GENERAL OPTIONS.
-n- Do not resolve numeric addresses and port numbers to names. See GENERAL OPTIONS.
-W- Show the path MTU for each route, and print interface names with a wider field size.
-F- Display the routing table with the number
fibnum. If the specified
fibnum is -1 or
-Fis not specified, the default routing table is displayed. -f- Display the routing table for a particular address_family.
-M- Use an alternative core See GENERAL OPTIONS.
-N- Use an alternative kernel image See GENERAL OPTIONS.
netstat-rs[-s] [-Mcore] [-Nsystem]- Display routing statistics.
-s- If
-sis repeated, counters with a value of zero are suppressed. -M- Use an alternative core See GENERAL OPTIONS.
-N- Use an alternative kernel image See GENERAL OPTIONS.
netstat-g[-46W] [-faddress_family] [-Mcore] [-Nsystem]- Display the contents of the multicast virtual interface tables, and
multicast forwarding caches. Entries in these tables will appear only when
the kernel is actively forwarding multicast sessions. This option is
applicable only to the
inetandinet6address families.-4- Show IPv4 only See GENERAL OPTIONS.
-6- Show IPv6 only See GENERAL OPTIONS.
-W- Avoid truncating addresses even if this causes some fields to overflow.
-fprotocol_family- Filter by protocol_family. See GENERAL OPTIONS.
-M- Use an alternative core See GENERAL OPTIONS.
-N- Use an alternative kernel image See GENERAL OPTIONS.
netstat-gs[-46s] [-faddress_family] [-Mcore] [-Nsystem]- Show multicast routing statistics.
-4- Show IPv4 only See GENERAL OPTIONS.
-6- Show IPv6 only See GENERAL OPTIONS.
-s- If
-sis repeated, counters with a value of zero are suppressed. -fprotocol_family- Filter by protocol_family. See GENERAL OPTIONS.
-M- Use an alternative core See GENERAL OPTIONS.
-N- Use an alternative kernel image See GENERAL OPTIONS.
netstat-Q- Show netisr(9) statistics. The flags field shows available ISR
handlers:
CNETISR_SNP_FLAGS_M2CPUIDAble to map mbuf to cpu id DNETISR_SNP_FLAGS_DRAINEDCPUHas queue drain handler FNETISR_SNP_FLAGS_M2FLOWAble to map mbuf to flow id
GENERAL OPTIONS
Some options have the general meaning:
-4- Is shorthand for
-finet (Show only IPv4) -6- Is shorthand for
-finet6 (Show only IPv6) -faddress_family,-pprotocol- Limit display to those records of the specified
address_family or a single
protocol. The following address families and
protocols are recognized:
- Family
- Protocols
inet(AF_INET)divert,icmp,igmp,ip,ipsec,pim, sctp,tcp,udpinet6(AF_INET6)icmp6,ip6,ipsec6,rip6,sctp,tcp,udppfkey(PF_KEY)pfkeynetgraph,ng(AF_NETGRAPH)ctrl,dataunix(AF_UNIX)link(AF_LINK)
The program will complain if protocol is unknown or if there is no statistics routine for it.
-M- Extract values associated with the name list from the specified core instead of the default /dev/kmem.
-N- Extract the name list from the specified system instead of the default, which is the kernel image the system has booted from.
-n- Show network addresses and ports as numbers. Normally
netstatattempts to resolve addresses and ports, and display them symbolically.
EXAMPLES
Show packet traffic information (packets, bytes, errors, packet drops, etc) for interface re0 updated every 2 seconds and exit after 5 outputs:
$ netstat -w 2 -q 5 -I re0
Show statistics for ICMP on any interface:
$ netstat -s -p icmp
Show routing tables:
$ netstat -r
Same as above, but without resolving numeric addresses and port numbers to names:
$ netstat -rn
SEE ALSO
fstat(1), nfsstat(1), procstat(1), ps(1), sockstat(1), libxo(3), xo_parse_args(3), bpf(4), inet(4), route(4), unix(4), hosts(5), networks(5), protocols(5), services(5), iostat(8), route(8), trpt(8), vmstat(8), mbuf(9)
HISTORY
The netstat command appeared in
4.2BSD.
IPv6 support was added by WIDE/KAME project.
BUGS
The notion of errors is ill-defined.