RHEL7: Use /proc/sys and sysctl to modify and set kernel runtime parameters.

Share this link

Note: This was a RHCE 7 exam objective until June 2016. It is now removed from the curriculum.

Presentation

When you want to improve the performance or the characteristics of your server, you need to set the kernel runtime parameters.

In order to do this, you’ve got three ways:

  • through the /proc filesystem,
  • with the sysctl command,
  • through the /etc/sysctl.conf file.

The /proc Filesystem

To get the value of a kernel runtime parameter (here /proc/sys/net/ipv4/ip_forward used for allowing a host to act as an router), type:

# cat /proc/sys/net/ipv4/ip_forward

To set the value of the same parameter, type:

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

Note: 1 is used for On and 0 for off.

This change is instantaneously active but doesn’t persist a reboot. You have to write it into the /etc/rc.d/rc.local file to get it re-applied at each boot. See below for a better solution.

The sysctl Command

With the sysctl command, you can get all the available kernel runtime parameters with their current value.

# sysctl -a | grep vm.swappiness
vm.swappiness = 30

But you can also set a kernel runtime parameter with the -w option.

# sysctl -w vm.swappiness=20
vm.swappiness = 20

Still like the previous method, this change is instantaneously active but doesn’t persist a reboot. You have to write it into the /etc/rc.d/rc.local file to get it re-applied at each boot. See below for a better solution.

The /etc/sysctl.conf File

To permanently store kernel runtime parameters, you need to write them into the /etc/sysctl.conf file.

For example, edit the /etc/sysctl.conf file and paste the following line:

# allow IPv4 forwarding
net.ipv4.ip_forward = 1

Caution: Comments are only allowed on a separate line and not at the end of a line!
Note: It is not a coincidence if the net.ipv4.ip_forward kernel runtime parameter name matches the /proc/sys/net/ipv4/ip_forward path name.

Note: There is also a directory called /etc/sysctl.d. You can create files with .conf extension inside that will be read at boot.

Then, you need to apply the change:

# sysctl -p

Caution: Only changes in the /etc/sysctl.conf file will be applied. If you created some files in the /etc/sysctl.d directory, you will need either to type sysctl -p /etc/sysctl.d/file.conf (if file.conf is the file where kernel runtime parameters are stored) or sysctl –system to get the associated changes applied.

Many kernel runtime parameters can be set this way. Here are only a few examples:

# don't respond to a ping
net.ipv4.icmp_echo_ignore_all = 1
# don't respond to a ping to the broadcast address
net.ipv4.icmp_echo_ignore_broadcasts = 1
# disable IPv6 for all network interfaces
net.ipv6.conf.all.disable_ipv6 = 1

Note: As seen before, the sysctl -a command gets all the kernel runtime parameters with their current value. By redirecting the output to a file, this is also a good way to back up your configuration before any change.

Default kernel runtime configuration is located in the /usr/lib/sysctl.d directory.

To know the order the files are read and apply the various settings, type: # sysctl –system.

Caution: Kernel runtime parameters set in the /etc/sysctl.conf file can be overrided by the application of a tuned profile (see this example).

Additional Resources

Suse provides an interesting SLES 11/12 OS Tuning & Optimization Guide.
Fedora documentation‘s got a page about Suggested /etc/sysctl.conf config.
Kernel.org also provides documentation about sysctl configuration.

