Skip to main content
Proceed at Your Own Risk: Changing kernel settings with sysctl is risky and could break your server. If you don’t know what you are doing, don’t have the time to debug issues, or just don’t want to take the risks, do not follow these steps.

Overview

The kernel is the brains of a Linux system. Securing it through sysctl parameters can provide additional hardening against various attacks and improve overall system security.

Why Sysctl Hardening?

Kernel hardening helps protect against:
  • Spoofing attacks
  • Denial of Service (DOS) attacks
  • Network-based exploits
  • Local privilege escalation
  • Information disclosure

Important Disclaimer

These settings are compiled from multiple reputable sources. Most of them are for general kernel hardening and performance, while others protect against spoofing and DOS attacks. Test each setting thoroughly before deploying to production.
Documentation for these settings references the Linux 2.2 kernel. Settings may have changed in newer kernels. Always test in a non-production environment first.

Testing Sysctl Changes

Before making any kernel sysctl change permanent, test it with the sysctl command:
sudo sysctl -w [key=value]
Example:
sudo sysctl -w kernel.ctrl-alt-del=0
There are no spaces in key=value, including before and after the equals sign.

Making Changes Permanent

Once you have tested a setting and verified it works without breaking your server, make it permanent by adding the values to /etc/sysctl.conf:
# Example /etc/sysctl.conf
kernel.ctrl-alt-del = 0
fs.file-max = 65535
kernel.sysrq = 0
After updating the file, reload the settings:
sudo sysctl -p
If sysctl has trouble writing any settings, sysctl -w or sysctl -p will write an error to stderr. You can use this to quickly find invalid settings:
sudo sysctl -p >/dev/null

Sysctl Parameters Reference

Below is a comprehensive table of recommended sysctl hardening parameters:

File System Parameters

ParameterValueDocumentation
fs.file-max65535fs.txt
fs.protected_hardlinks1fs.txt
fs.protected_symlinks1fs.txt
fs.suid_dumpable0fs.txt

Kernel Parameters

ParameterValueDocumentation
kernel.core_uses_pid1kernel.txt
kernel.ctrl-alt-del0kernel.txt
kernel.kptr_restrict2kernel.txt
kernel.maps_protect1-
kernel.msgmax65535kernel.txt
kernel.msgmnb65535kernel.txt
kernel.pid_max65535kernel.txt
kernel.randomize_va_space2kernel.txt
kernel.shmall268435456kernel.txt
kernel.shmmax268435456kernel.txt
kernel.sysrq0kernel.txt

Network Core Parameters

ParameterValueDocumentation
net.core.default_qdiscfqnet.txt
net.core.dev_weight64net.txt
net.core.netdev_max_backlog16384net.txt
net.core.optmem_max65535net.txt
net.core.rmem_default262144net.txt
net.core.rmem_max16777216net.txt
net.core.somaxconn32768ip-sysctl.txt
net.core.wmem_default262144ip-sysctl.txt
net.core.wmem_max16777216ip-sysctl.txt

IPv4 Configuration Parameters

ParameterValueNotesDocumentation
net.ipv4.conf.all.accept_redirects0-ip-sysctl.txt
net.ipv4.conf.all.accept_source_route0-ip-sysctl.txt
net.ipv4.conf.all.bootp_relay0-ip-sysctl.txt
net.ipv4.conf.all.forwarding0-ip-sysctl.txt
net.ipv4.conf.all.log_martians1-ip-sysctl.txt
net.ipv4.conf.all.proxy_arp0-ip-sysctl.txt
net.ipv4.conf.all.rp_filter1-ip-sysctl.txt
net.ipv4.conf.all.secure_redirects0-ip-sysctl.txt
net.ipv4.conf.all.send_redirects0-ip-sysctl.txt
net.ipv4.conf.default.accept_redirects0-ip-sysctl.txt
net.ipv4.conf.default.accept_source_route0-ip-sysctl.txt
net.ipv4.conf.default.forwarding0-ip-sysctl.txt
net.ipv4.conf.default.log_martians1-ip-sysctl.txt
net.ipv4.conf.default.rp_filter1-ip-sysctl.txt
net.ipv4.conf.default.secure_redirects0-ip-sysctl.txt
net.ipv4.conf.default.send_redirects0-ip-sysctl.txt
net.ipv4.conf.eth0.accept_redirects0Change eth0 to your network interfaceip-sysctl.txt
net.ipv4.conf.eth0.accept_source_route0Change eth0 to your network interfaceip-sysctl.txt
net.ipv4.conf.eth0.log_martians0Change eth0 to your network interfaceip-sysctl.txt
net.ipv4.conf.eth0.rp_filter1Change eth0 to your network interfaceip-sysctl.txt
net.ipv4.conf.lo.accept_redirects0-ip-sysctl.txt
net.ipv4.conf.lo.accept_source_route0-ip-sysctl.txt
net.ipv4.conf.lo.log_martians0-ip-sysctl.txt
net.ipv4.conf.lo.rp_filter1-ip-sysctl.txt

IPv4 ICMP Parameters

ParameterValueDocumentation
net.ipv4.icmp_echo_ignore_all1ip-sysctl.txt
net.ipv4.icmp_echo_ignore_broadcasts1ip-sysctl.txt
net.ipv4.icmp_ignore_bogus_error_responses1ip-sysctl.txt

IPv4 General Parameters

