How to Harden Kernel Parameters for Security

Beyond application and network-layer hardening, several kernel-level parameters directly affect your server's security posture. This guide covers the security-relevant sysctl settings worth reviewing.

Why Kernel-Level Hardening Matters

The kernel enforces fundamental system behavior — certain default settings prioritize compatibility over security; adjusting them closes specific classes of attacks at the lowest system level.

Disabling IP Forwarding (Unless Genuinely Needed)

net.ipv4.ip_forward = 0

Prevents your server from acting as an unintended router — only enable this if you specifically need routing functionality (e.g. a VPN gateway).

Protecting Against SYN Flood Attacks

net.ipv4.tcp_syncookies = 1

Ignoring ICMP Redirects

net.ipv4.conf.all.accept_redirects = 0
net.ipv6.conf.all.accept_redirects = 0

Prevents potential man-in-the-middle attacks via malicious ICMP redirect messages attempting to alter your routing table.

Disabling Source Routing

net.ipv4.conf.all.accept_source_route = 0
net.ipv6.conf.all.accept_source_route = 0

Source routing lets a packet specify its own path, a technique sometimes used to bypass network security controls — disabling it closes this avenue.

Enabling Reverse Path Filtering

net.ipv4.conf.all.rp_filter = 1

Helps prevent IP spoofing by verifying incoming packets have a legitimate return path via the interface they arrived on.

Logging Martian Packets

net.ipv4.conf.all.log_martians = 1

Logs packets with impossible/spoofed source addresses, useful for detecting certain attack patterns.

Restricting Core Dumps for setuid Programs

fs.suid_dumpable = 0

Prevents privileged programs from generating core dumps that could potentially expose sensitive memory content.

Restricting Access to Kernel Pointers

kernel.kptr_restrict = 2

Hides kernel memory addresses from unprivileged users, making certain kernel exploitation techniques more difficult.

Restricting dmesg Access

kernel.dmesg_restrict = 1

Prevents unprivileged users from reading kernel log messages, which can sometimes reveal information useful to an attacker.

Applying These Settings

sudo nano /etc/sysctl.d/99-security-hardening.conf

Add your chosen settings, then apply:

sudo sysctl -p /etc/sysctl.d/99-security-hardening.conf

Testing Before Applying to Production

Some of these settings can affect legitimate functionality in specific network configurations (e.g. IP forwarding if you actually need routing) — understand what each setting does and verify it's appropriate for your specific server's role before applying broadly.

Common Errors

Legitimate routing/VPN functionality breaks after hardening — review whether ip_forward or other network-behavior settings were inappropriately disabled for a server that specifically needs that functionality (like a VPN gateway).

Continue Reading

Browse more articles in Server Security & Hardening.

  • kernel security hardening, sysctl security settings, linux kernel hardening, security sysctl parameters
  • 0 Users Found This Useful
Was this answer helpful?

Related Articles

SSH Hardening: Change the Port, Disable Root Login & Use SSH Keys (Ubuntu & Debian)

SSH is the front door to your VPS — and by default it listens on a well-known port, often...

How to Install and Configure Fail2Ban on Ubuntu & Debian (Complete Guide)

Fail2Ban monitors your server's log files and automatically blocks (bans) IP addresses that show...

How to Configure UFW Firewall on a Linux VPS (Ubuntu & Debian)

UFW (Uncomplicated Firewall) is the standard firewall front-end on Ubuntu and Debian. A correctly...

How to Enable Two-Factor Authentication (2FA) for SSH on a Linux VPS

Two-Factor Authentication (2FA) adds a second layer of protection to SSH: even if your password...

VPS Security Checklist for Beginners: 12 Essential Steps

Every new VPS is deployed with default settings that are convenient but not secure. This...