Geavanceerd
Zoeken inHow-to-gidsen
Zo zoek je
  • Typ de taak in je eigen woorden (poort vinden, firewall openen, schijf vol) of plak een foutmelding tussen aanhalingstekens.
  • Kies "Snel antwoord" om alleen de commando's te zien, of een gebied om in één vakgebied te blijven.
  • "twee woorden" vindt precies die zin.
  • Gewone woorden vinden namen, teksten en voorbeelden.
  • ↑ ↓ bewegen · Enter openen · Esc sluiten · / zoeken
Probeer:

How-to 219System · Kernel

How to change kernel settings with sysctl

Turn on IP forwarding for a router or Kubernetes node, raise the connection backlog for a busy web server, make the kernel less eager to swap, hide kernel pointers from normal users — all are kernel parameters, changed at runtime with sysctl and made permanent with a file in /etc/sysctl.d/. This how-to reads, changes and persists them, with useful examples and the traps.

  • 5 Lessen
  • 5 Commando's

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

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

219.1

The quick answer

sysctl net.ipv4.ip_forward
sysctl -w net.ipv4.ip_forward=1
echo 'net.ipv4.ip_forward = 1' > /etc/sysctl.d/90-router.conf
sysctl --system

219.2

Step by step

  1. Read a value (line 1) — names map to files under /proc/sys (net.ipv4.ip_forward = /proc/sys/net/ipv4/ip_forward). sysctl -a | grep somaxconn searches all.
  2. Change it now (line 2) — takes effect at once, but is lost at reboot.
  3. Make it permanent (lines 3–4) — one file per purpose in /etc/sysctl.d/, with a comment why. Files are read in name order; a higher number wins. sysctl --system loads all files now and prints what it applied.
  4. Useful examples:
/etc/sysctl.d/90-web.conf
# busy web server: longer accept queue
net.core.somaxconn = 4096
net.ipv4.tcp_max_syn_backlog = 4096
 
# database server: swap only under real pressure
vm.swappiness = 10
 
# security hardening
kernel.dmesg_restrict = 1
kernel.kptr_restrict = 2
net.ipv4.conf.all.accept_redirects = 0
net.ipv4.conf.all.send_redirects = 0
net.ipv4.tcp_syncookies = 1
  1. Kubernetes nodes need net.ipv4.ip_forward = 1 and, with the br_netfilter module loaded, net.bridge.bridge-nf-call-iptables = 1.
  2. Change one thing at a time and measure; copy-paste "tuning" lists from the internet often do nothing or harm. Note the old value before changing.
  3. Containers — some net.* settings are per network namespace and can be set per Pod/container (securityContext.sysctls, docker run --sysctl); host-wide ones (vm.*) only on the node.

219.3

Check that it worked

sysctl net.ipv4.ip_forward prints = 1; after a reboot it still does; sysctl --system lists your file and its values without errors.

219.4

Common problems

ProblemCauseFix
Value back to the old one after rebootOnly set with -w.Put it in /etc/sysctl.d/*.conf.
Another file overrides yoursA file with a higher name order sets the same key.grep -r KEY /etc/sysctl.d /usr/lib/sysctl.d /etc/sysctl.conf; rename yours (99-).
cannot stat /proc/sys/net/bridge/…Module br_netfilter not loaded.Load it (and at boot), then apply again.
permission denied in a containerHost-wide key.Set it on the host/node.
No visible effectThe app has its own limit (for example listen backlog).Raise the app setting too.
sysctl: setting key …: Invalid argumentWrong value or unit.Check the kernel documentation for that key.

Commando's in deze les

219.5

Go further

1How do you make a sysctl change survive a reboot?

Put the setting in a file in /etc/sysctl.d/ and load it with sysctl --system.

2Where does sysctl read and write its values?

In the files under /proc/sys; the dots in the name are the folder levels.

Alle commando's in dit hoofdstuk