Skip to main content
  1. Linux Articles/
  2. Ubuntu 26.04 LTS Server/

Configuring Kernel Parameters on Ubuntu 26.04 LTS Server (sysctl)

Table of Contents

Checking and Changing Kernel Parameters

sysctl reads and changes settings of the running kernel. Memory behaviour, networking and limits such as the number of file watches can be changed without rebuilding the kernel or rebooting.

The settings appear as files under /proc/sys/, and the sysctl command reads and writes them. The dots in a parameter name map to directories: vm.swappiness is /proc/sys/vm/swappiness.

Reading the Current Values

sysctl -a lists every parameter. This system has about 1,200 of them.

Command to list every parameter
sysctl -a

Name one or more parameters to read them individually.

Command to read a parameter
sysctl [PARAMETER]
FieldValue
[PARAMETER]Parameter name, such as vm.swappiness
Example: reading parameters
kazulog@sv1:~$ sysctl -a 2>/dev/null | wc -l
1189
kazulog@sv1:~$ sysctl net.ipv4.ip_forward vm.swappiness fs.file-max fs.inotify.max_user_instances
net.ipv4.ip_forward = 0
vm.swappiness = 60
fs.file-max = 9223372036854775807
fs.inotify.max_user_instances = 128
kazulog@sv1:~$ cat /proc/sys/vm/swappiness
60
kazulog@sv1:~$

sysctl vm.swappiness and cat /proc/sys/vm/swappiness print the same value because they read the same thing.

Changing a Value Temporarily

sysctl -w sets a value. Writing to the file under /proc/sys/ does the same.

Command to change a parameter
sudo sysctl -w [PARAMETER]=[VALUE]
FieldValue
[PARAMETER]Parameter to change
[VALUE]Value to set
Example: changing a parameter
kazulog@sv1:~$ sudo sysctl -w vm.swappiness=10
vm.swappiness = 10
kazulog@sv1:~$ sysctl vm.swappiness
vm.swappiness = 10
kazulog@sv1:~$ cat /proc/sys/vm/swappiness
10
kazulog@sv1:~$ echo 20 | sudo tee /proc/sys/vm/swappiness
20
kazulog@sv1:~$ sysctl vm.swappiness
vm.swappiness = 20
A value set this way is lost at the next reboot. As shown below, the parameter returns to its default of 60. Use a configuration file, described next, to make a change permanent.
Example: the value after a reboot
kazulog@sv1:~$ uptime -p
up 0 minutes
kazulog@sv1:~$ sysctl vm.swappiness
vm.swappiness = 60

Making a Setting Permanent

To keep a setting across reboots, create a .conf file under /etc/sysctl.d/. Ubuntu 26.04 has no /etc/sysctl.conf.

Command to create a configuration file
printf 'vm.swappiness = 10\nnet.core.somaxconn = 1024\n' | sudo tee /etc/sysctl.d/99-[NAME].conf
FieldValue
[NAME]A name describing the settings (free choice)

Creating the file is not enough. Run sysctl --system to read every configuration file again.

Command to apply the settings
sudo sysctl --system
Example: creating and applying a configuration file
kazulog@sv1:~$ printf 'vm.swappiness = 10\nnet.core.somaxconn = 1024\n' | sudo tee /etc/sysctl.d/99-kazulog.conf
vm.swappiness = 10
net.core.somaxconn = 1024
kazulog@sv1:~$ sudo sysctl --system 2>&1 | tail -4
net.ipv6.conf.all.use_tempaddr = 0
net.ipv6.conf.default.use_tempaddr = 0
vm.swappiness = 10
net.core.somaxconn = 1024
kazulog@sv1:~$ sysctl vm.swappiness net.core.somaxconn
vm.swappiness = 10
net.core.somaxconn = 1024
kazulog@sv1:~$

The values survive a reboot.

Example: the values after a reboot
kazulog@sv1:~$ uptime -p
up 0 minutes
kazulog@sv1:~$ sysctl vm.swappiness net.core.somaxconn
vm.swappiness = 10
net.core.somaxconn = 1024

The Order the Files Are Read

sysctl --system reads settings from several directories and prints each file as it applies it.

Example: the files that are read
kazulog@sv1:~$ sudo sysctl --system 2>&1 | head -14
* Applying /usr/lib/sysctl.d/10-apparmor.conf ...
* Applying /usr/lib/sysctl.d/10-coredump-debian.conf ...
* Applying /usr/lib/sysctl.d/50-default.conf ...
* Applying /usr/lib/sysctl.d/50-pid-max.conf ...
* Applying /usr/lib/sysctl.d/55-bufferbloat.conf ...
* Applying /usr/lib/sysctl.d/55-console-messages.conf ...
* Applying /usr/lib/sysctl.d/55-ipv6-privacy.conf ...
* Applying /usr/lib/sysctl.d/55-kernel-hardening.conf ...
* Applying /usr/lib/sysctl.d/55-magic-sysrq.conf ...
* Applying /usr/lib/sysctl.d/55-map-count.conf ...
* Applying /usr/lib/sysctl.d/55-network-security.conf ...
* Applying /usr/lib/sysctl.d/55-ptrace.conf ...
* Applying /usr/lib/sysctl.d/55-zeropage.conf ...
* Applying /etc/sysctl.d/99-cloudimg-ipv6.conf ...
kazulog@sv1:~$
DirectoryPurpose
/usr/lib/sysctl.d/Settings shipped by packages. Do not edit
/run/sysctl.d/Settings generated at run time
/etc/sysctl.d/Where an administrator puts settings
When the same parameter appears in more than one file, the file read last wins. Files are read in name order across the directories, so a higher number takes precedence. That is why names beginning with 99- are common in /etc/sysctl.d/.

