xref: /netbsd-src/usr.bin/netstat/netstat.1 (revision 133b743cd19925634f8d41fc9f32866244790f4c)
1.\"	$NetBSD: netstat.1,v 1.76 2022/12/21 09:06:59 msaitoh Exp $
2.\"
3.\" Copyright (c) 1983, 1990, 1992, 1993
4.\"	The Regents of the University of California.  All rights reserved.
5.\"
6.\" Redistribution and use in source and binary forms, with or without
7.\" modification, are permitted provided that the following conditions
8.\" are met:
9.\" 1. Redistributions of source code must retain the above copyright
10.\"    notice, this list of conditions and the following disclaimer.
11.\" 2. Redistributions in binary form must reproduce the above copyright
12.\"    notice, this list of conditions and the following disclaimer in the
13.\"    documentation and/or other materials provided with the distribution.
14.\" 3. Neither the name of the University nor the names of its contributors
15.\"    may be used to endorse or promote products derived from this software
16.\"    without specific prior written permission.
17.\"
18.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
19.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
22.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
24.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
27.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
28.\" SUCH DAMAGE.
29.\"
30.\"	@(#)netstat.1	8.8 (Berkeley) 4/18/94
31.\"
32.Dd December 21, 2022
33.Dt NETSTAT 1
34.Os
35.Sh NAME
36.Nm netstat
37.Nd show network status
38.Sh SYNOPSIS
39.ds address_family Fl f Ar address_family Ns Op , Ns Ar family ...
40.Nm
41.Op Fl Aan
42.Op \*[address_family]
43.Op Fl M Ar core
44.Op Fl N Ar system
45.Nm
46.Op Fl bdghiLlmnqrSsTtv
47.Op \*[address_family]
48.Op Fl M Ar core
49.Op Fl N Ar system
50.Nm
51.Op Fl dn
52.Op Fl I Ar interface
53.Op Fl M Ar core
54.Op Fl N Ar system
55.Op Fl w Ar wait
56.Nm
57.Op Fl M Ar core
58.Op Fl N Ar system
59.Op Fl p Ar protocol
60.Nm
61.Op Fl M Ar core
62.Op Fl N Ar system
63.Op Fl p Ar protocol
64.Fl P Ar pcbaddr
65.Nm
66.Op Fl i
67.Op Fl I Ar Interface
68.Op Fl p Ar protocol
69.Nm
70.Op Fl is
71.Op \*[address_family]
72.Op Fl I Ar Interface
73.Nm
74.Op Fl s
75.Op Fl I Ar Interface
76.Fl B
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.
84The first form of the command displays a list of active sockets for
85each protocol.
86The second form presents the contents of one of the other network
87data structures according to the option selected.
88Using the third form, with a
89.Ar wait
90interval specified,
91.Nm
92will continuously display the information regarding packet
93traffic on the configured network interfaces.
94The fourth form displays statistics about the named protocol.
95The fifth and sixth forms display per interface statistics for
96the specified protocol or address family.
97.Pp
98The options have the following meaning:
99.Bl -tag -width flag
100.It Fl A
101With the default display,
102show the address of any protocol control blocks associated with sockets; used
103for debugging.
104.It Fl a
105With the default display,
106show the state of all sockets; normally sockets used by
107server processes are not shown.
108.It Fl B
109With the default display,
110show the current
111.Xr bpf 4
112peers.
113To show only the peers listening to a specific interface,
114use the
115.Fl I
116option.
117If the
118.Fl s
119option is present, show the current
120.Xr bpf 4
121statistics.
122.It Fl b
123With the interface display (option
124.Fl i ) ,
125show bytes in and out, instead of packets in and out.
126.It Fl d
127With either interface display (option
128.Fl i
129or an interval, as described below),
130show the number of dropped packets.
131.It \*[address_family]
132Limit statistics or address control block reports to those
133of the specified
134.Ar address_families  .
135The following address families
136are recognized:
137.Ar inet ,
138for
139.Dv AF_INET ;
140.Ar inet6 ,
141for
142.Dv AF_INET6 ;
143.Ar arp ,
144for
145.Dv AF_ARP ;
146.Ar ns ,
147for
148.Dv AF_NS ;
149.Ar atalk ,
150for
151.Dv AF_APPLETALK ;
152.Ar mpls ,
153for
154.Dv AF_MPLS ;
155and
156.Ar local
157or
158.Ar unix ,
159for
160.Dv AF_LOCAL .
161.It Fl g
162Show information related to multicast (group address) routing.
163By default, show the IP Multicast virtual-interface and routing tables.
164If the
165.Fl s
166option is also present, show multicast routing statistics.
167.It Fl h
168When used with
169.Fl b
170in combination with either
171.Fl i
172or
173.Fl I ,
174output "human-readable" byte counts.
175.It Fl I Ar interface
176Show information about the specified interface;
177used with a
178.Ar wait
179interval as described below.
180If the
181.Fl f Ar address_family
182option (with the
183.Fl s
184option) or the
185.Fl p Ar protocol
186option is present, show per-interface statistics on the
187.Ar interface
188for the specified
189.Ar address_family
190or
191.Ar protocol ,
192respectively.
193.It Fl i
194Show the state of interfaces which have been auto-configured
195(interfaces statically configured into a system, but not
196located at boot time are not shown).
197If the
198.Fl a
199options is also present, multicast addresses currently in use are shown
200for each Ethernet interface and for each IP interface address.
201Multicast addresses are shown on separate lines following the interface
202address with which they are associated.
203If the
204.Fl f Ar address_family
205option (with the
206.Fl s
207option) or the
208.Fl p Ar protocol
209option is present, show per-interface statistics on all interfaces
210for the specified
211.Ar address_family
212or
213.Ar protocol ,
214respectively.
215.It Fl L
216Don't show link-level routes (e.g., IPv4 ARP or IPv6 neighbour cache).
217.It Fl l
218With the
219.Fl g
220option, display wider fields for the IPv6 multicast routing table
221.Qq Origin
222and
223.Qq Group
224columns.
225.It Fl M Ar core
226Use
227.Xr kvm 3
228instead of
229.Xr sysctl 3
230to retrieve information and
231extract values associated with the name list from the specified core.
232If the
233.Fl M
234option is not given but the
235.Fl N
236option is given, the default
237.Pa /dev/mem
238is used.
239.It Fl m
240Show statistics recorded by the mbuf memory management routines
241(the network manages a private pool of memory buffers).
242If the kernel option
243.Cd options MBUFTRACE
244is set, extra info can be retrieved with
245.Fl mssv .
246See also
247.Xr options 4 .
248.It Fl N Ar system
249Use
250.Xr kvm 3
251instead of
252.Xr sysctl 3
253to retrieve information and extract the name list from the specified system.
254For the default behavior when only
255.Fl M
256option is given, see the description about when
257.Fa execfile
258is
259.Dv NULL
260in
261.Xr kvm_openfiles 3 .
262.It Fl n
263Show network addresses and ports as numbers (normally
264.Nm
265interprets addresses and ports and attempts to display them
266symbolically).
267This option may be used with any of the display formats.
268.It Fl P Ar pcbaddr
269Dump the contents of the protocol control block (PCB) located at kernel
270virtual address
271.Ar pcbaddr .
272This address may be obtained using the
273.Fl A
274flag.
275The default protocol is TCP, but may be overridden using the
276.Fl p
277flag.
278.It Fl p Ar protocol
279Show statistics about
280.Ar protocol  ,
281which is either a well-known name for a protocol or an alias for it.
282Some protocol names and aliases are listed in the file
283.Pa /etc/protocols .
284A null response typically means that there are no interesting numbers to
285report.
286The program will complain if
287.Ar protocol
288is unknown or if there is no statistics routine for it.
289.It Fl q
290Show software interrupt queue setting/statistics for all protocols.
291.It Fl r
292Show the routing tables.
293When
294.Fl s
295is also present, show routing statistics instead.
296.It Fl S
297Show network addresses as numbers (as with
298.Fl n ,
299but show ports symbolically).
300.It Fl s
301Show per-protocol statistics.
302If this option is repeated, counters with a value of zero are suppressed.
303.It Fl T
304Show MPLS Tags for the routing tables.
305If multiple tags exists, they will
306be comma separated, first tag being the BoS one.
307.It Fl t
308With the
309.Fl i
310option, display the current value of the watchdog timer function.
311.It Fl v
312Show extra (verbose) detail for the routing tables
313.Pq Fl r ,
314or avoid truncation of long addresses.
315.It Fl w Ar wait
316Show network interface statistics at intervals of
317.Ar wait
318seconds.
319.It Fl X
320Force use of
321.Xr sysctl 3
322when retrieving information.
323Some features of
324.Nm
325may not be (fully) supported when using
326.Xr sysctl 3 .
327This flag forces the use of the latter regardless, and emits a message if a
328not yet fully supported feature is used in conjunction with it.
329This flag might be removed at any time; do not rely on its presence.
330.El
331.Pp
332The default display, for active sockets, shows the local
333and remote addresses, send and receive queue sizes (in bytes), protocol,
334and the internal state of the protocol.
335Address formats are of the form ``host.port'' or ``network.port''
336if a socket's address specifies a network but no specific host address.
337When known the host and network addresses are displayed symbolically
338according to the data bases
339.Pa /etc/hosts
340and
341.Pa /etc/networks ,
342respectively.
343If a symbolic name for an address is unknown, or if
344the
345.Fl n
346option is specified, the address is printed numerically, according
347to the address family.
348For more information regarding
349the Internet ``dot format,''
350refer to
351.Xr inet 3 ) .
352Unspecified,
353or ``wildcard'', addresses and ports appear as ``*''.
354You can use the
355.Xr fstat 1
356command to find out which process or processes hold references to a socket.
357.Pp
358The interface display provides a table of cumulative
359statistics regarding packets transferred, errors, and collisions.
360The network addresses of the interface
361and the maximum transmission unit (``mtu'') are also displayed.
362.Pp
363The routing table display indicates the available routes and
364their status.
365Each route consists of a destination host or network
366and a gateway to use in forwarding packets.
367The flags field shows
368a collection of information about the route stored as
369binary choices.
370The individual flags are discussed in more
371detail in the
372.Xr route 8
373and
374.Xr route 4
375manual pages.
376.Pp
377Direct routes are created for each
378interface attached to the local host;
379the gateway field for such entries shows the address of the outgoing interface.
380The refcnt field gives the
381current number of active uses of the route.
382Connection oriented
383protocols normally hold on to a single route for the duration of
384a connection while connectionless protocols obtain a route while sending
385to the same destination.
386The use field provides a count of the number of packets
387sent using that route.
388The mtu entry shows the mtu associated with
389that route.
390This mtu value is used as the basis for the TCP maximum
391segment size.
392The 'L' flag appended to the mtu value indicates that
393the value is locked, and that path mtu discovery is turned off for
394that route.
395A
396.Sq -
397indicates that the mtu for this route has not been set, and a default
398TCP maximum segment size will be used.
399The interface entry indicates
400the network interface used for the route.
401.Pp
402When
403.Nm
404is invoked with the
405.Fl w
406option and a
407.Ar wait
408interval argument, it displays a running count of statistics related to
409network interfaces.
410An obsolescent version of this option used a numeric parameter
411with no option, and is currently supported for backward compatibility.
412This display consists of a column for the primary interface (the first
413interface found during autoconfiguration) and a column summarizing
414information for all interfaces.
415The primary interface may be replaced with another interface with the
416.Fl I
417option.
418The first line of each screen of information contains a summary since the
419system was last rebooted.
420Subsequent lines of output show values
421accumulated over the preceding interval.
422.Pp
423The first character of the flags column in the
424.Fl B
425option shows the status of the
426.Xr bpf 4
427descriptor which has three different values:
428Idle ('I'), Waiting ('W') and Timed Out ('T').
429The second character indicates whether the promisc flag is set.
430The third character indicates the status of the immediate mode.
431The fourth character indicates whether the peer will have the ability
432to see the packets sent.
433And the fifth character shows the header complete flag status.
434.Sh SEE ALSO
435.Xr fstat 1 ,
436.Xr nfsstat 1 ,
437.Xr ps 1 ,
438.Xr sockstat 1 ,
439.Xr vmstat 1 ,
440.Xr inet 3 ,
441.Xr kvm 3 ,
442.Xr kvm_openfiles 3 ,
443.Xr sysctl 3 ,
444.Xr bpf 4 ,
445.Xr options 4 ,
446.Xr route 4 ,
447.Xr hosts 5 ,
448.Xr networks 5 ,
449.Xr protocols 5 ,
450.Xr services 5 ,
451.Xr ifmcstat 8 ,
452.Xr iostat 8 ,
453.Xr route 8 ,
454.Xr trpt 8
455.Sh HISTORY
456The
457.Nm
458command appeared in
459.Bx 4.2 .
460IPv6 support was added by WIDE/KAME project.
461.\" .Sh FILES
462.\" .Bl -tag -width /dev/mem -compact
463.\" .It Pa /netbsd
464.\" default kernel namelist
465.\" .It Pa /dev/mem
466.\" default memory file
467.\" .El
468.Sh BUGS
469The notion of errors is ill-defined.
470