The Linux kernel exposes hundreds of runtime knobs through /proc/sys/. Most defaults are fine; a handful are not, and a handful more are conservative defaults that you can tighten on a server that does not need them open. This article is the curated list of sysctl tunables worth applying as part of a hardening baseline, with the trade-offs each one carries — because every “secure by default” recommendation breaks somebody’s workload.
How to verify
Check the current effective values and where they came from:
sudo sysctl -a 2>/dev/null | grep -E 'rp_filter|tcp_syncookies|kptr_restrict|kernel.dmesg_restrict' | sort
sudo sysctl --system | tail # show which file last set each value
ls /etc/sysctl.d/
sudo cat /etc/sysctl.d/99-hardening.conf 2>/dev/null
sysctl --system reads every file under /etc/sysctl.d/, /usr/lib/sysctl.d/, and /etc/sysctl.conf in order; the last write wins. The order matters — distro defaults often live in /usr/lib/sysctl.d/ and your overrides should be in /etc/sysctl.d/99-*.conf to come last.
What’s happening
sysctl values live in the kernel’s procfs. Writing to /proc/sys/... takes effect immediately; writing to a file under /etc/sysctl.d/ makes the value persist across reboots when systemd applies the contents on next boot. The naming maps directly: net.ipv4.tcp_syncookies is the file /proc/sys/net/ipv4/tcp_syncookies.
Hardening tunables fall into three families. Network: protect against SYN floods, IP spoofing, source routing, ICMP redirects. Kernel: hide pointer addresses from non-root users, restrict dmesg, restrict ptrace. Filesystem: protect against hard-link and symlink races, restrict access to BPF and user namespaces.
The pitfall with every recommendation list is that some workloads need the “insecure” default. A container host that uses user namespaces relies on kernel.unprivileged_userns_clone=1; setting it to 0 breaks rootless Podman. The right approach is to read what each knob does and write a host-class baseline that turns off only what the class never needs.
The procedure
- Create one operator-owned sysctl file.
/etc/sysctl.d/99-stackharbor-hardening.conf. Keep distro files alone; your file ends in 99 so it loads last and wins. - Network hardening — apply on every internet-exposed host.
net.ipv4.tcp_syncookies = 1,net.ipv4.tcp_rfc1337 = 1,net.ipv4.conf.all.rp_filter = 1,net.ipv4.conf.default.rp_filter = 1,net.ipv4.conf.all.accept_source_route = 0,net.ipv4.conf.default.accept_source_route = 0,net.ipv4.conf.all.send_redirects = 0,net.ipv4.conf.all.accept_redirects = 0,net.ipv4.icmp_echo_ignore_broadcasts = 1,net.ipv4.icmp_ignore_bogus_error_responses = 1. Mirror eachipv4value with theipv6equivalent where it exists. - IP forwarding off by default.
net.ipv4.ip_forward = 0andnet.ipv6.conf.all.forwarding = 0. Container/router hosts override this with their own file (Docker writes/etc/sysctl.d/...). - Kernel info disclosure.
kernel.kptr_restrict = 2(hide kernel pointers from all users),kernel.dmesg_restrict = 1(restrict dmesg to CAP_SYSLOG),kernel.perf_event_paranoid = 3(disable perf events for non-root),kernel.yama.ptrace_scope = 1(ptrace only your descendants). - Filesystem races.
fs.protected_symlinks = 1,fs.protected_hardlinks = 1,fs.protected_fifos = 2,fs.protected_regular = 2. These prevent classic/tmpsymlink attacks on world-writable directories. - Core dumps.
fs.suid_dumpable = 0(no core dumps from setuid binaries) pluskernel.core_pattern = |/bin/falseif you want to disable core dumps entirely. A core dump from a vulnerable daemon may contain secrets in memory. - BPF and user namespaces — opt-in.
kernel.unprivileged_bpf_disabled = 1if no workload needs eBPF from non-root.kernel.unprivileged_userns_clone = 0if no rootless container runtime is in use. Both break common dev workflows — verify the host’s role first. - Apply and verify.
sudo sysctl --systemreads everything.sudo sysctl -a | grep tcp_syncookiesconfirms the value is 1. Reboot and re-check; a value that disappears at boot was set in/procdirectly, not in a config file.
Common pitfalls
- The
rp_filter = 1(strict reverse path filtering) drops packets that arrive on an interface that is not the route back to the source. On a host with asymmetric routing (multi-WAN, dual-NIC with BGP), this drops legitimate traffic. Userp_filter = 2(loose) or write per-interface overrides. net.ipv4.ip_forward = 0on a Docker host breaks container networking — Docker writes its own sysctl file to override. If you also writeip_forward = 0in your99-*.conffile, the order of the files determines who wins (Docker is typically100-docker.confso it wins anyway, but verify withsysctl --system | tail).kernel.ptrace_scope = 1breaksgdbfor non-root debugging across processes — annoying for developers, fine for servers. Setting it to3is one-way; you must reboot to change it back.- A
net.core.somaxconn = 1024(raising the listen backlog) is necessary for high-concurrency services but the application also needs to calllisten()with a matching backlog argument — without that, the sysctl change has no effect. - Some VMs and cloud providers re-write
/etc/sysctl.conffrom cloud-init on every boot, overwriting your changes. Put your overrides in/etc/sysctl.d/(which cloud-init typically leaves alone) and confirm by rebooting and re-checking.
In the engagements we run, sysctl baselines are part of the OS image and applied via configuration management — never hand-edited per host. The drift detection that catches “someone changed tcp_syncookies on the database server” is the kind of operating hygiene that lives in Managed Operations.