Inspect and Safely Tune Linux's /proc/sys/net Settings
You will finish with a repeatable way to inspect the networking controls exposed under /proc/sys/net/, check two documented settings, and test a temporary change without confusing a kernel limit with an application setting. The installed proc_sys_net(5) page is short: it describes the directory, net.core.bpf_jit_enable, and net.core.somaxconn. It is not a complete catalogue of every networking knob on a modern kernel.
The route
Jump straight to the step you need, or tick off Done means at the end.
Allow about fifteen minutes. You need a shell, the procps-ng sysctl command, and a Linux host where you can read the relevant pseudo-files. Reading is normally unprivileged. Writing a kernel setting requires root or the capability and policy your host grants for that operation. The examples below are tested against Linux 6.8.0-139-generic, man-pages 6.7, and procps-ng 4.0.4; values and available files are host-specific.
1. Confirm the local tools and kernel
Start with read-only version checks. This prevents a copied example from silently describing a different host:
$ uname -sr
Linux 6.8.0-139-generic
$ sysctl --version
sysctl from procps-ng 4.0.4
$ man -P cat 5 proc_sys_net | sed -n '1,90p'
Checkpoint: the local manpage should identify itself as Linux man-pages 6.7 and describe /proc/sys/net/ as the networking area. If the page or command is missing, stop and install the normal documentation or procps package through your distribution's approved process. Do not infer a setting from an online snippet.
2. List the networking namespace without changing it
The manpage says that /proc/sys/net/ contains networking material, while the kernel and loaded modules decide which descendants exist. Ask sysctl to list readable variables:
$ sysctl --all --pattern '^net\.' | sed -n '1,40p'
net.core.bpf_jit_enable = 1
net.core.somaxconn = 4096
# more net.* variables may appear here
Your output will be longer and can differ between kernels, network namespaces and loaded features. The command reads values only. The pattern is anchored at net., so it avoids mixing unrelated kernel., fs. or vm. settings into the review.
For an exact path check, use the pseudo-files directly:
$ ls -l /proc/sys/net/core/somaxconn /proc/sys/net/core/bpf_jit_enable
-rw-r--r-- 1 root root 0 ... /proc/sys/net/core/bpf_jit_enable
-rw-r--r-- 1 root root 0 ... /proc/sys/net/core/somaxconn
The size of these files is reported as zero because they are procfs interfaces, not ordinary files. Do not edit them with a text editor. Use sysctl or a deliberate write to the pseudo-file when you have established the setting's meaning and rollback value.
3. Understand the two settings documented locally
net.core.somaxconn is a ceiling for the backlog argument passed to listen(2). It is not the application's requested backlog, a count of current connections, or a guarantee that a service can accept that many clients. The application, protocol, available memory and other queue limits still matter.
$ sysctl net.core.somaxconn
net.core.somaxconn = 4096
$ sysctl -n net.core.somaxconn
4096
Use the value without the name when a script needs a number. Keep the setting's purpose in the script comment; otherwise a future reader may mistake it for a live queue depth.
net.core.bpf_jit_enable is documented by reference to bpf(2). It controls the kernel's BPF just-in-time compiler setting, not whether every BPF program is permitted and not whether a particular tracing or networking tool will work. Treat changes to it as security-sensitive kernel policy. First record the current value:
$ sysctl net.core.bpf_jit_enable
net.core.bpf_jit_enable = 1
Checkpoint: write down the exact values you found, plus the workload and network namespace where you found them. A value from the host namespace may not describe a container or another namespace.
4. Test a reversible somaxconn change
Changing a sysctl affects kernel behaviour immediately and can affect a running service. Take a maintenance window for a production test, capture the old value, and make sure you have a root shell or an approved sudo rule. The following example changes only the current runtime value:
$ old_somaxconn=$(sysctl -n net.core.somaxconn)
$ printf 'old somaxconn: %s\n' "$old_somaxconn"
old somaxconn: 4096
$ sudo sysctl -w net.core.somaxconn=512
net.core.somaxconn = 512
$ sysctl -n net.core.somaxconn
512
Use a value suited to your actual service, not 512 by habit. This is a test of the ceiling, not a recommendation. An application that asks listen(2) for a backlog above 512 will now be capped at 512; existing connections are not rewritten.
Undo the runtime change as soon as the test is complete. The shell variable is available only in the shell where you captured it:
$ sudo sysctl -w "net.core.somaxconn=$old_somaxconn"
net.core.somaxconn = 4096
$ sysctl -n net.core.somaxconn
4096
If the variable was lost, use the value recorded before the change. If the write failed, do not keep retrying with broader privileges: inspect the error, the active namespace and your host policy first.
5. Keep persistence separate from a runtime test
sysctl -w changes the current kernel state; it does not by itself create a persistent configuration file. Persistence is distribution-specific and is commonly applied during boot or service startup. Before adding a file under /etc/sysctl.d/, confirm which configuration manager owns it and whether another file sets the same key.
$ rg -n '^(net\.core\.(somaxconn|bpf_jit_enable))\s*=' /etc/sysctl.conf /etc/sysctl.d 2>/dev/null
$ sysctl --system --dry-run 2>/dev/null | rg 'net\.core\.(somaxconn|bpf_jit_enable)'
The second command is a preview where supported by the installed sysctl. It does not write a value. If your version does not support the option, read its --help output and use the distribution's documented dry-run or configuration inspection method.
Do not persist the temporary value simply because the command worked. A persistent change needs an owner, a reason, a rollback patch and a reboot or startup verification plan. If you do add a managed drop-in, remove that exact drop-in to undo it, then reload through the same mechanism and verify the resulting value. Do not delete an entire sysctl directory.
6. Avoid the common failure modes
- An unknown key can mean the kernel does not expose that feature, the command is in a different network namespace, or the spelling is wrong. It does not prove that a reboot will create the key.
- A successful
somaxconnwrite does not prove that a service is healthy. Check the service's own configuration, socket state and application metrics separately. - A successful BPF JIT read does not grant BPF privileges or validate a program. Review the relevant kernel security policy and the tool's own diagnostics.
- Do not use
sysctl --alloutput as a stable API. It includes settings outside this manpage and can change with the kernel. - Do not paste untrusted values into a privileged shell command. Validate numeric input and quote shell variables when a value is supplied by automation.
Done means
- You confirmed the installed kernel, man-pages and
sysctlversions. - You listed the available
net.*settings and checked the two paths documented byproc_sys_net(5). - You understand
somaxconnas alisten(2)backlog ceiling, not a connection count. - You treated
bpf_jit_enableas kernel security policy rather than a general BPF permission switch. - Any runtime test has a recorded old value and a tested undo command.
- No persistent file or service configuration was changed without an explicit owner and rollback plan.