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