ParameterValueDocumentation
net.ipv4.ip_forward0ip-sysctl.txt
net.ipv4.ip_local_port_range2000 65000ip-sysctl.txt
net.ipv4.ipfrag_high_thresh262144ip-sysctl.txt
net.ipv4.ipfrag_low_thresh196608ip-sysctl.txt

IPv4 Neighbor Parameters

ParameterValueDocumentation
net.ipv4.neigh.default.gc_interval30-
net.ipv4.neigh.default.gc_thresh132ip-sysctl.txt
net.ipv4.neigh.default.gc_thresh21024ip-sysctl.txt
net.ipv4.neigh.default.gc_thresh32048ip-sysctl.txt
net.ipv4.neigh.default.proxy_qlen96-
net.ipv4.neigh.default.unres_qlen6ip-sysctl.txt

IPv4 TCP Parameters

ParameterValueDocumentation
net.ipv4.route.flush1-
net.ipv4.tcp_congestion_controlhtcpip-sysctl.txt
net.ipv4.tcp_ecn1ip-sysctl.txt
net.ipv4.tcp_fastopen3ip-sysctl.txt
net.ipv4.tcp_fin_timeout15ip-sysctl.txt
net.ipv4.tcp_keepalive_intvl15ip-sysctl.txt
net.ipv4.tcp_keepalive_probes5ip-sysctl.txt
net.ipv4.tcp_keepalive_time1800ip-sysctl.txt
net.ipv4.tcp_max_orphans16384ip-sysctl.txt
net.ipv4.tcp_max_syn_backlog2048ip-sysctl.txt
net.ipv4.tcp_max_tw_buckets1440000ip-sysctl.txt
net.ipv4.tcp_moderate_rcvbuf1ip-sysctl.txt
net.ipv4.tcp_no_metrics_save1ip-sysctl.txt
net.ipv4.tcp_orphan_retries0ip-sysctl.txt
net.ipv4.tcp_reordering3ip-sysctl.txt
net.ipv4.tcp_retries13ip-sysctl.txt
net.ipv4.tcp_retries215ip-sysctl.txt
net.ipv4.tcp_rfc13371ip-sysctl.txt
net.ipv4.tcp_rmem8192 87380 16777216ip-sysctl.txt
net.ipv4.tcp_sack0ip-sysctl.txt
net.ipv4.tcp_slow_start_after_idle0ip-sysctl.txt
net.ipv4.tcp_syn_retries5ip-sysctl.txt
net.ipv4.tcp_synack_retries2ip-sysctl.txt
net.ipv4.tcp_syncookies1ip-sysctl.txt
net.ipv4.tcp_timestamps1ip-sysctl.txt
net.ipv4.tcp_tw_recycle0-
net.ipv4.tcp_tw_reuse1ip-sysctl.txt
net.ipv4.tcp_window_scaling0ip-sysctl.txt
net.ipv4.tcp_wmem8192 65536 16777216ip-sysctl.txt

IPv4 UDP Parameters

ParameterValueDocumentation
net.ipv4.udp_rmem_min16384ip-sysctl.txt
net.ipv4.udp_wmem_min16384ip-sysctl.txt

IPv6 Configuration Parameters

ParameterValueNotesDocumentation
net.ipv6.conf.all.accept_ra0-ip-sysctl.txt
net.ipv6.conf.all.accept_redirects0-ip-sysctl.txt
net.ipv6.conf.all.accept_source_route0-ip-sysctl.txt
net.ipv6.conf.all.autoconf0-ip-sysctl.txt
net.ipv6.conf.all.forwarding0-ip-sysctl.txt
net.ipv6.conf.default.accept_ra_defrtr0-ip-sysctl.txt
net.ipv6.conf.default.accept_ra_pinfo0-ip-sysctl.txt
net.ipv6.conf.default.accept_ra_rtr_pref0-ip-sysctl.txt
net.ipv6.conf.default.accept_ra0-ip-sysctl.txt
net.ipv6.conf.default.accept_redirects0-ip-sysctl.txt
net.ipv6.conf.default.accept_source_route0-ip-sysctl.txt
net.ipv6.conf.default.autoconf0-ip-sysctl.txt
net.ipv6.conf.default.dad_transmits0-ip-sysctl.txt
net.ipv6.conf.default.forwarding0-ip-sysctl.txt
net.ipv6.conf.default.max_addresses1-ip-sysctl.txt
net.ipv6.conf.default.router_solicitations0-ip-sysctl.txt
net.ipv6.conf.eth0.accept_ra0Change eth0 to your network interfaceip-sysctl.txt
net.ipv6.conf.eth0.autoconf0Change eth0 to your network interfaceip-sysctl.txt
net.ipv6.ip6frag_high_thresh262144-ip-sysctl.txt
net.ipv6.ip6frag_low_thresh196608-ip-sysctl.txt
net.ipv6.route.flush1--

Unix Domain Socket Parameters

ParameterValueDocumentation
net.unix.max_dgram_qlen50ip-sysctl.txt

Virtual Memory Parameters

ParameterValueDocumentation
vm.dirty_background_ratio5vm.txt
vm.dirty_ratio30vm.txt
vm.min_free_kbytes65535vm.txt
vm.mmap_min_addr4096vm.txt
vm.overcommit_memory0vm.txt
vm.overcommit_ratio50vm.txt
vm.swappiness30vm.txt

Additional Resources

This comprehensive list is compiled from multiple trusted sources:
Always test sysctl changes in a non-production environment before deploying to production systems. Keep backups and have a recovery plan ready.

Build docs developers (and LLMs) love