Note:

Use sysctl on Oracle Linux 8

Introduction

The following tutorial provides step-by-step procedures to modify system configuration files, view and modify kernel settings, and discover hardware device and device driver attributes.

Objectives

In this lab, you’ll:

What Do You Need?

(Hands-on Lab) Connect to the Compute Instance

Note: This step is specific to the Oracle provided free lab environment.

The Desktop environment will display before the instance(s) are ready. Deployment of this environment can take two to five minutes, depending on the number of resources and provisioning steps needed.

First, to access the lab compute instance(s), connect to the Oracle Cloud Console and copy the compute instance Public IP address.

  1. Sign in to Oracle Cloud Console, and select your Compartment.

  2. Click Instances.

  3. Copy the Public IP to a temporary location (such as a text file) on your computer.

    copy public ip

    To copy, highlight the IP address with the mouse and press Ctrl+C.

  4. Right-click the Virtual Desktop and select Open Terminal Here.

  5. Connect to the instance.

    ssh -i ../.ssh/id_rsa oracle@<IP_ADDRESS_OF_COMPUTE_INSTANCE>
    

    Where <IP_ADDRESS_OF_COMPUTE_INSTANCE> is the IP address copied from the Oracle Cloud Console.

  6. Accept the ECDSA key fingerprint by typing yes at the prompt.

  7. You are now connected to the compute instance for this lab.

If the connection fails with the Permission denied (publickey,gssapi-keyex,gssapi-with-mic) message, wait a bit longer for the provisioning process to complete and try making the ssh connection again.

Explore the /etc/sysconfig Directory

In this section, you explore the /etc/sysconfig directory and selected files in it. You see that many initialization scripts derive values from files in the directory. You view documentation that describes the entries in the directory. And, you make changes to files and observe the effect of the changes.

  1. As the root user, use the cd command to change to the /etc/sysconfig directory, and then use the ls command to explore the contents of it.

    cd /etc/sysconfig
    ls -l
    

    sysconfig output

    • Some of these files contain configuration settings for the respective service.
    • Some of these files contain command-line arguments for the respective service.
    • Some of these are directories and some are symbolic links.

  2. Use the less command to view selected files.

    • Press q to quit the less command and close the file.
    • Some files are given as examples but you can view files and directories of your choice.
    less firewalld
    less crond
    less kernel
    

    sysconfig output

    Note that the files contain configuration settings, command-line options, and so on.

  3. Use the cd command to change to the /usr/share/doc/initscripts* directory and explore its contents.

    cd /usr/share/doc/initscripts*
    ls
    

    sysconfig output

  4. Use the less command to display the contents of the sysconfig.txt file.

    less sysconfig.txt
    

    sysconfig output

  5. Search the contents of the sysconfig.txt file for /etc/sysconfig.

    • While viewing the file using the less command, use the slash (/) key followed by etc/sysconfig to search for this string.
    • Press n (lowercase for “next”) to display the next instance of the string.
    • Continue to view the /etc/sysconfig entries in this file.
    • At the /etc/sysconfig/network entry, notice some of the variables initialized in this file. Here are some examples: NETWORKING=yes|no GATEWAY=<gateway IP> NISDOMAIN=<nis domain name>
    • Press q to quit the “less” command.

Explore the /proc File System

