Filters
Zo zoek je
  • Gewone woorden vinden namen, teksten en voorbeelden.
  • "twee woorden" vindt precies die zin.
  • --naam of -x vindt een optie.
  • #woord zoekt alleen in commando's.
  • @grep vindt lessen en labs die grep gebruiken.
  • Filters: cat:network · in:labs · in:notes · level:rhcsa · ch:8 · root:yes. Zet ! voor een woord om het weg te laten. OR tussen woorden betekent één ervan.
  • ↑ ↓ bewegen · Enter openen · Esc sluiten · / zoeken

sysctl

Read and change kernel parameters at run time (the files under /proc/sys), and load them from config files.

Niveau
RHCSA-examen
Groep
Kernel en hardware
Root nodig
Voor wijzigingen
Pakket
procps-ng

Dit deel is nog niet vertaald. Je ziet de Engelse tekst.

Wat het doet

Every file in /proc/sys/ is a kernel setting; the dots in the name are slashes: net.ipv4.ip_forward = /proc/sys/net/ipv4/ip_forward. sysctl NAME reads it, sysctl -w NAME=VALUE changes it until reboot. For permanent values put NAME = VALUE lines in a file in /etc/sysctl.d/ and run sysctl --system.

Zo schrijf je het

sysctl [OPTION]... [NAME[=VALUE]]...
sysctl -p [FILE]
sysctl --system

Opties 14

Meest gebruikt

-w, --write
Change a value: -w NAME=VALUE.
-a, --all
Show all settings (-A, -X are aliases).
-p[FILE], --load[=FILE]
Load settings from a file (default /etc/sysctl.conf).
--system
Load all files from all sysctl.d folders.
-n, --values
Only the values.
-N, --names
Only the names.
-r, --pattern REGEX
Only names that match.
-e, --ignore
Ignore unknown names.
-q, --quiet
Do not print values when setting.
-b, --binary
Values without a newline.
--deprecated
Also show deprecated names.
-f
Same as -p.
-h, --help
Show help.
-V, --version
Show the version.

Voorbeelden 10

$ als gewone gebruiker# als root (of met sudo)

  1. 1Read a value

    sysctl net.ipv4.ip_forward
    net.ipv4.ip_forward = 0

    Same as cat /proc/sys/net/ipv4/ip_forward.

  2. 2Change it now

    sysctl -w net.ipv4.ip_forward=1

    Lost at reboot.

  3. 3Make it permanent

    echo "net.ipv4.ip_forward = 1" > /etc/sysctl.d/90-forward.conf
    sysctl --system

    Files are read in name order; later wins.

  4. 4Only the value

    sysctl -n vm.swappiness
    60

    For scripts.

  5. 5Search settings

    sysctl -a 2>/dev/null | grep -i swappiness

    Or sysctl -a -r swap.

  6. 6Lower swapping on a database server

    echo "vm.swappiness = 10" > /etc/sysctl.d/90-swap.conf; sysctl --system

    The kernel keeps more in RAM.

  7. 7Network hardening (security)

    cat /etc/sysctl.d/90-hardening.conf
    net.ipv4.conf.all.accept_redirects = 0
    net.ipv4.conf.all.send_redirects = 0
    net.ipv4.conf.all.rp_filter = 1
    net.ipv4.tcp_syncookies = 1
    kernel.kptr_restrict = 2
    kernel.dmesg_restrict = 1

    Common CIS benchmark settings.

  8. 8Load one file

    sysctl -p /etc/sysctl.d/90-hardening.conf

    Test a new file.

  9. 9More open files for big servers

    sysctl -w fs.file-max=2097152

    System-wide limit (per-process limits are in limits.conf/systemd).

  10. 10Where does a setting come from?

    grep -r swappiness /etc/sysctl.d/ /usr/lib/sysctl.d/ /etc/sysctl.conf

    tuned can also set values (check the tuned profile).

Bestanden

/etc/sysctl.d/*.conf
Your permanent settings.
/usr/lib/sysctl.d/
Defaults from packages.
/etc/sysctl.conf
Old main file (still read).
/proc/sys/
The live values.

Exitcodes

0Done.
1Error.
255Unknown setting or permission denied.