LFCS Kernel Parameter Modification Questions and Answers — Questions and Answers
Question 1: A system administrator has just created a new configuration file at `/etc/sysctl.d/99-custom.conf` to tune network parameters. Which command should be used to apply these new settings immediately without rebooting the system?
- `sysctl -a`
- `systemctl restart sysctl.service`
- `sysctl -p` (Correct answer)
- `load-sysctl /etc/sysctl.d/99-custom.conf`
Correct answer: `sysctl -p`
The `sysctl -p` command loads kernel parameter settings from all standard configuration files, including `/etc/sysctl.conf` and files within `/etc/sysctl.d/`. This is the standard procedure to apply persistent settings to the running kernel without needing to reboot.
Question 2: To configure a Linux server as a simple network router, a system administrator needs to enable IPv4 forwarding permanently. What is the recommended method to ensure this setting persists across reboots?
- Run the command `sysctl -w net.ipv4.ip_forward=1`.
- Add the line `net.ipv4.ip_forward = 1` to the `/etc/rc.local` file.
- Create a file, such as `/etc/sysctl.d/90-routing.conf`, with the content `net.ipv4.ip_forward = 1`. (Correct answer)
- Run the command `echo 1 > /proc/sys/net/ipv4/ip_forward`.
Correct answer: Create a file, such as `/etc/sysctl.d/90-routing.conf`, with the content `net.ipv4.ip_forward = 1`.
Creating a dedicated file in the `/etc/sysctl.d/` directory is the modern and recommended best practice for making persistent changes to kernel parameters. This method is organized, easy to manage, and automatically applied at boot by the `systemd-sysctl.service`. The other methods are either temporary (sysctl -w, echo) or rely on legacy mechanisms (`rc.local`).
Question 3: Which of the following filesystems provides a direct, real-time interface for viewing and modifying kernel parameters?
- `/sys`
- `/dev`
- `/etc/sysconfig`
- `/proc/sys` (Correct answer)
Correct answer: `/proc/sys`
The `/proc/sys/` directory is a virtual filesystem that provides a direct interface to kernel parameters. Each file within this hierarchy corresponds to a specific parameter, and reading from or writing to these files directly manipulates the kernel's live configuration.
Question 4: A system administrator modifies the kernel's tendency to use swap space by executing the command: `echo 10 > /proc/sys/vm/swappiness`. The server is then rebooted for unrelated maintenance. Assuming no persistent configuration for this parameter exists, what will be the value of `vm.swappiness` after the server boots up?
- It will remain 10.
- It will revert to the system's default value. (Correct answer)
- It will be set to 0.
- The system will fail to boot due to the un-saved configuration change.
Correct answer: It will revert to the system's default value.
Writing directly to files in the `/proc/sys` filesystem modifies the kernel parameters for the current runtime session only. These changes are ephemeral and do not survive a reboot. Upon startup, the kernel loads its default values, which are then overridden by any persistent settings found in `/etc/sysctl.conf` or `/etc/sysctl.d/`.
Question 5: What is the primary function of the `sysctl -w parameter=value` command?
- To write the parameter change permanently to `/etc/sysctl.conf`.
- To watch a parameter for any real-time changes.
- To display all writable kernel parameters.
- To change a single kernel parameter in the running kernel. (Correct answer)
Correct answer: To change a single kernel parameter in the running kernel.
The `sysctl -w` command is used to modify (write) a single kernel parameter at runtime. It is functionally equivalent to using `echo` to write a value to the corresponding file in `/proc/sys/`. This change is not persistent and will be lost upon reboot unless also added to a configuration file.
Question 6: A system administrator adds `vm.swappiness = 20` to the `/etc/sysctl.conf` file. After rebooting, they run `sysctl vm.swappiness` and see the output `vm.swappiness = 60`. Which of the following is the most likely reason the setting was not applied?
- The `sysctl` service is disabled in systemd.
- Another configuration file in `/etc/sysctl.d/` with a later name (e.g., `99-performance.conf`) is setting the same parameter to 60. (Correct answer)
- The `/etc/sysctl.conf` file has incorrect file permissions and could not be read.
- The kernel does not support the `vm.swappiness` parameter.
Correct answer: Another configuration file in `/etc/sysctl.d/` with a later name (e.g., `99-performance.conf`) is setting the same parameter to 60.
The system processes files in `/etc/sysctl.d/` in lexicographical (alphabetical) order after processing `/etc/sysctl.conf`. A file with a name that sorts later, such as `99-performance.conf`, will be read after other files, and any settings it contains will override previously defined ones. This is a common source of configuration conflicts.
A system administrator has just created a new configuration file at `/etc/sysctl.d/99-custom.conf` to tune network parameters.
Which command should be used to apply these new settings immediately without rebooting the system?