Viewing Current Kernel Parameters
To view all active kernel runtime parameters, use the sysctl command with the -a flag. Note that not all parameters are accessible to a normal user; some lines might display “permission denied”. Using sudo will grant root privileges to read all parameters. Below are example outputs demonstrating the difference:net.ipv6.conf.default.disable_ipv6 controls the status of IPv6 within the network category. A value of 0 (false) means IPv6 is enabled, while 1 (true) disables IPv6. To change this parameter non-persistently—meaning the change lasts only until the next system reboot—use the command below. The -w flag is used to write a new value, and be sure not to include spaces before or after the equals sign.
Non-persistent changes are effective immediately but will revert to their default settings after a reboot.
Making Changes Persistent
Persistent changes require modifying configuration files in the/etc/sysctl.d/ directory. These files must have a .conf extension. Persistent settings ensure that your changes are maintained across reboots.
For example, consider the memory-related parameter vm.swappiness, which determines how aggressively the kernel uses disk swap space as an extension of physical memory. The parameter can take a value between 0 and 100: a higher value causes the kernel to use swap sooner, while a lower value delays swapping.
Begin by referencing the man page for the sysctl.d directory to confirm the file extension requirement:
vm.swappiness:
vm.swappiness from 30 to 29. Create a new configuration file in the /etc/sysctl.d directory. In our example, we use the filename swap-less.conf to indicate that the setting will result in less frequent swapping.
Remember, non-persistent changes made with sysctl -w will be lost after reboot, while persistent changes require adding a configuration file in
/etc/sysctl.d/ and can be activated immediately using sysctl -p.