Below, vm.swappiness is set in both a 10- and a 99- file. Both are applied, and the value from 99- is the one that remains.

Example: which file wins
kazulog@sv1:~$ echo 'vm.swappiness = 30' | sudo tee /etc/sysctl.d/10-kazulog-test.conf
vm.swappiness = 30
kazulog@sv1:~$ grep -H . /etc/sysctl.d/10-kazulog-test.conf /etc/sysctl.d/99-kazulog.conf
/etc/sysctl.d/10-kazulog-test.conf:vm.swappiness = 30
/etc/sysctl.d/99-kazulog.conf:vm.swappiness = 10
/etc/sysctl.d/99-kazulog.conf:net.core.somaxconn = 1024
kazulog@sv1:~$ sudo sysctl --system 2>&1 | grep -E 'kazulog|swappiness'
* Applying /etc/sysctl.d/10-kazulog-test.conf ...
* Applying /etc/sysctl.d/99-kazulog.conf ...
vm.swappiness = 30
vm.swappiness = 10
kazulog@sv1:~$ sysctl vm.swappiness
vm.swappiness = 10
kazulog@sv1:~$

Confirming That a Setting Has an Effect

You can confirm more than the number: the behaviour changes too. The example uses fs.inotify.max_user_instances, which limits how many file watches one user may create at a time.

The script below starts three file watches and reports whether each one was created.

The script used for the check
kazulog@sv1:~$ cat ino_test.sh
#!/bin/bash
# 監視を3つ起動して、それぞれ作成できたかを表示する
for i in 1 2 3; do
  inotifywait -q -m /tmp > /dev/null 2>/tmp/ino$i.err &
  sleep 1
  if [ -s /tmp/ino$i.err ]; then echo "watcher $i: $(head -1 /tmp/ino$i.err)"; else echo "watcher $i: OK"; fi
done
sleep 1; pkill -f "inotifywait -q -m /tmp"; rm -f /tmp/ino*.err
kazulog@sv1:~$

Lowering the limit to 2 makes the watches impossible to create; restoring the default of 128 makes them work again.

Example: behaviour at different limits
kazulog@sv1:~$ sysctl fs.inotify.max_user_instances
fs.inotify.max_user_instances = 128
kazulog@sv1:~$ sudo sysctl -w fs.inotify.max_user_instances=2
fs.inotify.max_user_instances = 2
kazulog@sv1:~$ ./ino_test.sh
watcher 1: Couldn't initialize inotify: Too many open files
watcher 2: Couldn't initialize inotify: Too many open files
watcher 3: Couldn't initialize inotify: Too many open files
kazulog@sv1:~$ sudo sysctl -w fs.inotify.max_user_instances=128
fs.inotify.max_user_instances = 128
kazulog@sv1:~$ ./ino_test.sh
watcher 1: OK
watcher 2: OK
watcher 3: OK

Reaching the limit produces Too many open files. Servers running many programs that watch files (backup and sync tools, container platforms) often need this limit raised.

Undoing a Setting

Delete the configuration file you created.

Command to delete a configuration file
sudo rm /etc/sysctl.d/99-[NAME].conf
Example: deleting the configuration file
kazulog@sv1:~$ sudo rm /etc/sysctl.d/99-kazulog.conf
kazulog@sv1:~$ sudo sysctl --system > /dev/null 2>&1; sysctl vm.swappiness net.core.somaxconn
vm.swappiness = 10
net.core.somaxconn = 1024
kazulog@sv1:~$ ls /etc/sysctl.d/
99-cloudimg-ipv6.conf  README.sysctl
Deleting the file and running sysctl --system does not restore the old value. sysctl --system only applies what the configuration files contain; it does not reset parameters whose settings disappeared. In the example above vm.swappiness is still 10. Reboot, or set the default explicitly, to restore it.
Example: the defaults are back after a reboot
kazulog@sv1:~$ uptime -p
up 0 minutes
kazulog@sv1:~$ sysctl vm.swappiness net.core.somaxconn
vm.swappiness = 60
net.core.somaxconn = 4096

Parameters in Common Use

ParameterMeaning
net.ipv4.ip_forwardEnables packet forwarding. Set to 1 to use the server as a router
net.ipv4.conf.all.rp_filterChecks a packet’s source address against the routing table (reverse path filter)
net.core.somaxconnUpper bound of the connection backlog. Raised on servers with many connections
net.ipv4.tcp_max_syn_backlogUpper bound of the SYN queue
vm.swappinessHow readily swap is used (0-100). Lower values avoid swapping
vm.max_map_countMemory maps one process may hold. Raised for databases and search engines
fs.file-maxSystem-wide limit on open files
fs.inotify.max_user_instancesFile watches one user may create
fs.inotify.max_user_watchesFiles and directories one user may watch

Test Environment and Session Logs

The examples were captured on Ubuntu 26.04 LTS Server running on CML. The session log of each step can be downloaded below.

StepSession log
Initial state (defaults and configuration files)log
Temporary change and the order files are readlog
The value is lost after a rebootlog
Making a setting permanentlog
The setting survives a rebootlog
Which configuration file winslog
Behaviour at different inotify limitslog
Deleting the configuration filelog
The state after deleting and rebootinglog

Reference

sysctl.d(5) - systemd documentation

Related articles

Ubuntu official pages