SYSCTL
Section: Linux Programmer's Manual (2)Updated: 2017-09-15
Index Return to Main Contents
NAME
sysctl - read/write system parametersSYNOPSIS
#include <unistd.h> #include <linux/sysctl.h> int _sysctl(struct __sysctl_args *args);
Note: There is no glibc wrapper for this system call; see NOTES.
DESCRIPTION
Do not use this system call! See NOTES.The _sysctl() call reads and/or writes kernel parameters. For example, the hostname, or the maximum number of open files. The argument has the form
struct __sysctl_args {
int *name; /* integer vector describing variable */
int nlen; /* length of this vector */
void *oldval; /* 0 or address where to store old value */
size_t *oldlenp; /* available room for old value,
overwritten by actual size of old value */
void *newval; /* 0 or address of new value */
size_t newlen; /* size of new value */
};
This call does a search in a tree structure, possibly resembling a directory tree under /proc/sys, and if the requested item is found calls some appropriate routine to read or modify the value.
RETURN VALUE
Upon successful completion, _sysctl() returns 0. Otherwise, a value of -1 is returned and errno is set to indicate the error.ERRORS
- EACCES, EPERM
- No search permission for one of the encountered "directories", or no read permission where oldval was nonzero, or no write permission where newval was nonzero.
- EFAULT
- The invocation asked for the previous value by setting oldval non-NULL, but allowed zero room in oldlenp.
- ENOTDIR
- name was not found.
CONFORMING TO
This call is Linux-specific, and should not be used in programs intended to be portable. A sysctl() call has been present in Linux since version 1.3.57. It originated in 4.4BSD. Only Linux has the /proc/sys mirror, and the object naming schemes differ between Linux and 4.4BSD, but the declaration of the sysctl() function is the same in both.NOTES
Glibc does not provide a wrapper for this system call; call it using syscall(2). Or rather... don't call it: use of this system call has long been discouraged, and it is so unloved that it is likely to disappear in a future kernel version. Since Linux 2.6.24, uses of this system call result in warnings in the kernel log. Remove it from your programs now; use the /proc/sys interface instead.This system call is available only if the kernel was configured with the CONFIG_SYSCTL_SYSCALL option.
BUGS
The object names vary between kernel versions, making this system call worthless for applications.Not all available objects are properly documented.
It is not yet possible to change operating system by writing to /proc/sys/kernel/ostype.
EXAMPLE
#define _GNU_SOURCE #include <unistd.h> #include <sys/syscall.h> #include <string.h> #include <stdio.h> #include <stdlib.h> #include <linux/sysctl.h>int _sysctl(struct __sysctl_args *args );
#define OSNAMESZ 100
int
main(void)
{
struct __sysctl_args args;
char osname[OSNAMESZ];
size_t osnamelth;
int name[] = { CTL_KERN, KERN_OSTYPE };
memset(&args, 0, sizeof(struct __sysctl_args));
args.name = name;
args.nlen = sizeof(name)/sizeof(name[0]);
args.oldval = osname;
args.oldlenp = &osnamelth;
osnamelth = sizeof(osname);
if (syscall(SYS__sysctl, &args) == -1) {
perror("_sysctl");
exit(EXIT_FAILURE);
}
printf("This machine is running %*s\n", osnamelth, osname);
exit(EXIT_SUCCESS);
}
SEE ALSO
proc(5)COLOPHON
This page is part of release 4.15 of the Linux man-pages project. A description of the project, information about reporting bugs, and the latest version of this page, can be found at https://www.kernel.org/doc/man-pages/.
Index
This document was created by man2html, using the manual pages.
Time: 04:45:35 GMT, September 16, 2022 Content-type: text/html; charset=UTF-8
SYSCTL.D
Section: sysctl.d (5)Updated:
Index Return to Main Contents
NAME
sysctl.d - Configure kernel parameters at bootSYNOPSIS
/etc/sysctl.d/*.conf
/run/sysctl.d/*.conf
DESCRIPTION
At boot, systemd-sysctl.service(8) reads configuration files from the above directories to configure sysctl(8) kernel parameters.
CONFIGURATION FORMAT
The configuration files contain a list of variable assignments, separated by newlines. Empty lines and lines whose first non-whitespace character is "#" or ";" are ignored.
Note that either "/" or "." may be used as separators within sysctl variable names. If the first separator is a slash, remaining slashes and dots are left intact. If the first separator is a dot, dots and slashes are interchanged. "kernel.domainname=foo" and "kernel/domainname=foo" are equivalent and will cause "foo" to be written to /proc/sys/kernel/domainname. Either "net.ipv4.conf.enp3s0/200.forwarding" or "net/ipv4/conf/enp3s0.200/forwarding" may be used to refer to /proc/sys/net/ipv4/conf/enp3s0.200/forwarding.
The settings configured with sysctl.d files will be applied early on boot. The network interface-specific options will also be applied individually for each network interface as it shows up in the system. (More specifically, net.ipv4.conf.*, net.ipv6.conf.*, net.ipv4.neigh.* and net.ipv6.neigh.*).
Many sysctl parameters only become available when certain kernel modules are loaded. Modules are usually loaded on demand, e.g. when certain hardware is plugged in or network brought up. This means that systemd-sysctl.service(8) which runs during early boot will not configure such parameters if they become available after it has run. To set such parameters, it is recommended to add an udev(7) rule to set those parameters when they become available. Alternatively, a slightly simpler and less efficient option is to add the module to modules-load.d(5), causing it to be loaded statically before sysctl settings are applied (see example below).
CONFIGURATION DIRECTORIES AND PRECEDENCE
Configuration files are read from directories in /etc/, /run/, and /lib/, in order of precedence. Each configuration file in these configuration directories shall be named in the style of filename.conf. Files in /etc/ override files with the same name in /run/ and /lib/. Files in /run/ override files with the same name in /lib/.
Packages should install their configuration files in /lib/. Files in /etc/ are reserved for the local administrator, who may use this logic to override the configuration files installed by vendor packages. All configuration files are sorted by their filename in lexicographic order, regardless of which of the directories they reside in. If multiple files specify the same option, the entry in the file with the lexicographically latest name will take precedence. It is recommended to prefix all filenames with a two-digit number and a dash, to simplify the ordering of the files.
If the administrator wants to disable a configuration file supplied by the vendor, the recommended way is to place a symlink to /dev/null in the configuration directory in /etc/, with the same filename as the vendor configuration file. If the vendor configuration file is included in the initrd image, the image has to be regenerated.
EXAMPLES
Example 1. Set kernel YP domain name
/etc/sysctl.d/domain-name.conf:
-
kernel.domainname=example.com
Example 2. Apply settings available only when a certain module is loaded (method one)
/etc/udev/rules.d/99-bridge.rules:
-
ACTION=="add", SUBSYSTEM=="module", KERNEL=="br_netfilter", \ RUN+="/lib/systemd/systemd-sysctl --prefix=/net/bridge"
/etc/sysctl.d/bridge.conf:
-
net.bridge.bridge-nf-call-ip6tables = 0 net.bridge.bridge-nf-call-iptables = 0 net.bridge.bridge-nf-call-arptables = 0
This method applies settings when the module is loaded. Please note that, unless the br_netfilter module is loaded, bridged packets will not be filtered by Netfilter (starting with kernel 3.18), so simply not loading the module is sufficient to avoid filtering.
Example 3. Apply settings available only when a certain module is loaded (method two)
/etc/modules-load.d/bridge.conf:
-
br_netfilter
/etc/sysctl.d/bridge.conf:
-
net.bridge.bridge-nf-call-ip6tables = 0 net.bridge.bridge-nf-call-iptables = 0 net.bridge.bridge-nf-call-arptables = 0
This method forces the module to be always loaded. Please note that, unless the br_netfilter module is loaded, bridged packets will not be filtered with Netfilter (starting with kernel 3.18), so simply not loading the module is sufficient to avoid filtering.
SEE ALSO
systemd(1), systemd-sysctl.service(8), systemd-delta(1), sysctl(8), sysctl.conf(5), modprobe(8)
Index
- NAME
- SYNOPSIS
- DESCRIPTION
- CONFIGURATION FORMAT
- CONFIGURATION DIRECTORIES AND PRECEDENCE
- EXAMPLES
- SEE ALSO
This document was created by man2html, using the manual pages.
Time: 04:45:54 GMT, September 16, 2022 Content-type: text/html; charset=UTF-8
SYSCTL.CONF
Section: File Formats (5)Updated: January 2012
Index Return to Main Contents
NAME
sysctl.conf - sysctl preload/configuration fileDESCRIPTION
sysctl.conf is a simple file containing sysctl values to be read in and set by sysctl. The syntax is simply as follows:-
# comment ; comment token = value
Note that blank lines are ignored, and whitespace before and after a token or value is ignored, although a value can contain whitespace within. Lines which begin with a # or ; are considered comments and ignored.
EXAMPLE
-
# sysctl.conf sample # kernel.domainname = example.com ; this one has a space which will be written to the sysctl! kernel.modprobe = /sbin/mod probe
FILES
- /run/sysctl.d/*.conf
- /etc/sysctl.d/*.conf /usr/local/lib/sysctl.d/*.conf /usr/lib/sysctl.d/*.conf /lib/sysctl.d/*.conf /etc/sysctl.conf The paths where sysctl preload files usually exist. See also sysctl option --system.
SEE ALSO
sysctl(8)AUTHOR
George StaikosREPORTING BUGS
Please send bug reports to
Index
This document was created by man2html, using the manual pages.
Time: 04:45:56 GMT, September 16, 2022 Content-type: text/html; charset=UTF-8
SYSCTL
Section: System Administration (8)Updated: Jan 2012
Index Return to Main Contents
NAME
sysctl - configure kernel parameters at runtimeSYNOPSIS
sysctl [options] [variable[=value]] [...]sysctl -p [file or regexp] [...]
DESCRIPTION
sysctl is used to modify kernel parameters at runtime. The parameters available are those listed under /proc/sys/. Procfs is required for sysctl support in Linux. You can use sysctl to both read and write sysctl data.PARAMETERS
- variable
- The name of a key to read from. An example is kernel.ostype. The '/' separator is also accepted in place of a '.'.
- variable=value
- To set a key, use the form variable=value where variable is the key and value is the value to set it to. If the value contains quotes or characters which are parsed by the shell, you may need to enclose the value in double quotes. This requires the -w parameter to use.
- -n, --values
- Use this option to disable printing of the key name when printing values.
- -e, --ignore
- Use this option to ignore errors about unknown keys.
- -N, --names
- Use this option to only print the names. It may be useful with shells that have programmable completion.
- -q, --quiet
- Use this option to not display the values set to stdout.
- -w, --write
- Use this option when you want to change a sysctl setting.
- -p[FILE], --load[=FILE]
- Load in sysctl settings from the file specified or /etc/sysctl.conf if none given. Specifying - as filename means reading data from standard input. Using this option will mean arguments to sysctl are files, which are read in the order they are specified. The file argument may be specified as regular expression.
- -a, --all
- Display all values currently available.
- --deprecated
- Include deprecated parameters to --all values listing.
- -b, --binary
- Print value without new line.
- --system
-
Load settings from all system configuration files.
/run/sysctl.d/*.conf
/etc/sysctl.d/*.conf
/usr/local/lib/sysctl.d/*.conf
/usr/lib/sysctl.d/*.conf
/lib/sysctl.d/*.conf
/etc/sysctl.conf - -r, --pattern pattern
- Only apply settings that match pattern. The pattern uses extended regular expression syntax.
- -A
- Alias of -a
- -d
- Alias of -h
- -f
- Alias of -p
- -X
- Alias of -a
- -o
- Does nothing, exists for BSD compatibility.
- -x
- Does nothing, exists for BSD compatibility.
- -h, --help
- Display help text and exit.
- -V, --version
- Display version information and exit.
EXAMPLES
/sbin/sysctl -a/sbin/sysctl -n kernel.hostname
/sbin/sysctl -w kernel.domainname="example.com"
/sbin/sysctl -p/etc/sysctl.conf
/sbin/sysctl -a --pattern forward
/sbin/sysctl -a --pattern forward$
/sbin/sysctl -a --pattern 'net.ipv4.conf.(eth|wlan)0.arp'
/sbin/sysctl --system --pattern '^net.ipv6'
DEPRECATED PARAMETERS
The base_reachable_time and retrans_time are deprecated. The sysctl command does not allow changing values of these parameters. Users who insist to use deprecated kernel interfaces should push values to /proc file system by other means. For example:echo 256 > /proc/sys/net/ipv6/neigh/eth0/base_reachable_time
FILES
/proc/sys/etc/sysctl.conf
SEE ALSO
sysctl.conf(5) regex(7)AUTHOR
George StaikosREPORTING BUGS
Please send bug reports to
Index
- NAME
- SYNOPSIS
- DESCRIPTION
- PARAMETERS
- EXAMPLES
- DEPRECATED PARAMETERS
- FILES
- SEE ALSO
- AUTHOR
- REPORTING BUGS
This document was created by man2html, using the manual pages.
Time: 04:46:01 GMT, September 16, 2022
0 댓글