sysctl
Please give several examples of changing kernel parameters temporarily and permantently. Assume that the computer system is running a modern version of RHEL.
Certainly! Here are several examples of changing kernel parameters temporarily and permanently in a modern version of RHEL (Red Hat Enterprise Linux):
Temporarily Changing Kernel Parameters:
a) Modify a kernel parameter during runtime:
sysctl -w kernel.sysrq=1
This command temporarily sets the value of the "kernel.sysrq" parameter to 1, enabling the SysRq key functionality. The change is effective until the next system reboot.
b) Set a boot-time kernel parameter during the current boot:
grubby --args="selinux=0" --update-kernel="$(grubby --default-kernel)"
This command adds the "selinux=0" parameter temporarily to the current kernel's boot configuration, disabling SELinux for the current boot only. The change is effective until the next system reboot.
Permanently Changing Kernel Parameters:
a) Modify a kernel parameter persistently using sysctl.conf:
echo "net.ipv4.ip_forward = 1" >> /etc/sysctl.conf sysctl -p
This sequence of commands appends the "net.ipv4.ip_forward = 1" line to the "/etc/sysctl.conf" file, enabling IP forwarding persistently. The
sysctl -p
command reloads the sysctl settings.b) Set a boot-time kernel parameter permanently:
grubby --args="ipv6.disable=1" --update-kernel="$(grubby --default-kernel)"
This command adds the "ipv6.disable=1" parameter permanently to the kernel's boot configuration, disabling IPv6 permanently across system reboots.
c) Modify kernel parameters using the sysctl.d directory:
echo "vm.swappiness=10" > /etc/sysctl.d/99-custom.conf sysctl -p /etc/sysctl.d/99-custom.conf
This sequence of commands creates a custom configuration file "/etc/sysctl.d/99-custom.conf" with the line "vm.swappiness=10", modifying the swappiness parameter. The
sysctl -p
command reloads the sysctl settings from the custom configuration file.
It's important to note that the specific kernel parameters and their values may vary depending on the system's requirements. Always consult the documentation and consider the impact of changing kernel parameters before making any modifications, especially for permanent changes.