In this section, you explore the proc file system (directory), view various files and directories that represent the current state of the kernel, and change the value of current settings. Where needed, scroll through output using navigation keys such as Page Up and Page Down. Also where needed, enter “q” to terminate output and return to the prompt.

  1. As the root user, use the ls command to display the contents of the /proc directory.

    ls /proc
    

    ls output

    • Numbered entries are directories referring to process IDs.

  2. Use the ls command to display entries without numerical names.

    • Output shows partial directory listing.

    ls -ld /proc/[a-z]* | less
    

    ls output

    • Notice that some entries are files and some entries are directories.

  3. View the meminfo file to display information about RAM.

    less /proc/meminfo
    

    meminfo output

  4. View the cpuinfo file to display information about the processors used by your system.

    less /proc/cpuinfo
    

    cpuinfo output

  5. View the devices file to display information about the various character and block devices currently configured.

    less /proc/devices
    

    devices output

  6. Change to the /proc directory, and then use the ls command to display only the directories in /proc with numerical names.

    • Output shows partial directory listing.

    cd /proc
    ls -d [0-9]*
    

    proc output

  7. Show that one process directory exists for each process running on your system.

    ls -d [0-9]* | wc -l
    ps -e | wc -l
    

    groups

    • The ps command produces one more entry due to the column headings.

  8. Use the ps command to show that the process id (PID) of the systemd process is “1”, and then change directory to the PID directory in /proc and view its contents.

    ps -e | less
    cd /proc/1
    ls -l
    

    proc output

    • Notice that some entries are files, some entries are directories, and some entries are symbolic links.

  9. Use the less command to display the status of PID=1.

    less status
    

    less output

    • Note output shows partial listing.

  10. Use the cat command to check the status of IP forwarding.

    • Note that IP forwarding is disabled by default, set to 0.

    cat /proc/sys/net/ipv4/ip_forward
    

    cat output

    • If the value is 0, IP forwarding is disabled; if set to 1, forwarding is enabled. IP forwarding allows you to set up a Linux router or gateway.
    • If the value of IP forwarding is currently set to 1, use the echo command to set the value of IP forwarding to 0 and then change it back to 1.
    • If the value of IP forwarding is currently set to 0, simply change it to 1 by only running the second echo command followed by the cat command.

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

    cat output

  11. Use the cat command to view the local port range used by TCP and UDP traffic.

    cat /proc/sys/net/ipv4/ip_local_port_range
    

    cat output

    • If the port range is not 32768 61000, use the echo command to define the local port range used by TCP and UDP traffic to be 32768 61000.

    echo "32768 61000" > /proc/sys/net/ipv4/ip_local_port_range
    cat /proc/sys/net/ipv4/ip_local_port_range
    

    cat output

    • Notice that the first local port and the last local port allowed are surrounded by quotation marks.

Explore the sysfs File System

In this section, you explore the sysfs file system. You view the virtual block devices and virtual interfaces, and determine which power states are supported on your system.

  1. As the root user, use the ls command to display the contents of the /sys directory.

    ls -l /sys
    

    ls output

  2. Use the ls command to display the virtual disk block (sd) devices on your system.

    ls -l /sys/block | grep sd
    

    ls output

  3. Traverse the /sys/bus directory and display the virtual interface (virtio) devices.

    cd /sys/bus/virtio/devices
    ls virt*
    

    ls output

  4. Display the operational state, MAC address, and MTU of ens3.

    cd virtio0/net/ens3
    pwd
    ls
    cat operstate
    cat address
    cat mtu
    

    virt devices

Use the sysctl Utility

  1. As the root user, use the sysctl command to disable IP forwarding.

    • Setting the ip_forward variable to 0 disables IP forwarding.

    cat /proc/sys/net/ipv4/ip_forward
    sysctl -w net.ipv4.ip_forward=0
    cat /proc/sys/net/ipv4/ip_forward
    

    sysctl output

  2. Use the sysctl command to enable IP forwarding.

    • Setting the ip_forward variable to 1 enables IP forwarding.

    sysctl -w net.ipv4.ip_forward=1
    cat /proc/sys/net/ipv4/ip_forward
    

    sysctl output

  3. Use the sysctl command to display the current kernel settings, piping the output to the less command.

    sysctl -a | less
    

    sudo works

    • Output shows partial listing.
    • Scroll through the output using navigation keys such as Page Up and Page Down. Enter “q” to return to the prompt.

  4. Use the less command to view the contents of the /etc/sysctl.d/99-sysctl.conf file.

    less /etc/sysctl.d/99-sysctl.conf
    

    less output

    • Changes that are made by using both echo and sysctl are lost when the system is rebooted.
    • To preserve custom settings, add them to a /etc/sysctl.d/<name>.conf file.
    • Values that are added to these files take effect each time the system boots.
    • To immediately enable changes added to files in /etc/sysctl.d/<name>.conf, run sysctl -p /etc/sysctl.d/<name>.conf, providing the file name.
    • Enter “q” to return to the prompt.

More Learning Resources

Explore other labs on docs.oracle.com/learn or access more free learning content on the Oracle Learning YouTube channel. Additionally, visit education.oracle.com/learning-explorer to become an Oracle Learning Explorer.

For product documentation, visit Oracle Help Center.

More Learning Resources

Explore other labs on docs.oracle.com/learn or access more free learning content on the Oracle Learning YouTube channel. Additionally, visit education.oracle.com/learning-explorer to become an Oracle Learning Explorer.

For product documentation, visit Oracle Help Center.