Article Title: how to modify Kernel Parameters during system running in Linux. Linux is a technology channel of the IT lab in China. Includes basic categories such as desktop applications, Linux system management, kernel research, embedded systems, and open source.
RedHat provides an excellent way for administrators to change kernel parameters while the system is running without the need to reboot the system. This is achieved through the/proc Virtual File System. The/proc/sys directory stores most Kernel Parameters and is designed to be changed while the system is running. The following describes how to modify Kernel Parameters during system running by taking the kernel ip forwarding function as an example. IP forwarding allows the system to block data packets from both the source and destination through the network. The RedHat function is disabled by default. This function must be enabled when the local machine is used as a router or NAT.
Method 1: Modify the Kernel Parameter file in/proc
Directly modify the file/proc/sys/net/ipv4/ip_forward corresponding to the Kernel Parameter ip_forward under/proc. Run the following command to view the ip_forward file:
# Cat/proc/sys/net/ipv4/ip_forward
The default value 0 of this file indicates that ip Forwarding is prohibited. If it is changed to 1, the ip forwarding function is enabled. The modification command is as follows:
# Echo 1>/proc/sys/net/ipv4/ip_forward
The modification takes effect immediately, that is, the kernel has enabled the ip forwarding function. However, if the default value is 0 after the system is restarted, you must modify the content of the/etc/sysctl. conf file to enable it permanently.
Method 2. Modify the/etc/sysctl. conf file
By default, one variable in the sysctl. conf file is
Net. ipv4.ip _ forward = 0
Change the nominal value to 1 and save the file. Because the initialization script/etc/rc every time the system starts. d/rc. sysinit reads/etc/sysctl. conf file, so the ip forwarding function is enabled every time the system starts. However, modifications to the sysctl file do not take effect immediately. If you want the modifications to take effect immediately, run the following command:
# Sysctl? P
You can modify other kernel parameters to/etc/sysctl. add the corresponding variables to the conf file. The Kernel File and configuration file sysctl in/proc/sys are described below. in conf, because all the kernel parameters that can be modified are in the/proc/sys directory, sysctl. the conf variable name omits the prefix facial score (/proc/sys) of the directory ).
To convert a file in/proc/sys to a variable in sysctl, follow these two simple rules:
1. Remove the previous section/proc/sys
2. Change the slash in the file name to a vertex.
These two rules can convert any file name in/proc/sys to the variable name in sysctl.
For example:
/Proc/sys/net/ipv4/ip_forward = "net. ipv4.ip _ forward
/Proc/sys/kernel/hostname = "kernel. hostname
You can use the following command to query all variable names that can be modified:
# Sysctl? A
The following describes some simple kernel parameters:
1./proc/sys/kernel/shmmax
This file specifies the maximum size of shared memory segments allowed by the kernel.
2./proc/sys/kernel/threads-max
This file specifies the maximum number of threads that the kernel can use.
3./proc/sys/kernel/hostname
This file allows you to configure the network host name.
4./proc/sys/kernel/domainname
This file allows you to configure the network domain name.