(No Ratings Yet)
Loading...
23 comments on “RHEL7: Use /proc/sys and sysctl to modify and set kernel runtime parameters.
  1. ak340 says:

    Hi Certdepot, should we need to know how to tune kernel module parameters and kernel parameters for rhcsa exam?

  2. ak340 says:

    Hi mate,
    sysctl -p is not working.
    Should I include the configuration file? like sysctl -p changes.conf?

    • CertDepot says:

      You are perfectly right.
      You need to run sysctl -p /etc/sysctl.d/changes.conf
      I updated the tutorial.
      Thanks a lot for this useful comment.

      • Buddha1115 says:

        I’ll quickly add that you do not necessarily need to specify the specific *.conf file, but rather, you can use sysctl -p –system to read in settings from all system configuration files, including but not limited to /etc/sysctl.d :

        –system
        Load settings from all system configuration files.
        /run/sysctl.d/*.conf
        /etc/sysctl.d/*.conf
        /usr/local/lib/sysctl.d/*.conf
        /usr/lib/sysctl.d/*.conf
        /lib/sysctl.d/*.conf
        /etc/sysctl.conf

  3. tom says:

    One little trick from sysctl.d man page:

    Note that both / and . are accepted as label separators within sysctl variable names. “kernel.domainname=foo” and “kernel/domainname=foo” hence are entirely equivalent.

  4. ILMostro says:

    Instead of trying to navigate the maze of directories in the “/proc/…” subdirectories, why not use the `sysctl` tool entirely on its own?

    For example,

    # cat /proc/sys/net/ipv4/ip_forward

    can be done with

    # sysctl -a |grep ip_forward

    To write/change values, do

    # sysctl -w net.ipv4.ip_forward=1

  5. ILMostro says:

    Take a look at the SYSCTL(8) man-page; here’s a useful note differences between sysctl commandline tool and /proc when dealing with deprecated params:

    DEPRECATED PARAMETERS
    The base_reachable_time and retrans_time are deprecated. The sysctl command does not allow changing values of these parameters. Users who insist to use deprecated kernel interfaces should push values to /proc file system by
    other means. For example:

    echo 256 > /proc/sys/net/ipv6/neigh/eth0/base_reachable_time

  6. hunter86_bg says:

    You should bear in mind that in CentOS 7.2 some kernel runtime parameters (I’ve tested with vm.swappiness) can’t be set on boot, while they could in CentOS 7.0.

  7. hunter86_bg says:

    By the way echo something > /proc/sys/ is not a recommended way. It’s better to use “sysctl -w (this switch is optional) =” with no spaces around the “=”.
    Also, sysctl variable=new_setting is equal to sysctl -w variable=new_setting.
    When I want to do it permanent, I write the conf file in /etc/sysctl.d/any_name.conf and then sysctl -p /etc/sysctl.d/any_name.conf

    • CertDepot says:

      Concerning echo something > /proc/sys/, I will add your method.
      Concerning the /etc/sysctl.d/any_name.conf file, I personally prefer to stick with /etc/sysctl.conf because it’s quicker. Sorry.

  8. hunter86_bg says:

    Is it possible to add some way of editing, so we won’t need to do it this way? By the way, I really loved your website while I was preparing for my RHCSA, and I still think it is.
    Happy New Year!

    • CertDepot says:

      Thanks for these kind words.
      I’m using the WordPress software and I don’t know if this feature is available.
      For the time being, editing doesn’t bother me!
      Happy New Year!

  9. hunter86_bg says:

    I have received response for the issue with the vm.swappiness not set on boot. It seems that the tuned daemon is applying settings after the systemd-sysctl daemon. There are 2 approaches in resolving this : to disable the tuned profile or to edit the configuration of the tuned daemon.
    I didn’t have enough time to review what tunables are affected by the tuned profiles.
    The virtual-guest profile seems to change only 2 tunables: vm.dirty_ratio and vm.swappiness.

  10. reaz_mahmood says:

    Sander’s book says /etc/sysctl.conf should not be used, instead .conf files should be created in the /etc/sysctl.d/ directory to make the tunable change permanent.
    Any idea why?
    Thanks.

  11. thegeekaid says:

    So, this topic is removed from RHCE objectives?

Leave a Reply

Upcoming Events (Local Time)

There are no events.

Follow me on Twitter

Archives

vceplus-200-125    | boson-200-125    | training-cissp    | actualtests-cissp    | techexams-cissp    | gratisexams-300-075    | pearsonitcertification-210-260    | examsboost-210-260    | examsforall-210-260    | dumps4free-210-260    | reddit-210-260    | cisexams-352-001    | itexamfox-352-001    | passguaranteed-352-001    | passeasily-352-001    | freeccnastudyguide-200-120    | gocertify-200-120    | passcerty-200-120    | certifyguide-70-980    | dumpscollection-70-980    | examcollection-70-534    | cbtnuggets-210-065    | examfiles-400-051    | passitdump-400-051    | pearsonitcertification-70-462    | anderseide-70-347    | thomas-70-533    | research-1V0-605    | topix-102-400    | certdepot-EX200    | pearsonit-640-916    | itproguru-70-533    | reddit-100-105    | channel9-70-346    | anderseide-70-346    | theiia-IIA-CIA-PART3    | certificationHP-hp0-s41    | pearsonitcertification-640-916    | anderMicrosoft-70-534    | cathMicrosoft-70-462    | examcollection-cca-500    | techexams-gcih    | mslearn-70-346    | measureup-70-486    | pass4sure-hp0-s41    | iiba-640-916    | itsecurity-sscp    | cbtnuggets-300-320    | blogged-70-486    | pass4sure-IIA-CIA-PART1    | cbtnuggets-100-101    | developerhandbook-70-486    | lpicisco-101    | mylearn-1V0-605    | tomsitpro-cism    | gnosis-101    | channel9Mic-70-534    | ipass-IIA-CIA-PART1    | forcerts-70-417    | tests-sy0-401    | ipasstheciaexam-IIA-CIA-PART3    | mostcisco-300-135    | buildazure-70-533    | cloudera-cca-500    | pdf4cert-2v0-621    | f5cisco-101    | gocertify-1z0-062    | quora-640-916    | micrcosoft-70-480    | brain2pass-70-417    | examcompass-sy0-401    | global-EX200    | iassc-ICGB    | vceplus-300-115    | quizlet-810-403    | cbtnuggets-70-697    | educationOracle-1Z0-434    | channel9-70-534    | officialcerts-400-051    | examsboost-IIA-CIA-PART1    | networktut-300-135    | teststarter-300-206    | pluralsight-70-486    | coding-70-486    | freeccna-100-101    | digitaltut-300-101    | iiba-CBAP    | virtuallymikebrown-640-916    | isaca-cism    | whizlabs-pmp    | techexams-70-980    | ciscopress-300-115    | techtarget-cism    | pearsonitcertification-300-070    | testking-2v0-621    | isacaNew-cism    | simplilearn-pmi-rmp    | simplilearn-pmp    | educationOracle-1z0-809    | education-1z0-809    | teachertube-1Z0-434    | villanovau-CBAP    | quora-300-206    | certifyguide-300-208    | cbtnuggets-100-105    | flydumps-70-417    | gratisexams-1V0-605    | ituonline-1z0-062    | techexams-cas-002    | simplilearn-70-534    | pluralsight-70-697    | theiia-IIA-CIA-PART1    | itexamtips-400-051    | pearsonitcertification-EX200    | pluralsight-70-480    | learn-hp0-s42    | giac-gpen    | mindhub-102-400    | coursesmsu-CBAP    | examsforall-2v0-621    | developerhandbook-70-487    | root-EX200    | coderanch-1z0-809    | getfreedumps-1z0-062    | comptia-cas-002    | quora-1z0-809    | boson-300-135    | killtest-2v0-621    | learncia-IIA-CIA-PART3    | computer-gcih    | universitycloudera-cca-500    | itexamrun-70-410    | certificationHPv2-hp0-s41    | certskills-100-105    | skipitnow-70-417    | gocertify-sy0-401    | prep4sure-70-417    | simplilearn-cisa    |
http://www.pmsas.pr.gov.br/wp-content/    | http://www.pmsas.pr.gov.br/wp-content/    |