chkconfig Command in Linux with Examples

chkconfig Command in Linux with Examples

chkconfig Command helps you to configure services for starting and stopping them automatically when the Operating System boots. This is configured in the scripts, /etc/rc.d/init.d. This tutorial covers the ground on installation of chkconfig command.

Command to list All Services in run-level

The &ndash list parameter displays all the services along with their current start up status in each run-level configuration.

[root@linuxhelp Desktop]# chkconfig --list
NetworkManager     0:off    1:off    2:on    3:on    4:on    5:on    6:off
abrt-ccpp          0:off    1:off    2:off    3:on    4:off    5:on    6:off
abrtd              0:off    1:off    2:off    3:on    4:off    5:on    6:off
acpid              0:off    1:off    2:on    3:on    4:on    5:on    6:off
atd                0:off    1:off    2:off    3:on    4:on    5:on    6:off
auditd             0:off    1:off    2:on    3:on    4:on    5:on    6:off
autofs             0:off    1:off    2:off    3:on    4:on    5:on    6:off
.
.
.
.
winbind            0:off    1:off    2:off    3:off    4:off    5:off    6:off
wpa_supplicant     0:off    1:off    2:off    3:off    4:off    5:off    6:off
ypbind             0:off    1:off    2:off    3:off    4:off    5:off    6:off

Command to check the Status of Specific Services in run-level

The following command shows the start up configuration for a particular service.

[root@linuxhelp Desktop]# chkconfig --list| grep nfs
nfs                0:off    1:off    2:off    3:off    4:off    5:off    6:off
nfslock            0:off    1:off    2:off    3:on    4:on    5:on    6:off

Command to start a Particular Service on Run Levels

Here we use &ndash level parameter in the chkconfig command, to start httpd services only on run level 3 and 5.

[root@tecmint ~]# chkconfig --level 35 httpd o

Similarly, we can start nfs service.

[root@linuxhelp Desktop]# chkconfig--level 35 nfs on

After assigned run level state to nfs now verify the state by following command.

[root@linuxhelp Desktop]# chkconfig --list | grep nfs
nfs              0:off    1:off    2:off    3:on    4:off    5:on    6:off

Command to check Whether the Services are On / Off state in run-level

Running the following command displays all the services, which are On and Off in run level 5.

[root@linuxhelp Desktop]# chkconfig --list | grep  5:on
NetworkManager     0:off    1:off    2:on    3:on    4:on    5:on    6:off
abrt-ccpp          0:off    1:off    2:off    3:on    4:off    5:on    6:off
abrtd              0:off    1:off    2:off    3:on    4:off    5:on    6:off
acpid              0:off    1:off    2:on    3:on    4:on    5:on    6:off
atd                0:off    1:off    2:off    3:on    4:on    5:on    6:off
auditd             0:off    1:off    2:on    3:on    4:on    5:on    6:off
[root@linuxhelp Desktop]# chkconfig --list | grep  5:off
dnsmasq            0:off    1:off    2:off    3:off    4:off    5:off    6:off
firstboot          0:off    1:off    2:off    3:off    4:off    5:off    6:off
htcacheclean       0:off    1:off    2:off    3:off    4:off    5:off    6:off
kdump              0:off    1:off    2:off    3:off    4:off    5:off    6:off
netconsole         0:off    1:off    2:off    3:off    4:off    5:off    6:off

Command to stop a Particular Service on Run Levels

Running the following command will turn Off a service named nfs for a single run level and it is also possible for turning Off a service in multiple levels as illustrated below.

[root@linuxhelp Desktop]# chkconfig --level 2 nfs off
[root@linuxhelp Desktop]# chkconfig --list | grep nfs
nfs                0:off    1:off    2:off    3:off    4:off    5:off    6:off
nfslock            0:off    1:off    2:off    3:on    4:on    5:on    6:off

If you want to give multiple run-level state you should follow the below command.

[root@linuxhelp Desktop]# chkconfig --level 234 nfs off
[root@linuxhelp Desktop]# chkconfig --list | grep nfs
nfs                0:off    1:off    2:off    3:off    4:off    5:off    6:off
nfslock            0:off    1:off    2:off    3:on    4:on    5:on    6:off
FAQ
Q
How to change Linux services startup/boot order?
A
You can change the order by renaming the symlinks under /etc/rcX.d/ where x will be your run level.
chkconfig: 35 90 10
Q
What is the command to help to view the options in chkconfig?
A
The command to view the options in the chkconfig
syntax; " chkconfig --help "
Q
What is the command to list all startup services in alphabetic order?
A
The command to list all startup services in alphabetic order is chkconfig --list | sort | less
auditd 0:off 1:off 2:on 3:on 4:on 5:on 6:off
...
Q
How to turn off audit in the run levels 3,4 and 5?
A
The command to turn off the audit run levels
chkconfig --level 345 auditd off
auditd 0:off 1:off 2:on 3:off 4:off 5:off 6:off
Q
How to list audit service using chkconfig?
A
The command used to view the audit service.
chkconfig --list auditd
auditd 0:off 1:off 2:on 3:on 4:on 5:on 6:off