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