Inspect sysctl config in /etc/sysctl.d
In the previous steps, we learned how to check and temporarily change kernel parameters using sysctl and how these parameters are reflected in the /proc/sys file system. However, changes made with sysctl -w are not permanent. To make kernel parameter changes persistent across reboots, we need to configure them in specific configuration files.
The primary location for persistent sysctl configurations is the /etc/sysctl.conf file. Additionally, Linux systems often use the /etc/sysctl.d/ directory to store configuration snippets in separate files. This modular approach makes it easier to manage configurations for different applications or system components.
Let's inspect the contents of the /etc/sysctl.d/ directory. We can use the ls command to list the files within this directory.
Open your terminal and type the following command:
ls /etc/sysctl.d/
Press Enter.
You will see a list of configuration files. These files typically have a .conf extension. The output might look something like this:
10-console-messages.conf 10-kernel-hardening.conf 10-tcp-congestion-control.conf 99-sysctl.conf
Each of these files can contain sysctl parameter settings in the format parameter = value. When the system boots, it reads /etc/sysctl.conf and then all files in /etc/sysctl.d/ in alphabetical order to apply the persistent kernel parameter settings.
Let's view the content of one of these configuration files, for example, 10-kernel-hardening.conf. We can use the cat command to display its content.
Type the following command:
cat /etc/sysctl.d/10-kernel-hardening.conf
Press Enter.
You will see the kernel parameters configured in this file. The content will vary, but it might include settings related to security or system behavior.
#
## sysctl settings for kernel hardening
#
## Disable unprivileged user namespaces
kernel.unprivileged_userns_clone=0
## Protect against symlink attacks
fs.protected_hardlinks=1
fs.protected_symlinks=1
## Disable kexec
kernel.kexec_load_disabled=1
## Disable bpf JIT
net.core.bpf_jit_enable=0
## Disable ptrace access to other processes
kernel.yama.ptrace_scope=1
You can see how kernel parameters like kernel.unprivileged_userns_clone and fs.protected_hardlinks are set here.
To make our vm.overcommit_memory=1 setting permanent, we would typically add the line vm.overcommit_memory = 1 to a new or existing file in /etc/sysctl.d/ (or in /etc/sysctl.conf). However, for the purpose of this introductory lab, we will not make this change permanent.
Understanding the /etc/sysctl.d/ directory is crucial for configuring persistent kernel parameter settings on your Linux system.
Click Continue to complete this lab.