≡ Menu

Linux set sysctl variables

How do I set sysctl variables (kernel parameters) under a Debian/Ubuntu or any Linux distributions using command line options?

You need to use the sysctl command which is used to modify kernel parameters at runtime. The parameters available are those listed under /proc/sys/. Procfs is required for sysctl support in Linux.
Tutorial details
DifficultyEasy (rss)
Root privilegesYes
RequirementsNone
Estimated completion time5m
You can use sysctl command to both read and write sysctl variables.

You must login as the root user to use any one of the following command on a Linux operating systems.

Display Linux kernel parameters

The syntax is:
# sysctl variable
####################################
### Display all sysctl variables ###
####################################
# sysctl -a
# sysctl -a | more
# sysctl -a | grep 'something'
# sysctl -a | grep memory

Sample outputs:

vm.memory_failure_early_kill = 0
vm.memory_failure_recovery = 1
vm.overcommit_memory = 0

To see value for kernel variable called kernel.hostname, enter:
# sysctl -n kernel.hostname

How do I set new values?

There are three methods to set new values for given kernel parameters as follows:

Method # 1: Setting value via procfs

You can use standard echo command to write data to variables (this temporary change):
# echo "value" > /proc/sys/location/variable

Method # 2: Temporary on the command line

Use sysctl command with -w option when you want to change a sysctl setting:
sysctl -w variable=value

Method # 3: Configuration file /etc/sysctl.conf

This is recommended way. First open /etc/sysctl.conf file, enter:
# vi /etc/sysctl.conf
Now add value:
variable = value
Close and save the changes. Type the following command to load sysctl settings from the file /etc/sysctl.conf file:
# sysctl -p
OR
# sysctl -p /etc/sysctl.conf
The last method will load settings permanently at boot time from /etc/sysctl.conf file. Read man page of sysctl for information:
$ man sysctl

Tweet itFacebook itGoogle+ itPDF itFound an error/typo on this page?

{ 2 comments… add one }

  • Dimitrios June 14, 2014, 6:40 am

    Can you make an example for “variable” and “value” ?

    • Ninja Dragon June 22, 2015, 7:18 pm

      EXAMPLE….
      [root@hostname1 /]# sysctl -a
      kernel.sched_child_runs_first = 0
      kernel.sched_min_granularity_ns = 4000000
      kernel.sched_latency_ns = 20000000
      kernel.sched_wakeup_granularity_ns = 4000000
      kernel.sched_tunable_scaling = 1
      kernel.sched_features = 3183
      kernel.sched_migration_cost = 500000
      kernel.sched_nr_migrate = 32
      kernel.sched_time_avg = 1000
      kernel.sched_shares_window = 10000000
      kernel.timer_migration = 1
      kernel.sched_rt_period_us = 1000000
      kernel.sched_rt_runtime_us = 950000
      kernel.sched_compat_yield = 0
      kernel.sched_rr_timeslice_ms = 100
      kernel.sched_autogroup_enabled = 0
      kernel.sched_cfs_bandwidth_slice_us = 5000
      kernel.panic = 0
      kernel.exec-shield = 1
      kernel.core_uses_pid = 1
      kernel.core_pattern = |/usr/libexec/abrt-hook-ccpp %s %c %p %u %g %t e
      kernel.core_pipe_limit = 4
      kernel.tainted = 0
      kernel.real-root-dev = 0
      kernel.print-fatal-signals = 0
      kernel.ctrl-alt-del = 0
      kernel.ftrace_enabled = 1
      kernel.stack_tracer_enabled = 0
      kernel.ftrace_dump_on_oops = 0
      kernel.modprobe = /sbin/modprobe
      kernel.modules_disabled = 0
      kernel.kexec_load_disabled = 0
      kernel.hotplug =
      kernel.acct = 4 2 30
      kernel.sysrq = 0
      kernel.cad_pid = 1
      kernel.threads-max = 513406
      kernel.random.poolsize = 4096
      kernel.random.entropy_avail = 135
      kernel.random.read_wakeup_threshold = 64
      kernel.random.write_wakeup_threshold = 128
      kernel.random.boot_id = 95a40261-6816-445f-b5ae-38660f15d7e3
      kernel.random.uuid = 7a1d1848-0868-42f5-bb3b-21172b60996b
      kernel.usermodehelper.bset = 4294967295 4294967295
      kernel.usermodehelper.inheritable = 4294967295 4294967295
      kernel.overflowuid = 65534
      kernel.overflowgid = 65534
      kernel.pid_max = 32768
      kernel.panic_on_oops = 1
      kernel.printk = 4 4 1 7
      kernel.printk_ratelimit = 5
      kernel.printk_ratelimit_burst = 10
      kernel.printk_delay = 0
      kernel.dmesg_restrict = 0
      kernel.kptr_restrict = 1
      kernel.ngroups_max = 65536
      kernel.watchdog = 1
      kernel.watchdog_thresh = 60
      kernel.softlockup_panic = 0
      kernel.nmi_watchdog = 1
      kernel.unknown_nmi_panic = 0
      kernel.panic_on_unrecovered_nmi = 0
      kernel.panic_on_io_nmi = 0
      kernel.bootloader_type = 113
      kernel.bootloader_version = 1
      kernel.kstack_depth_to_print = 12
      kernel.io_delay_type = 0
      kernel.randomize_va_space = 2
      kernel.acpi_video_flags = 0
      kernel.hung_task_panic = 0
      kernel.hung_task_check_count = 4194304
      kernel.hung_task_timeout_secs = 120
      kernel.hung_task_warnings = 10
      kernel.compat-log = 1
      kernel.max_lock_depth = 1024
      kernel.poweroff_cmd = /sbin/poweroff
      kernel.keys.maxkeys = 200
      kernel.keys.maxbytes = 20000
      kernel.keys.root_maxkeys = 1000000
      kernel.keys.root_maxbytes = 25000000
      kernel.keys.gc_delay = 300
      kernel.slow-work.min-threads = 2
      kernel.slow-work.max-threads = 8
      kernel.slow-work.vslow-percentage = 50
      kernel.perf_event_paranoid = 1
      kernel.perf_event_mlock_kb = 516
      kernel.perf_event_max_sample_rate = 100000

      (VARIABLE = VALUE)

      sysctl -w variable=value
      sysctl -w kernel.keys.maxkeys=400

Leave a Comment