Monday, March 18, 2019

how to reload all kernel parameters in linux ?

You need to use the sysctl command which is used to modify kernel parameters at run time.
The parameters available are those listed under /proc/sys/.
Procfs is required for sysctl support in Linux. You can use sysctl command to both read and write sysctl variables.

Display Linux kernel parameters

Display all sysctl variables

The syntax is:
# sysctl variable
# sysctl -a
# sysctl -a | more

Sample output

vm.swappiness = 60
vm.user_reserve_kbytes = 131072
vm.vfs_cache_pressure = 100

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
Echo “1” > /proc/sys/net/ipv4/conf/all/rp_filter

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

To enable packet forwarding for IPv4, enter:
# sysctl -w net.ipv4.ip_forward=1


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

example :

net.ipv4.ip_forward=1


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


Reload settings from all system configuration files

Type the following command to reload settings from config files without rebooting the box:
# sysctl --system

For older versions (that is, if --system does not work):

# Load settings from /etc/sysctl.conf
sysctl -p

The settings are read from all of the following system configuration files:

/run/sysctl.d/*.conf
/etc/sysctl.d/*.conf
/usr/local/lib/sysctl.d/*.conf
/usr/lib/sysctl.d/*.conf
/lib/sysctl.d/*.conf
/etc/sysctl.conf


# Load settings from the specified file
sysctl -p /etc/sysctl.d/<whatever>.conf

example:

sysctl -p /etc/sysct.d/10-magic-sysrq.conf


No comments:

Post a Comment