How to reload sysctl.conf variables on Linux

The sysctl command is used to modify Linux kernel variables at runtime. The variables are read and write from /proc/sys/ location using procfs. The syntax is as follows for to define variable:


Read variable from command line

Type the following command
$ sysctl kernel.ostype
Sample outputs:

kernel.ostype = Linux
To see all variables pass the -a option:
 $ sysctl -a
 $ sysctl -a | grep kernel
 $ sysctl -a | more

Write variable from command line

The syntax is:
# sysctl -w variable=value
To enable packet forwarding for IPv4, enter:
# sysctl -w net.ipv4.ip_forward=1

Reload settings from all system configuration files

Type the following command to reload settings from config files without rebooting the box:
# sysctl --system
The settings are read from all of the following system configuration files:

  1. /run/sysctl.d/*.conf
  2. /etc/sysctl.d/*.conf
  3. /usr/local/lib/sysctl.d/*.conf
  4. /usr/lib/sysctl.d/*.conf
  5. /lib/sysctl.d/*.conf
  6. /etc/sysctl.conf

Persistent configuration

You need to edit the /etc/sysctl.conf file for setting system variables:
# vi /etc/sysctl.conf
Modify or add in the file. Close and save the file. To Load in sysctl settings from the file specified or /etc/sysctl.conf if none given, enter:
# sysctl -p



Leave a Reply

Your email address will not be published. Required fields are marked *