How To Use Chkconfig Command.
This guide will show you how to use the chkconfig command to control system services in Linux.
Modern Linux distributions come with the systemd initialization system that allows users to manage services with the systemctl command.
However, some older systems still use System V or Upstart. In that case, use the chkconfig command to list, start, and stop services, as well as enable or disable services from startup.
The chkconfig Command Syntax
The chkconfig command syntax looks like this:
The command works on its own but can also be used with:
The –list, –level, –add, –del, and –override options specified before the service name. The options print the details or manage the service in question.
The on, off, reset, or resetpriorities subcommands added after the service name. The subcommands change the startup info for the specified service.
The chkconfig Command Options.
However, executing the command with different options and subcommands enables users to manage services instead of only listing them. The table below shows the options and subcommands used with the chkconfig command:
Displays all services and their current startup status in each runlevel.
–list | sort
Sorts services alphabetically and displays them with their current startup status in each runlevel.
–list | grep on
Shows only running services and their current startup status in each runlevel.
–list | grep off
Shows only services disabled in one or more runlevels and their current startup status in each runlevel.
–list | grep –level <levels>:on
Level-specific: Prints services running in a particular runlevel.
–list | grep –level <levels>:off
Level-specific: Prints services that are disabled in a certain runlevel.
Outputs the status of a particular service in each runlevel.
Enables a service to start on system boot.
Disables a service from starting on system boot.
–level <levels> [service] on
Turns on a particular service in a single or multiple runlevels.
–level <levels> [service] off
Turns off a particular service in single or multiple runlevels.
Adds a service to startup in all runlevels.
Removes a service from the startup in all runlevels.
Resets the on/off statuses of all services.
Resets the start/stop priorities of all services.
Reconfigures a service to the override settings instead of the default configuration.
The chkconfig Command Examples
The chkconfig command is the ultimate service managing tool for older Linux systems. The sections below outline common chkconfig examples.
List All Services
To list all services, execute the command without options or run:
Using –list with the chkconfig command displays the status of all available services in all runlevels. In case you want to sort services in alphabetical order, use the sort option:
List All Enabled Services
To find all enabled services (in one or multiple runlevels), execute combine chkconfig –list with the grep command:
To find all disabled services (in one or multiple runlevels), run:
Furthermore, to narrow down the scope to the services on/off a particular runlevel, use:
For example, list all the services running in runlevel 5 with:
On the other hand, to display all the services that are not running in runlevel 5, execute:
List a Particular Service
To show the startup configuration of a particular service in all runlevels, run chkconfig –list and specify the service.
For example, check the status of the ntpd service in all runlevels with:
The output shows that the ntpd service is disabled on boot in any runlevel.
Enable a Service
Enable a service to start on boot with the chkconfig [service] on command. Next, confirm that the service is on using <strong>–list</strong>.
The on option affects runlevels 2, 3, 4, and 5 and starts the ntpd service on boot on these runlevels. To enable a service on one or multiple runlevels only, run:
For example, start the ntpd service on the third runlevel and verify the service’s configuration with:
Similarly, to turn on the ntpd service in multiple runlevels in one go use:
Disable a Service
Disable a service from starting at system boot with the chkconfig [service] off command:
Even though the off variable also affects runlevels 2 to 5, users can specify in which runlevels to disable a service.
For instance, disable the ntpd service only in runlevel 3 and verify the results with:
Add a Service
Add a service to startup in all runlevels with the following command:
For example, use the –add option to add ntpd to startup in all runlevels. Next, use –list to verify the service has been added:
The chkconfig command adds and configures the service as specified by the default values in the init script. For example, the ntpd service is disabled in every runlevel by default.
Remove a Service
Remove a service from startup in all runlevels with the –del option:
The –del option removes the service from startup, but the service remains in the system. Therefore, to add the service back to startup, use the –add option again.
Reset Service Configuration
To reset the on/off status of a service in all runlevels as specified in the init script, execute:
The output shows that ntpd returns to the default off status in all runlevels.
After reading this tutorial, you know how to use the chkconfig command to manage services in older versions of Linux.