jcs's openbsd hax
openbsd
1.\" $OpenBSD: sysctl.8,v 1.218 2025/04/29 17:44:00 jmc Exp $
2.\" $NetBSD: sysctl.8,v 1.4 1995/09/30 07:12:49 thorpej Exp $
3.\"
4.\" Copyright (c) 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.\" @(#)sysctl.8 8.2 (Berkeley) 5/9/95
32.\"
33.Dd $Mdocdate: April 29 2025 $
34.Dt SYSCTL 8
35.Os
36.Sh NAME
37.Nm sysctl
38.Nd get or set kernel state
39.Sh SYNOPSIS
40.Nm sysctl
41.Op Fl Aanq
42.Op Fl f Ar file
43.Op Ar name Ns Oo = Ns Ar value Oc Ar ...
44.Sh DESCRIPTION
45The
46.Nm
47utility retrieves kernel state and allows processes with
48appropriate privilege to set kernel state.
49The state to be retrieved or set is described using a
50.Dq Management Information Base
51.Pq MIB
52style name, using a dotted set of components.
53.Pp
54When retrieving a variable,
55a subset of the MIB name may be specified to retrieve a list of
56variables in that subset.
57For example, to list all the machdep variables:
58.Pp
59.Dl $ sysctl machdep
60.Pp
61The options are as follows:
62.Bl -tag -width xxx
63.It Fl A
64List all the known MIB names including tables.
65Those with string or integer values will be printed as with the
66.Fl a
67flag; for the table values, the name of the utility to retrieve them is given.
68.It Fl a
69List all the currently available string or integer values.
70This is the default, if no parameters are given to
71.Nm .
72.It Fl f Ar file
73Process
74.Ar name Ns Op = Ns Ar value
75arguments from
76.Ar file
77in
78.Xr sysctl.conf 5
79format.
80.It Fl n
81Suppress printing of the field name, only output the field value.
82Useful for setting shell variables.
83For example, to set the psize shell variable to the pagesize of the hardware:
84.Pp
85.Dl # set psize=`sysctl -n hw.pagesize`
86.It Fl q
87Suppress all output when setting a variable.
88This option overrides the behaviour of
89.Fl n .
90.It Ar name Ns Op = Ns Ar value
91Retrieve the specified variable
92.Ar name ,
93or attempt to set it to
94.Ar value .
95Multiple
96.Ar name Ns Op = Ns Ar value
97arguments may be given.
98If given,
99.Fl f Ar file
100is processed first.
101.El
102.Pp
103The information available from
104.Nm
105consists of integers, strings, and tables.
106For a detailed description of the variables, see
107.Xr sysctl 2 .
108Tables can only be retrieved by special purpose programs such as
109.Xr ps 1 ,
110.Xr systat 1 ,
111and
112.Xr netstat 1 .
113.Pp
114.Nm
115can extract information about the filesystems that have been compiled
116into the running system.
117This information can be obtained by using the command:
118.Pp
119.Dl $ sysctl vfs.mounts
120.Pp
121By default, only filesystems that are actively being used are listed.
122Use of the
123.Fl A
124flag lists all the filesystems compiled into the running kernel.
125.Sh FILES
126.Bl -tag -width "/etc/sysctl.confXX" -compact
127.It Pa /etc/sysctl.conf
128sysctl variables to set at system startup
129.El
130.Sh EXAMPLES
131To retrieve the maximum number of processes allowed
132in the system:
133.Pp
134.Dl $ sysctl kern.maxproc
135.Pp
136To set the maximum number of processes allowed
137in the system to 1000:
138.Pp
139.Dl # sysctl kern.maxproc=1000
140.Pp
141To retrieve information about the system clock rate:
142.Pp
143.Dl $ sysctl kern.clockrate
144.Pp
145To retrieve information about the load average history:
146.Pp
147.Dl $ sysctl vm.loadavg
148.Pp
149To set the list of reserved TCP ports that should not be allocated
150by the kernel dynamically:
151.Pp
152.Dl # sysctl net.inet.tcp.baddynamic=749,750,751,760,761,871
153.Dl # sysctl net.inet.udp.baddynamic=749,750,751,760,761,871,1024-2048
154.Pp
155This can be used to keep daemons
156from stealing a specific port that another program needs to function.
157List elements may be separated by commas and/or whitespace;
158a hyphen may be used to specify a range of ports.
159.Pp
160It is also possible to add or remove ports from the current list:
161.Bd -literal -offset indent
162# sysctl net.inet.tcp.baddynamic=+748,+6000-6999
163# sysctl net.inet.tcp.baddynamic=-871
164.Ed
165.Pp
166To set the amount of shared memory available in the system and
167the maximum number of shared memory segments:
168.Bd -literal -offset indent
169# sysctl kern.shminfo.shmmax=33554432
170# sysctl kern.shminfo.shmseg=32
171.Ed
172.Pp
173To place core dumps from
174.Xr issetugid 2
175programs (in this example
176.Xr bgpd 8 )
177into a safe place for debugging purposes:
178.Bd -literal -offset indent
179# mkdir -m 700 /var/crash/bgpd
180# sysctl kern.nosuidcoredump=3
181.Ed
182.Sh SEE ALSO
183.Xr sysctl 2 ,
184.Xr options 4 ,
185.Xr sysctl.conf 5
186.Sh HISTORY
187.Nm
188first appeared in
189.Bx 4.4 .