xref: /openbsd-src/usr.bin/netstat/netstat.1 (revision 99fd087599a8791921855f21bd7e36130f39aadc)
1.\"	$OpenBSD: netstat.1,v 1.86 2019/04/17 20:34:21 jmc Exp $
2.\"	$NetBSD: netstat.1,v 1.11 1995/10/03 21:42:43 thorpej Exp $
3.\"
4.\" Copyright (c) 1983, 1990, 1992, 1993
5.\"	The Regents of the University of California.  All rights reserved.
6.\"
7.\" Redistribution and use in source and binary forms, with or without
8.\" modification, are permitted provided that the following conditions
9.\" are met:
10.\" 1. Redistributions of source code must retain the above copyright
11.\"    notice, this list of conditions and the following disclaimer.
12.\" 2. Redistributions in binary form must reproduce the above copyright
13.\"    notice, this list of conditions and the following disclaimer in the
14.\"    documentation and/or other materials provided with the distribution.
15.\" 3. Neither the name of the University nor the names of its contributors
16.\"    may be used to endorse or promote products derived from this software
17.\"    without specific prior written permission.
18.\"
19.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
20.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
23.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29.\" SUCH DAMAGE.
30.\"
31.\"	from: @(#)netstat.1	8.8 (Berkeley) 4/18/94
32.\"
33.Dd $Mdocdate: April 17 2019 $
34.Dt NETSTAT 1
35.Os
36.Sh NAME
37.Nm netstat
38.Nd show network status
39.Sh SYNOPSIS
40.Nm
41.Op Fl AaBln
42.Op Fl f Ar address_family
43.Op Fl p Ar protocol
44.Op Fl M Ar core
45.Op Fl N Ar system
46.Nm
47.Op Fl bdeFgilmnqrstu
48.Op Fl f Ar address_family
49.Op Fl p Ar protocol
50.Op Fl M Ar core
51.Op Fl N Ar system
52.Op Fl T Ar rtable
53.Nm
54.Op Fl bdehn
55.Op Fl c Ar count
56.Op Fl I Ar interface
57.Op Fl M Ar core
58.Op Fl N Ar system
59.Op Fl w Ar wait
60.Nm
61.Op Fl v
62.Op Fl M Ar core
63.Op Fl N Ar system
64.Fl P Ar pcbaddr
65.Nm
66.Op Fl s
67.Op Fl M Ar core
68.Op Fl N Ar system
69.Op Fl p Ar protocol
70.Nm
71.Op Fl a
72.Op Fl f Ar address_family
73.Op Fl p Ar protocol
74.Op Fl i | I Ar interface
75.Nm
76.Op Fl W Ar interface
77.Sh DESCRIPTION
78The
79.Nm
80command symbolically displays the contents of various network-related
81data structures.
82There are a number of output formats,
83depending on the options for the information presented.
84.Pp
85The first form of the command displays a list of active sockets for
86each protocol.
87The second form presents the contents of one of the other network
88data structures according to the option selected.
89Using the third form, with a
90.Ar wait
91interval specified,
92.Nm
93will continuously display the information regarding packet
94traffic on the configured network interfaces.
95The fourth form displays internals of the protocol control block (PCB)
96and the socket structure.
97The fifth form displays statistics about the named protocol.
98The sixth form displays per interface statistics for
99the specified address family.
100The final form displays per interface statistics for
101the specified wireless (802.11) device.
102.Pp
103The options are as follows:
104.Bl -tag -width Ds
105.It Fl A
106Show the address of any protocol control blocks associated with sockets;
107useful for debugging e.g. with the
108.Fl P
109flag.
110When used with the
111.Fl r
112flag it shows the internal addresses of the routing table.
113Only the super-user can see these addresses;
114unprivileged users will see them as 0x0.
115.It Fl a
116With the default display,
117show the state of all sockets; normally sockets used by
118server processes are not shown.
119.It Fl B
120With the default display,
121show buffer sizes for TCP sockets.
122This includes the send window size, receive window size and congestion
123window size.
124.It Fl b
125With the interface display (options
126.Fl I
127or
128.Fl i ) ,
129show bytes in and out, instead of packet statistics.
130.It Fl c Ar count
131Display
132.Ar count
133updates, then exit.
134This option has no effect unless
135.Fl w
136is specified as well.
137.It Fl d
138With either the interface display (options
139.Fl I
140or
141.Fl i )
142or an interval (option
143.Fl w ) ,
144show only the number of dropped packets.
145.It Fl e
146With either the interface display (options
147.Fl I
148or
149.Fl i )
150or an interval (option
151.Fl w ) ,
152show only the number of errors on the interface.
153.It Fl F
154When showing routes, only show routes whose gateway are in the
155same address family as the destination.
156.It Fl f Ar address_family
157Limit statistics or address control block reports to those
158of the specified
159.Ar address_family .
160.Pp
161The following address families are recognized:
162.Bl -column "Address Family" "AF_APPLETA" "Description" -offset indent
163.It Sy "Address Family" Ta Sy "Constant" Ta Sy "Description"
164.It "inet" Ta Dv "AF_INET" Ta "IP Version 4"
165.It "inet6" Ta Dv "AF_INET6" Ta "IP Version 6"
166.It "local" Ta Dv "AF_UNIX" Ta "Alias for unix"
167.It "mpls" Ta Dv "AF_MPLS" Ta "MPLS"
168.It "unix" Ta Dv "AF_UNIX" Ta "Local to Host (i.e., pipes)"
169.El
170.It Fl h
171Use unit suffixes to reduce the number of digits shown with the
172.Fl b
173and
174.Fl w
175options.
176.It Fl g
177Show information related to multicast (group address) routing.
178By default, show the IP multicast virtual-interface and routing tables.
179If the
180.Fl s
181option is also present, show multicast routing statistics.
182.It Fl I Ar interface
183Show information about the specified
184.Ar interface ;
185used with a
186.Ar wait
187interval as described below.
188.Pp
189If the
190.Fl f Ar address_family
191option (with the
192.Fl s
193option) is present, show per-interface
194statistics on the given interface for the specified
195.Ar address_family .
196.It Fl i
197Show the state of interfaces which have been auto-configured
198(interfaces statically configured into a system but not
199located at boot-time are not shown).
200.Pp
201If the
202.Fl f Ar address_family
203option (with the
204.Fl s
205option) is present, show per-interface statistics on all interfaces
206for the specified
207.Ar address_family .
208.It Fl l
209With the default display,
210show only listening sockets.
211With the
212.Fl g
213option, display wider fields for the IPv6 multicast routing table
214.Qq Origin
215and
216.Qq Group
217columns.
218.It Fl M Ar core
219Extract values associated with the name list from the specified core
220instead of the running kernel.
221.It Fl m
222Show statistics recorded by the memory management routines
223(the network manages a private pool of memory buffers).
224.It Fl N Ar system
225Extract the name list from the specified system instead of the running kernel.
226.It Fl n
227Show network addresses as numbers (normally
228.Nm
229interprets addresses and attempts to display them
230symbolically).
231This option may be used with any of the display formats.
232.It Fl P Ar pcbaddr
233Display the contents of the protocol control block (PCB)
234located at the kernel virtual address
235.Ar pcbaddr .
236PCB addresses can be obtained using the
237.Fl A
238flag.
239When used with the
240.Fl v
241option, also print socket, domain and protocol specific structures.
242Only the super-user can use the
243.Fl P
244option.
245.Pp
246The
247.Fl P
248option requires the ability to open
249.Pa /dev/kmem
250which may be restricted based upon the value of the
251.Ar kern.allowkmem
252.Xr sysctl 8 .
253.It Fl p Ar protocol
254Restrict the output to
255.Ar protocol ,
256which is either a well-known name for a protocol or an alias for it.
257Some protocol names and aliases are listed in the file
258.Pa /etc/protocols .
259The program will complain if
260.Ar protocol
261is unknown.
262If the
263.Fl s
264option is specified, the per-protocol statistics are displayed.
265Otherwise the states of the matching sockets are shown.
266.It Fl q
267Only show interfaces that have seen packets (or bytes if
268.Fl b
269is specified).
270.It Fl r
271Show the routing tables.
272The output is explained in more detail below.
273If the
274.Fl s
275option is also specified, show routing statistics instead.
276When used with the
277.Fl v
278option, also print routing labels.
279.It Fl s
280Show per-protocol statistics.
281If this option is repeated, counters with a value of zero are suppressed.
282.It Fl T Ar rtable
283Select an alternate routing table to query.
284The default is to use the current routing table.
285.It Fl t
286With the
287.Fl i
288option, display the current value of the watchdog timer function.
289.It Fl u
290Limit statistics or address control block reports to the
291.Dv AF_UNIX
292address family.
293.It Fl v
294Show extra (verbose) detail for the routing tables
295.Pq Fl r ,
296or avoid truncation of long addresses.
297When used with the
298.Fl P
299option, also print socket, domain and protocol specific structures.
300.It Fl W Ar interface
301(IEEE 802.11 devices only)
302Show per-interface IEEE 802.11 wireless statistics.
303.It Fl w Ar wait
304Show network interface statistics at intervals of
305.Ar wait
306seconds.
307.El
308.Pp
309The default display, for active sockets, shows the local
310and remote addresses, send and receive queue sizes (in bytes), protocol,
311and the internal state of the protocol.
312.Pp
313Address formats are of the form
314.Dq host.port
315or
316.Dq network.port
317if a socket's address specifies a network but no specific host address.
318When known, the host addresses are displayed symbolically
319according to the
320.Xr hosts 5
321database.
322If a symbolic name for an address is unknown, or if the
323.Fl n
324option is specified, the address is printed numerically, according
325to the address family.
326.Pp
327For more information regarding the Internet
328.Dq dot format ,
329refer to
330.Xr inet_ntop 3 .
331Unspecified or
332.Dq wildcard
333addresses and ports appear as a single
334.Sq * .
335If a local port number is registered as being in use for RPC by
336.Xr portmap 8 ,
337its RPC service name or RPC service number will be printed in
338.Dq []
339immediately after the port number.
340.Pp
341The interface display provides a table of cumulative
342statistics regarding packets transferred, errors, and collisions.
343The network addresses of the interface
344and the maximum transmission unit (MTU) are also displayed.
345.Pp
346The routing table display indicates the available routes and their status.
347Each route consists of a destination host or network and
348a gateway to use in forwarding packets.
349If the destination is a
350network in numeric format, the netmask (in /24 style format) is appended.
351The flags field shows a collection of information about
352the route stored as binary choices.
353The individual flags are discussed in more detail in the
354.Xr route 8
355and
356.Xr route 4
357manual pages.
358.Pp
359The mapping between letters and flags is:
360.Bl -column "1" "RTF_BLACKHOLE" "Protocol specific routing flag #1."
361.It 1 Ta RTF_PROTO1 Ta "Protocol specific routing flag #1."
362.It 2 Ta RTF_PROTO2 Ta "Protocol specific routing flag #2."
363.It 3 Ta RTF_PROTO3 Ta "Protocol specific routing flag #3."
364.It B Ta RTF_BLACKHOLE Ta "Just discard pkts (during updates)."
365.It b Ta RTF_BROADCAST Ta "Correspond to a local broadcast address."
366.It C Ta RTF_CLONING Ta "Generate new routes on use."
367.It c Ta RTF_CLONED Ta "Cloned routes (generated from RTF_CLONING)."
368.It D Ta RTF_DYNAMIC Ta "Created dynamically (by redirect)."
369.It d Ta RTF_DONE Ta "Completed (for routing messages only)."
370.It G Ta RTF_GATEWAY Ta "Destination requires forwarding by intermediary."
371.It H Ta RTF_HOST Ta "Host entry (net otherwise)."
372.It h Ta RTF_CACHED Ta "Referenced by gateway route."
373.It L Ta RTF_LLINFO Ta "Valid protocol to link address translation."
374.It l Ta RTF_LOCAL Ta "Correspond to a local address."
375.It M Ta RTF_MODIFIED Ta "Modified dynamically (by redirect)."
376.It m Ta RTF_MULTICAST Ta "Correspond to a multicast address."
377.It n Ta RTF_CONNECTED Ta "Interface route."
378.It P Ta RTF_MPATH Ta "Multipath route."
379.It R Ta RTF_REJECT Ta "Host or net unreachable."
380.It S Ta RTF_STATIC Ta "Manually added."
381.It T Ta RTF_MPLS Ta "MPLS route."
382.It U Ta RTF_UP Ta "Route usable."
383.El
384.Pp
385Direct routes are created for each interface attached to the local host;
386the gateway field for such entries shows the address of the outgoing interface.
387The refcnt field gives the current number of active uses of the route.
388Connection oriented protocols normally hold on to a single route for the
389duration of a connection while connectionless protocols obtain a route while
390sending to the same destination.
391The use field provides a count of the number of packets sent using that route.
392The MTU entry shows the MTU associated with that route.
393This MTU value is used as the basis for the TCP maximum segment size (MSS).
394The
395.Sq L
396flag appended to the MTU value indicates that the value is
397locked, and that path MTU discovery is turned off for that route.
398A
399.Sq -
400indicates that the MTU for this route has not been set, and a default
401TCP maximum segment size will be used.
402The interface entry indicates the network interface utilized for the route.
403.Pp
404When
405.Nm
406is invoked with the
407.Fl w
408option and a
409.Ar wait
410interval argument, it displays a running count of statistics related to
411network interfaces.
412An obsolescent version of this option used a numeric parameter
413with no option, and is currently supported for backward compatibility.
414This display consists of a column for the primary interface (the first
415interface found during autoconfiguration) and a column summarizing
416information for all interfaces.
417The primary interface may be replaced with another interface with the
418.Fl I
419option.
420The first line of each screen of information contains a summary since the
421system was last rebooted.
422Subsequent lines of output show values accumulated over the preceding interval.
423.Sh SEE ALSO
424.Xr fstat 1 ,
425.Xr nfsstat 1 ,
426.Xr ps 1 ,
427.Xr systat 1 ,
428.Xr tcpbench 1 ,
429.Xr top 1 ,
430.Xr inet_ntop 3 ,
431.Xr netintro 4 ,
432.Xr route 4 ,
433.Xr hosts 5 ,
434.Xr protocols 5 ,
435.Xr services 5 ,
436.Xr iostat 8 ,
437.Xr portmap 8 ,
438.Xr pstat 8 ,
439.Xr route 8 ,
440.Xr tcpdrop 8 ,
441.Xr trpt 8 ,
442.Xr vmstat 8
443.Sh HISTORY
444The
445.Nm
446command appeared in
447.Bx 4.2 .
448IPv6 support was added by the WIDE/KAME project.
449.Sh BUGS
450The notion of errors is ill-defined.
451