1.\" $NetBSD: netstat.1,v 1.55 2010/02/24 11:00:27 pooka 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 February 24, 2009 33.Dt NETSTAT 1 34.Os 35.Sh NAME 36.Nm netstat 37.Nd show network status 38.Sh SYNOPSIS 39.Nm 40.Op Fl Aan 41.Op Fl f Ar address_family 42.Op Fl M Ar core 43.Op Fl N Ar system 44.Nm 45.Op Fl bdghiLmnqrSsv 46.Op Fl f Ar address_family 47.Op Fl M Ar core 48.Op Fl N Ar system 49.Nm 50.Op Fl dn 51.Op Fl I Ar interface 52.Op Fl M Ar core 53.Op Fl N Ar system 54.Op Fl w Ar wait 55.Nm 56.Op Fl M Ar core 57.Op Fl N Ar system 58.Op Fl p Ar protocol 59.Nm 60.Op Fl M Ar core 61.Op Fl N Ar system 62.Op Fl p Ar protocol 63.Fl P Ar pcbaddr 64.Nm 65.Op Fl i 66.Op Fl I Ar Interface 67.Op Fl p Ar protocol 68.Nm 69.Op Fl is 70.Op Fl f Ar address_family 71.Op Fl I Ar Interface 72.Nm 73.Op Fl s 74.Op Fl I Ar Interface 75.Fl B 76.Sh DESCRIPTION 77The 78.Nm 79command symbolically displays the contents of various network-related 80data structures. 81There are a number of output formats, 82depending on the options for the information presented. 83The first form of the command displays a list of active sockets for 84each protocol. 85The second form presents the contents of one of the other network 86data structures according to the option selected. 87Using the third form, with a 88.Ar wait 89interval specified, 90.Nm 91will continuously display the information regarding packet 92traffic on the configured network interfaces. 93The fourth form displays statistics about the named protocol. 94The fifth and sixth forms display per interface statistics for 95the specified protocol or address family. 96.Pp 97The options have the following meaning: 98.Bl -tag -width flag 99.It Fl A 100With the default display, 101show the address of any protocol control blocks associated with sockets; used 102for debugging. 103.It Fl a 104With the default display, 105show the state of all sockets; normally sockets used by 106server processes are not shown. 107.It Fl B 108With the default display, 109show the current 110.Xr bpf 4 111peers. 112To show only the peers listening to a specific interface, 113use the 114.Fl I 115option. 116If the 117.Fl s 118option is present, show the current 119.Xr bpf 4 120statistics. 121.It Fl b 122With the interface display (option 123.Fl i ) , 124show bytes in and out, instead of packets in and out. 125.It Fl d 126With either interface display (option 127.Fl i 128or an interval, as described below), 129show the number of dropped packets. 130.It Fl f Ar address_family 131Limit statistics or address control block reports to those 132of the specified 133.Ar address_family . 134The following address families 135are recognized: 136.Ar inet , 137for 138.Dv AF_INET ; 139.Ar inet6 , 140for 141.Dv AF_INET6 ; 142.Ar arp , 143for 144.Dv AF_ARP ; 145.Ar ns , 146for 147.Dv AF_NS ; 148.Ar iso , 149for 150.Dv AF_ISO ; 151.Ar atalk , 152for 153.Dv AF_APPLETALK ; 154and 155.Ar local 156or 157.Ar unix , 158for 159.Dv AF_LOCAL . 160.It Fl g 161Show information related to multicast (group address) routing. 162By default, show the IP Multicast virtual-interface and routing tables. 163If the 164.Fl s 165option is also present, show multicast routing statistics. 166.It Fl I Ar interface 167Show information about the specified interface; 168used with a 169.Ar wait 170interval as described below. 171If the 172.Fl f Ar address_family 173option (with the 174.Fl s 175option) or the 176.Fl p Ar protocol 177option is present, show per-interface statistics on the 178.Ar interface 179for the specified 180.Ar address_family 181or 182.Ar protocol , 183respectively. 184.It Fl h 185When used with 186.Fl b 187in combination with either 188.Fl i 189or 190.Fl I , 191output "human-readable" byte counts. 192.It Fl i 193Show the state of interfaces which have been auto-configured 194(interfaces statically configured into a system, but not 195located at boot time are not shown). 196If the 197.Fl a 198options is also present, multicast addresses currently in use are shown 199for each Ethernet interface and for each IP interface address. 200Multicast addresses are shown on separate lines following the interface 201address with which they are associated. 202If the 203.Fl f Ar address_family 204option (with the 205.Fl s 206option) or the 207.Fl p Ar protocol 208option is present, show per-interface statistics on all interfaces 209for the specified 210.Ar address_family 211or 212.Ar protocol , 213respectively. 214.It Fl L 215Don't show link-level routes (e.g., IPv4 ARP or IPv6 neighbour cache). 216.It Fl M 217Extract values associated with the name list from the specified core 218instead of the default 219.Pa /dev/kmem . 220.It Fl m 221Show statistics recorded by the memory management routines 222(the network manages a private pool of memory buffers). 223.It Fl N 224Extract the name list from the specified system instead of the default 225.Pa /netbsd . 226.It Fl n 227Show network addresses and ports as numbers (normally 228.Nm 229interprets addresses and ports and attempts to display them 230symbolically). 231This option may be used with any of the display formats. 232.It Fl P Ar pcbaddr 233Dump the contents of the protocol control block (PCB) located at kernel 234virtual address 235.Ar pcbaddr . 236This address may be obtained using the 237.Fl A 238flag. 239The default protocol is TCP, but may be overridden using the 240.Fl p 241flag. 242.It Fl p Ar protocol 243Show statistics about 244.Ar protocol , 245which is either a well-known name for a protocol or an alias for it. 246Some protocol names and aliases are listed in the file 247.Pa /etc/protocols . 248A null response typically means that there are no interesting numbers to 249report. 250The program will complain if 251.Ar protocol 252is unknown or if there is no statistics routine for it. 253.It Fl q 254Show software interrupt queue setting/statistics for all protocols. 255.It Fl r 256Show the routing tables. 257When 258.Fl s 259is also present, show routing statistics instead. 260.It Fl S 261Show network addresses as numbers (as with 262.Fl n , 263but show ports symbolically). 264.It Fl s 265Show per-protocol statistics. 266If this option is repeated, counters with a value of zero are suppressed. 267.It Fl v 268Show extra (verbose) detail for the routing tables 269.Pq Fl r , 270or avoid truncation of long addresses. 271.It Fl w Ar wait 272Show network interface statistics at intervals of 273.Ar wait 274seconds. 275.It Fl X 276Force use of 277.Xr sysctl 3 278when retrieving information. 279Some features of 280.Nm 281may not be (fully) supported when using 282.Xr sysctl 3 . 283This flag forces the use of the latter regardless, and emits a message if a 284not yet fully supported feature is used in conjunction with it. 285This flag might be removed at any time; do not rely on its presence. 286.El 287.Pp 288The default display, for active sockets, shows the local 289and remote addresses, send and receive queue sizes (in bytes), protocol, 290and the internal state of the protocol. 291Address formats are of the form ``host.port'' or ``network.port'' 292if a socket's address specifies a network but no specific host address. 293When known the host and network addresses are displayed symbolically 294according to the data bases 295.Pa /etc/hosts 296and 297.Pa /etc/networks , 298respectively. 299If a symbolic name for an address is unknown, or if 300the 301.Fl n 302option is specified, the address is printed numerically, according 303to the address family. 304For more information regarding 305the Internet ``dot format,'' 306refer to 307.Xr inet 3 ) . 308Unspecified, 309or ``wildcard'', addresses and ports appear as ``*''. 310You can use the 311.Xr fstat 1 312command to find out which process or processes hold references to a socket. 313.Pp 314The interface display provides a table of cumulative 315statistics regarding packets transferred, errors, and collisions. 316The network addresses of the interface 317and the maximum transmission unit (``mtu'') are also displayed. 318.Pp 319The routing table display indicates the available routes and 320their status. 321Each route consists of a destination host or network 322and a gateway to use in forwarding packets. 323The flags field shows 324a collection of information about the route stored as 325binary choices. 326The individual flags are discussed in more 327detail in the 328.Xr route 8 329and 330.Xr route 4 331manual pages. 332The mapping between letters and flags is: 333.Bl -column XXXX RTF_BLACKHOLE 334.It 1 RTF_PROTO1 Protocol specific routing flag #1 335.It 2 RTF_PROTO2 Protocol specific routing flag #2 336.It B RTF_BLACKHOLE Just discard pkts (during updates) 337.It C RTF_CLONING Generate new routes on use 338.It c RTF_CLONED Cloned routes (generated from RTF_CLONING) 339.It D RTF_DYNAMIC Created dynamically (by redirect) 340.It G RTF_GATEWAY Destination requires forwarding by intermediary 341.It H RTF_HOST Host entry (net otherwise) 342.It L RTF_LLINFO Valid protocol to link address translation. 343.It M RTF_MODIFIED Modified dynamically (by redirect) 344.It R RTF_REJECT Host or net unreachable 345.It S RTF_STATIC Manually added 346.It U RTF_UP Route usable 347.It X RTF_XRESOLVE External daemon translates proto to link address 348.El 349.Pp 350Direct routes are created for each 351interface attached to the local host; 352the gateway field for such entries shows the address of the outgoing interface. 353The refcnt field gives the 354current number of active uses of the route. 355Connection oriented 356protocols normally hold on to a single route for the duration of 357a connection while connectionless protocols obtain a route while sending 358to the same destination. 359The use field provides a count of the number of packets 360sent using that route. 361The mtu entry shows the mtu associated with 362that route. 363This mtu value is used as the basis for the TCP maximum 364segment size. 365The 'L' flag appended to the mtu value indicates that 366the value is locked, and that path mtu discovery is turned off for 367that route. 368A 369.Sq - 370indicates that the mtu for this route has not been set, and a default 371TCP maximum segment size will be used. 372The interface entry indicates 373the network interface used for the route. 374.Pp 375When 376.Nm 377is invoked with the 378.Fl w 379option and a 380.Ar wait 381interval argument, it displays a running count of statistics related to 382network interfaces. 383An obsolescent version of this option used a numeric parameter 384with no option, and is currently supported for backward compatibility. 385This display consists of a column for the primary interface (the first 386interface found during autoconfiguration) and a column summarizing 387information for all interfaces. 388The primary interface may be replaced with another interface with the 389.Fl I 390option. 391The first line of each screen of information contains a summary since the 392system was last rebooted. 393Subsequent lines of output show values 394accumulated over the preceding interval. 395.Pp 396The first character of the flags column in the 397.Fl B 398option shows the status of the 399.Xr bpf 4 400descriptor which has three different values: 401Idle ('I'), Waiting ('W') and Timed Out ('T'). 402The second character indicates whether the promisc flag is set. 403The third character indicates the status of the immediate mode. 404The fourth character indicates whether the peer will have the ability 405to see the packets sent. 406And the fifth character shows the header complete flag status. 407.Sh SEE ALSO 408.Xr fstat 1 , 409.Xr nfsstat 1 , 410.Xr ps 1 , 411.Xr sockstat 1 , 412.Xr vmstat 1 , 413.Xr inet 3 , 414.Xr bpf 4 , 415.Xr hosts 5 , 416.Xr networks 5 , 417.Xr protocols 5 , 418.Xr services 5 , 419.Xr iostat 8 , 420.Xr trpt 8 421.Sh HISTORY 422The 423.Nm 424command appeared in 425.Bx 4.2 . 426IPv6 support was added by WIDE/KAME project. 427.\" .Sh FILES 428.\" .Bl -tag -width /dev/kmem -compact 429.\" .It Pa /netbsd 430.\" default kernel namelist 431.\" .It Pa /dev/kmem 432.\" default memory file 433.\" .El 434.Sh BUGS 435The notion of errors is ill-defined. 436