GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing wiki.archlinux.org — sysctl - ArchWiki
sysctl is a tool for examining and changing kernel parameters at runtime. sysctl is implemented in procfs, the virtual process file system at InstallationThe procps-ng package should already be installed, as it is a dependency of the base meta package. ConfigurationThe sysctl preload/configuration file can be created at To load all configuration files manually, execute: # sysctl --system which will also output the applied hierarchy. A single parameter file can also be loaded explicitly with: # sysctl --load=filename.conf See the new configuration files and more specifically sysctl.d(5) for more information. The parameters available are those listed under Note If you have the kernel documentation installed (linux-docs), you can find detailed information about sysctl settings in
/usr/lib/modules/$(uname -r)/build/Documentation/admin-guide/sysctl/. An online version is referred by the #See also section of this article. It is highly recommended reading these before changing sysctl settings.Settings can be changed through file manipulation or using the sysctl(8) utility. For example, to temporarily enable the magic SysRq key: # sysctl kernel.sysrq=1 or: # echo "1" > /proc/sys/kernel/sysrq See Linux kernel documentation for details about To preserve changes between reboots, add or modify the appropriate lines in Tip
SecuritySee also Security#Kernel hardening, as well as the rest of this article. Restrict capabilities for usermode helpersThe kernel uses usermode helper programs for loading modules (with modprobe(8)) and optionally for core dumping. The helpers do not need all capabilities, so their capability sets can be restricted. The capabilities needed are CAP_SYS_MODULE, CAP_DAC_READ_SEARCH, CAP_SETGID, CAP_SETUID, CAP_SETPCAP, CAP_SYS_PTRACE, added together yielding /etc/sysctl.d/51-usermodehelpers.conf kernel.usermodehelper.bset = 590276 0 kernel.usermodehelper.inheritable = 590276 0 If systemd-coredump is not used or core dumping is disabled entirely, replace NetworkingImproving performanceIncreasing the size of the receive queueThe received frames will be stored in this queue after taking them from the ring buffer on the network card. Increasing this value for high speed cards may help prevent losing packets: net.core.netdev_max_backlog = 16384 Note In real time application like SIP routers, this option requires a high speed CPU otherwise the data in the queue will be out of date.
Increase the maximum connectionsThe upper limit on how many connections the kernel will accept (default 4096): net.core.somaxconn = 8192 Warning Increasing this value may only increase performance on high-loaded servers and may cause a slow processing rate (e.g. a single threaded blocking server) or insufficient number of worker threads/processes [1].
Increase the memory dedicated to the network interfacesBy default the Linux network stack is not configured for high speed large file transfer across WAN links (i.e. handle more network packets) and setting the correct values may save memory resources: net.core.rmem_default = 1048576 net.core.rmem_max = 16777216 net.core.wmem_default = 1048576 net.core.wmem_max = 16777216 net.core.optmem_max = 65536 net.ipv4.tcp_rmem = 4096 1048576 2097152 net.ipv4.tcp_wmem = 4096 65536 16777216 It is also possible increase the default net.ipv4.udp_rmem_min = 8192 net.ipv4.udp_wmem_min = 8192 See the following sources for more information and recommend values:
Enable TCP Fast OpenTCP Fast Open is an extension to the transmission control protocol (TCP) that helps reduce network latency by enabling data to be exchanged during the sender’s initial TCP SYN [2]. Using the value net.ipv4.tcp_fastopen = 3 Tweak the pending connection handling
In the event of a synflood DOS attack, this queue can fill up pretty quickly, at which point TCP SYN cookies will kick in allowing your system to continue to respond to legitimate traffic, and allowing you to gain access to block malicious IPs. If the server suffers from overloads at peak times, you may want to increase this value a little bit: net.ipv4.tcp_max_syn_backlog = 8192
After reaching this number the system will start destroying the socket that are in this state. Increase this to prevent simple DOS attacks: net.ipv4.tcp_max_tw_buckets = 2000000
The default value is net.ipv4.tcp_tw_reuse = 1 Specify how many seconds to wait for a final FIN packet before the socket is forcibly closed. This is strictly a violation of the TCP specification, but required to prevent denial-of-service attacks: net.ipv4.tcp_fin_timeout = 10
This setting kills persistent single connection performance and could be turned off: net.ipv4.tcp_slow_start_after_idle = 0 Change TCP keepalive parametersTCP keepalive is a mechanism for TCP connections that help to determine whether the other end has stopped responding or not. TCP will send the keepalive probe that contains null data to the network peer several times after a period of idle time. If the peer does not respond, the socket will be closed automatically. By default, TCP keepalive process waits for two hours (7200 secs) for socket activity before sending the first keepalive probe, and then resend it every 75 seconds. As long as there is TCP/IP socket communications going on and active, no keepalive packets are needed. Note With the following settings, your application will detect dead TCP connections after 120 seconds (60s + 10s + 10s + 10s + 10s + 10s + 10s).
net.ipv4.tcp_keepalive_time = 60 net.ipv4.tcp_keepalive_intvl = 10 net.ipv4.tcp_keepalive_probes = 6 Enable MTU probingThe longer the maximum transmission unit (MTU) the better for performance, but the worse for reliability. This is because a lost packet means more data to be retransmitted and because many routers on the Internet cannot deliver very long packets: net.ipv4.tcp_mtu_probing = 1 See https://blog.cloudflare.com/path-mtu-discovery-in-practice/ for more information. On lossy connections, MTU probing can underestimate the actual MTU, and can sometimes lower the value to the MSS minimum (48 bytes in IPv4). To avoid excessive MSS decreases, it is recommended to increase the minimum MTU probing MSS. net.ipv4.tcp_mtu_probe_floor = 1024 See the commit introducing the tcp_mtu_probe_floor sysctl for more information. TCP timestampsWarning TCP timestamps protect against wrapping sequence numbers (at gigabit speeds) and round trip time calculation implemented in TCP. It is not recommended to turn off TCP timestamps as it may cause a security risk [4].
Disabling timestamp generation will reduce spikes and may give a performance boost on gigabit networks: net.ipv4.tcp_timestamps = 0 TCP Selective AcknowledgementTCP Selective Acknowledgement (TCP SACK), controlled by the boolean net.ipv4.tcp_sack = 1 Enable BBRThe BBR congestion control algorithm can help achieve higher bandwidths and lower latencies for internet traffic. First, load the Note BBR GitHub says, "This is not an official Google product."
net.core.default_qdisc = cake net.ipv4.tcp_congestion_control = bbr Increase the Ephemeral port rangeThe Wikipedia:Ephemeral port is typically used by the Transmission Control Protocol (TCP), User Datagram Protocol (UDP), or the Stream Control Transmission Protocol (SCTP) as the port assignment for the client end of a client–server communication. net.ipv4.ip_local_port_range = 30000 65535 TCP/IP stack hardeningThe following specifies a parameter set to tighten network security options of the kernel for the IPv4 protocol and related IPv6 parameters where an equivalent exists. For some use-cases, for example using the system as a router, other parameters may be useful or required as well. TCP SYN cookie protectionHelps protect against SYN flood attacks. Only kicks in when net.ipv4.tcp_syncookies = 1 TCP rfc1337Protect against tcp time-wait assassination hazards, drop RST packets for sockets in the time-wait state. Not widely supported outside of Linux, but conforms to RFC: net.ipv4.tcp_rfc1337 = 1 Reverse path filteringBy enabling reverse path filtering, the kernel will do source validation of the packets received from all the interfaces on the machine. This can protect from attackers that are using IP spoofing methods to do harm. The kernel's default value is The following will set the reverse path filtering mechanism to value net.ipv4.conf.*.rp_filter = 1 -net.ipv4.conf.all.rp_filter The relationship and behavior of Log martian packetsA martian packet is an IP packet which specifies a source or destination address that is reserved for special-use by Internet Assigned Numbers Authority (IANA). See Reserved IP addresses for more details. Often martian and unroutable packet may be used for a dangerous purpose. Logging these packets for further inspection may be useful [9]: net.ipv4.conf.*.log_martians = 1 -net.ipv4.conf.all.log_martians Note This can fill up your logs with a lot of information, it is advisable to only enable this for testing.
Disable ICMP redirectsBackground is at What are ICMP redirects? Should they be blocked? To disable ICMP redirect acceptance: net.ipv4.conf.*.accept_redirects = 0 -net.ipv4.conf.all.accept_redirects net.ipv6.conf.*.accept_redirects = 0 -net.ipv6.conf.all.accept_redirects To disable ICMP redirect sending when on a non router: net.ipv4.conf.*.send_redirects = 0 -net.ipv4.conf.all.send_redirects Ignore ICMP echo requestsTo disable ICMP echo (aka ping) requests: net.ipv4.icmp_echo_ignore_all = 1 net.ipv6.icmp.echo_ignore_all = 1 Note Beware this may cause issues with monitoring tools and/or applications relying on ICMP echo responses.
OtherAllow unprivileged users to create IPPROTO_ICMP socketsThe IPPROTO_ICMP (icmp(7)) socket type adds the possibility to send ICMP_ECHO messages and receive corresponding ICMP_ECHOREPLY messages without the need to open a raw(7) socket, an operation which requires the CAP_NET_RAW capability or the SUID bit with a proper privileged owner. These ICMP_ECHO messages are sent by the ping application thus making the IPPROTO_ICMP socket also known as ping socket in addition to ICMP Echo socket.
To allow only users which are members of the group with GID 100 to create IPPROTO_ICMP sockets: net.ipv4.ping_group_range = 100 100 To allow all the users in the system to create IPPROTO_ICMP sockets: net.ipv4.ping_group_range = 0 65535 Virtual memoryThere are several key parameters to tune the operation of the virtual memory subsystem of the Linux kernel and the write out of dirty data to disk. See the official Linux kernel documentation for more information. For example:
As noted in the comments for the parameters, one needs to consider the total amount of RAM when setting these values. For example, simplifying by taking the installed system RAM instead of available memory: Warning
See https://lonesysadmin.net/2013/12/22/better-linux-disk-caching-performance-vm-dirty_ratio/ for more information.
VFS cacheDecreasing the virtual file system (VFS) cache parameter value may improve system responsiveness:
MDADMSee RAID#Change sync speed limits. TroubleshootingSmall periodic system freezesSet dirty bytes to small enough value (for example 4 MiB): vm.dirty_background_bytes = 4194304 vm.dirty_bytes = 4194304 Note The
dirty_background_bytes and dirty_bytes parameters are counterparts of dirty_background_ratio and dirty_ratio (as seen in #Virtual memory). Only one of the parameters may be specified at a time.See also
Retrieved from "https://wiki.archlinux.org/index.php?title=Sysctl&oldid=888962" |
| You are visitor 01402775 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |