Logo
  • Ubuntu
  • CentOS
  • Debian
  • Fedora
  • RedHat

Sysctl Command in Linux - DesignLinux

designlinux 0 Comments

As a Linux system administrator, sometimes you may need to modify the default kernel’s behavior. For example, you may need to enable the magic SysRq key or to increase the number of connections that Kernel will accept. The kernel parameters can be set when building the kernel, on system boot, or at runtime.

This article explains how to use the sysctl command to view and modify kernel parameters at runtime.

Using sysctl to View the Kernel Parameters #

To view all current kernel parameters invoke the sysctl command with the -a option:

sysctl -a

This will output a large list that looks something like the following where each line includes the name of the parameter and its value:

abi.vsyscall32 = 1
debug.exception-trace = 1
debug.kprobes-optimization = 1
...

All users can view the current kernel parameters; only the root user can modify their values.

You can check the value of a single parameter by passing its name as an argument to sysctl. For example, to check the current swappiness value you would type:

sysctl vm.swappiness
vm.swappiness = 60

Swappiness is a Linux kernel property that defines how often the system will use the swap space.

The sysctl command reads the information from the /proc/sys directory. /proc/sys is a virtual directory that contains file objects that can be used to view and set the current kernel parameters.

You can also view a parameter value by displaying the content of the appropriate file. The only difference is how the file is represented. For example, both sysctl vm.swappiness and cat /proc/sys/vm/swappiness will give the same output. When using sysctl the directory slashes are replaced with dots and the proc.sys part is assumed.

Using sysctl to Modify the Kernel Parameters #

To set a kernel parameter at runtime run the sysctl command followed by the parameter name and value in the following format:

sysctl -w parameter=value

If the value contains empty space or special characters, enclose the value in double-quotes. You can also pass multiple parameter=value pairs in the same command.

Be extra careful when changing kernel settings on a production system as it may make the kernel unstable, and you’ll need to reboot the system.

For example, to enable IPv4 packet forwarding you would run:

sysctl -w net.ipv4.ip_forward=1

The change takes effect immediately, but it is not persistent. After a system reboot, the default value is loaded.

To set a parameter permanently, you’ll need to write the settings to /etc/sysctl.conf or another configuration file in the /etc/sysctl.d directory:

sysctl -w net.ipv4.ip_forward=1 >> /etc/sysctl.conf

Another way to change parameters is to use the echo command to write the settings to the files in the /proc/sys directory. For example, instead of running the command above, you can use:

echo 1 > /proc/sys/net/ipv4/ip_forward

The -p option allows you to load the settings from a configuration file:

sysctl -p /etc/sysctl.d/file_name.conf

When no file is given, sysctl reads the /etc/sysctl.conf file.

Conclusion #

The sysctl command allows you to view and change Linux kernel parameters.

Feel free to leave a comment if you have any questions.

sysctl kernel terminal

Related

Tags: kernel, sysctl, terminal

How to Install OpenCV on Ubuntu 20.04

Prev Post

How to Install Steam on Ubuntu 20.04

Next Post
Archives
  • January 2023
  • December 2022
  • November 2022
  • October 2022
  • September 2022
  • July 2022
  • June 2022
  • April 2022
  • March 2022
  • February 2022
  • January 2022
  • December 2021
  • November 2021
  • October 2021
  • September 2021
  • August 2021
  • July 2021
  • June 2021
  • May 2021
  • April 2021
  • March 2021
  • February 2021
  • January 2021
  • December 2020
  • November 2020
  • October 2020
  • September 2020
  • August 2020
  • July 2020
  • June 2020
  • May 2020
Categories
  • AlmaLinux
  • Android
  • Ansible
  • Apache
  • Arch Linux
  • AWS
  • Backups
  • Bash Shell
  • Bodhi Linux
  • CentOS
  • CentOS Stream
  • Chef
  • Cloud Software
  • CMS
  • Commandline Tools
  • Control Panels
  • CouchDB
  • Data Recovery Tools
  • Databases
  • Debian
  • Deepin Linux
  • Desktops
  • Development Tools
  • Docker
  • Download Managers
  • Drupal
  • Editors
  • Elementary OS
  • Encryption Tools
  • Fedora
  • Firewalls
  • FreeBSD
  • FTP
  • GIMP
  • Git
  • Hadoop
  • HAProxy
  • Java
  • Jenkins
  • Joomla
  • Kali Linux
  • KDE
  • Kubernetes
  • KVM
  • Laravel
  • Let's Encrypt
  • LFCA
  • Linux Certifications
  • Linux Commands
  • Linux Desktop
  • Linux Distros
  • Linux IDE
  • Linux Mint
  • Linux Talks
  • Lubuntu
  • LXC
  • Mail Server
  • Manjaro
  • MariaDB
  • MongoDB
  • Monitoring Tools
  • MySQL
  • Network
  • Networking Commands
  • NFS
  • Nginx
  • Nodejs
  • NTP
  • Open Source
  • OpenSUSE
  • Oracle Linux
  • Package Managers
  • Pentoo
  • PHP
  • Podman
  • Postfix Mail Server
  • PostgreSQL
  • Python
  • Questions
  • RedHat
  • Redis Server
  • Rocky Linux
  • Security
  • Shell Scripting
  • SQLite
  • SSH
  • Storage
  • Suse
  • Terminals
  • Text Editors
  • Top Tools
  • Torrent Clients
  • Tutorial
  • Ubuntu
  • Udemy Courses
  • Uncategorized
  • VirtualBox
  • Virtualization
  • VMware
  • VPN
  • VSCode Editor
  • Web Browsers
  • Web Design
  • Web Hosting
  • Web Servers
  • Webmin
  • Windows
  • Windows Subsystem
  • WordPress
  • Zabbix
  • Zentyal
  • Zorin OS
Visits
  • 0
  • 589
  • 1,055,361

DesignLinux.com © All rights reserved

Go to mobile version