Using chkconfig Command In Linux [Examples]

chkconfig command in linux

chkconfig command in Linux is actually a way allowing users to handle services on their machine. it can be used to list all available services, view or update their running status. means, using chkconfig command can easily help you to list current startup information of services or even of a particularly specified service too. in addition, it can help to update runlevelsettings of a service as well as adding or removing a specified service from management.

Syntax of chkconfig command

chkconfig --list [name]
chkconfig --add name
chkconfig --del name
chkconfig --override name
chkconfig [--level levels] name 
chkconfig [--level levels] name

Usage and examples of chkconfig command

1: Lising current status of all services

In order to list all services and their current status, we use the following command. It actually indicates the status of starting and stopping all services.

chkconfig --list

2: Listing all services in alphabetical order

In order to view current status of al services in alphabetical order, we can use the following command:

chkconfig --list | sort

3: Checking current status of specified services

If you intend to view the current status of a starting or stopping particular service, you can use the following command snippet. This command will show you startup configuration of a service, more precisely it actually tells that HTTP services are closed in all run levels.

chkconfig --list | grep httpd
httpd service status

4: Enable a particular service on run levels

The following command enables the httpd services at run level 4.

chkconfig --level 4 httpd on

to verify the action, run the following command to check the status of httpd services running at the run level.

chkconfig --list | grep httpd

5: Disable a particular service on run levels

In order to disable a particular service, we can use chkconfig command. In this example, we have stopped HTTP services at the run level 4 only.

chkconfig --level 4 httpd off

In order to stop a particular service (say httpd) at multiple run levels, you can run this command:

chkconfig --level 4 httpd off

6: Deleting a services

if we use delete command with chkconfig, it will completely delete a specified service from system. In the example below, we have removed ‘httpd’ service from the chkconfig list.

chkconfig --del httpd

7: Adding a new service

Creating a new service using chkconfig command is also very easy. Let’s take an instance where we would add a new ‘nfs’ service, and it will automatically start on run level 1,2,3,4, and 5.

chkconfig --add nfs

to check if the nfs service is added at all above mentioned run level, run the following command:

chkconfig --list | grep nfs
example 7
Note: While adding a new service using chkconfig command, it adds only those services which are already available on a machine. If you try to add such a service which is not available or installed on the machine, it will fail unless you install the associated package.