The /proc/sys/ contains the kernel parameters. We will see how to use the sysctl command to modify the Linux kernel parameters
Using the sysctl Linux Command
The sysctl uses the files in the /proc/sys directory to modify kernel parameters. You can list the contents of the directory to see the different folders.
sysctl: Display Kernel Parameters
Use the “-a” or “-all” flag to view all the configured kernel parameters.
All the configurations will display in a long list showing the parameters and their values in each line.
The previous list can be challenging to understand, but there is a way to narrow it down by checking the values of single parameters. You can pass the parameter’s name to the command and get its specific value. For instance, you can use the following commands to get the kernel hostname and swappiness, which defines how often the system uses the swap space.
$ sysctl vm.swappiness
The same output can be obtained by retrieving the contents of the file containing it. You only need to replace the “slash” with a “dot”.
For instance, use the following commands to get the same values previously shown:
Alternately, you can filter the output by grep-specific kernel parameters by providing matching words. For example, to filter all ipv4 output, you can use the following command:
sysctl: Modify Kernel Parameters
As an administrator, the sysctl allows you to permanently or temporarily modify the kernel parameters.
The syntax for temporarily modifying kernel parameters is:
Note that if the value contains special characters or spaces, you should enclose it in double quotes. Furthermore, the set parameters reset to the initial values after the next reboot.
Let’s take an example of the TCP Fast Open, which speeds up the loading of TCP connections between two devices. By default, it is enabled. To disable it, use the following command. You should have administrator privileges for it to work. Also, ensure no spaces are between the parameter and the value.
We see that the values modify from “1” for enabled to “0” for disabled.
If you were to set the same parameters permanently, you need to modify the parameters either in the /etc/sysctl.conf or in the /etc/sysctl.d/99-custom.conf directory. You can open the files using an editor or directly add the configuration using echo.
Executing the previous command will modify the parameters permanently.
You can also add the net.ipv4.tcp_fastopen in the configuration file.
Adding the parameter and its value will get loaded every time the system boots.
The system default loads the configurations in the /etc/sysctl.conf file. However, you can use the “-p” option to load another configuration file like the one we previously modified.
Proceed with caution when making the permanent kernel changes to avoid rendering your kernel unstable. That said, any time you need to modify a parameter, use the syntax highlighted in the article or directly modify it from the configuration file.
The Linux kernel powers the Linux operating system. If you are a Linux system administrator, modifying the kernel parameters to suit various tasks is part of your job. Luckily, this post covers how you can achieve that using the sysctl Linux command.