The chkconfig is a simple command-line utility to manage services at each run level. Using chkconfig command you can list all services status (on or off) for each run levels and configure start and stop of service listed in '/etc/rd.d/init.d' directory.
Apart from listing services, chkconfig command is used to add and remove services from specific run levels. The chkconfig command can also manage xinetd.d configuration files (services controlled by xinetd).
In this tutorial, we learn about chkconfig command through some practical examples.
Chkconfig command Syntax and Options
The following line shows chkconfig syntax and its available options:
chkconfig --list [name]
chkconfig --add name
chkconfig --del name
chkconfig [--level levels] name
chkconfig [--level levels] name
List all service status on runlevels
The chkconfig --list
option is used to display the current status all services showing either started or stopped in their respective run levels.
# chkconfig --list
auditd 0:off 1:off 2:on 3:on 4:on 5:on 6:off
blk-availability 0:off 1:on 2:on 3:on 4:on 5:on 6:off
crond 0:off 1:off 2:on 3:on 4:on 5:on 6:off
ip6tables 0:off 1:off 2:on 3:on 4:on 5:on 6:off
iptables 0:off 1:off 2:on 3:on 4:on 5:on 6:off
iscsi 0:off 1:off 2:off 3:on 4:on 5:on 6:off
iscsid 0:off 1:off 2:off 3:on 4:on 5:on 6:off
lvm2-monitor 0:off 1:on 2:on 3:on 4:on 5:on 6:off
mdmonitor 0:off 1:off 2:on 3:on 4:on 5:on 6:off
List specific service
You can add more command with chkconfig to list specific service.
In the following example I use grep command to list 'sshd' service:
# chkconfig --list | grep sshd
sshd 0:off 1:off 2:on 3:on 4:on 5:on 6:off
To list all service started on run level 3 use the following command:
# chkconfig --list | grep 3:on
Enable (start) service on run levels
Let's check how to start a particular service on specific run levels.
The following command shows how to start 'nfs' service on run level 5 and second command list the run level status of 'nfs' service:
# chkconfig --level 5 nfs on
# chkconfig --list | grep nfs
nfs 0:off 1:off 2:off 3:off 4:off 5:on 6:off
Lete check how to start a service in multiple levels using single command.
In the following command we start 'nfs' service in level 3 and 5:
# chkconfig --level 35 nfs on
# chkconfig --list | grep nfs
nfs 0:off 1:off 2:off 3:on 4:off 5:on 6:off
Disable (stop) service on run levels
The following commands show how to stop the 'nfs' service in run level 5:
# chkconfig --level 5 nfs off
You can stop the service in mutiple run level using the following command:
# chkconfig --level 35 nfs off
How to add service
The --add
option adds a service to chkconfig management. The chkconfig creates the appropriate entry (start or stop) as specified by the default values in the init script.
The following commands add iptables services and it will start on level 2, 3 , 4 and 5 automatically:
# chkconfig --add iptables
# chkconfig –list | grep iptables
iptables 0:off 1:off 2:on 3:on 4:on 5:on 6:off
Command will only add the service which is present in the system. If the service is not present then you should first install the package and then you can add to the startup list of the system.
How to delete a service
The --del
option completely removes a service from chkconfig system. The following commands delete 'iptables' service from chkconfig list.
# chkconfig --del ip6tables
Conclusion
When chkconfig --add
is executed, it creates a symbolic link file so that services can be started and stopped under its corresponding rc (/etc/rc[0-6].d) directory. And when chkconfig --del
is executed, it removes the same symbolic link from the directory.
As modern Linux distributions moved from SysV to systemd, chkconfig command is replaced with systemctl commands. I hope you enjoyed reading and please leave your commands in the below comment section.