≡ Menu

7 Linux chkconfig Command Examples – Add, Remove, View, Change Services

Chkconfig command is used to setup, view, or change services that are configured to start automatically during the system startup.

This article contains 7 practical examples that explains how to use the chkconfig command.

1. Check Service Startup status from Shell Script

When you execute chkconfig command only with the service name, it returns true if the service is configured for startup. The following code snippet shows how to check whether a service is configured for startup or not from a shell script.

# vi check.sh
chkconfig network && echo "Network service is configured"
chkconfig junk && echo "Junk service is configured"

# ./check.sh
Network service is configured

You can also specifically check whether it is configured for a particular run level or not.

# vi check1.sh
chkconfig network --level 3 && echo "Network service is configured for level 3"
chkconfig network --level 1 && echo "Network service is configured for level 1"

# ./check1.sh
Network service is configured for level 3

2. View Current Status of Startup Services

The –list option displays all the services with the current startup configuration status.

# chkconfig --list
abrtd   0:off   1:off   2:off   3:on    4:off   5:on    6:off
acpid   0:off   1:off   2:off   3:off   4:off   5:off   6:off
atd     0:off   1:off   2:off   3:on    4:on    5:on    6:off
...

To view only the services that are configured to be started during system startup, do the following. Please note that this assumes that your system startup level is 3.

chkconfig --list | grep 3:on

Note: To view all available system run levels, refer to 6 Stages of Linux Boot Process

To view the startup configuration of a particular service, grep the output of ‘chkconfig –list’ for that service.

chkconfig --list | grep network

3. Add a new Service to the Startup

Use –add option to add a specific service to the list of services that will be started during system reboot.

The following example shows how to add a new service (for example, iptables) to the list of services that needs to be started. The ‘chkconfig –add’ command will also turn on level 2, 3, 4 and 5 automatically as shown below.

# chkconfig --list | grep iptables

# chkconfig --add iptables

# chkconfig --list | grep iptables
iptables       0:off   1:off   2:on    3:on    4:on    5:on    6:off

Note: “chkconfig –add” only adds an existing service to the list of startup. If the service doesn’t exist, you should first install it before adding it to the system startup list. While this is pretty obvious, it is worth to mention it, as a newbie might make this mistake.

4. Remove a Service From Startup List

The following example shows that ip6tables services is configured for startup.

# chkconfig --list | grep ip6tables
ip6tables       0:off   1:off   2:off   3:on   4:off   5:off   6:off

To remove it from the startup list, use the –del option as shown below.

# chkconfig --del ip6tables

# chkconfig --list | grep ip6tables

5. Turn-on or Turn-off a Service for a Selected Run Level

Sometimes you might not want to delete the whole service. Instead, you might just want to turn the flag on or off for a particular run level (for a particular service).

The following example will turn off nfserver service for level 5

# chkconfig --level 5 nfsserver off

You can also combine multiple levels. The following example will turn off nfsserver for both level 3 and 5.

# chkconfig --level 35 nfsserver off

6. Script Files under rc.d Subdirectories

Whenever you add or remove a service from chkconfig control, it does the following under the /etc/rc.d sub-directories.

  • When chkconfig –add command is executed, it creates a symbolic link file to start and stop the service under corresponding rc directory.
  • When chkconfig –del command is executed, it removes the symbolic link file from the corresponding rc directory.

The following example shows that xinetd is enabled for both run level 3 and 5.

So, xinetd will have two files under rc3.d directory, and two files under rc5.d directory. The file that starts with K is used during shutdown (K stands for kill). The file that starts with S is used during startup (S stands for start).

# chkconfig --list | grep xinetd
xinetd                    0:off  1:off  2:off  3:on   4:off  5:on   6:off
xinetd based services:

# cd /etc/rc.d/rc3.d
# ls | grep xinetd
K08xinetd
S14xinetd

# cd /etc/rc.d/rc5.d

# ls | grep xinetd
K08xinetd
S14xinetd

7. rcx.d Directory Changes for Add Operation

When you add a new service to chkconfig control, the default run levels for that service will be turned on automatically, and files will be created under the corresponding rcx directories.

For example, if the nfsserver service doesn’t exist in the chkconfig control, no nfsserver service startup files would be present under /etc/rc.d/rc*.d directories as shown below.

# chkconfig  --list | grep nfsserver
nfsserver                 0:off  1:off  2:off  3:off  4:off  5:off  6:off

# ls /etc/rc.d/rc3.d | grep nfsserver

# ls /etc/rc.d/rc5.d | grep nfsserver

After you add the nfsserver service, you’ll see the symbolic links under these directories.

# chkconfig --add nfsserver
nfsserver                 0:off  1:off  2:off  3:on   4:off  5:on   6:off

# cd  /etc/rc.d/rc3.d
# ls -l | grep nfsserver
lrwxrwxrwx 1 root root 12 2011-06-18 00:52 K08nfsserver -> ../nfsserver
lrwxrwxrwx 1 root root 12 2011-06-18 00:52 S14nfsserver -> ../nfsserver

# cd /etc/rc.d/rc5.d
# ls -l | grep nfsserver
lrwxrwxrwx 1 root root 12 2011-06-18 00:52 K08nfsserver -> ../nfsserver
lrwxrwxrwx 1 root root 12 2011-06-18 00:52 S14nfsserver -> ../nfsserver

When you turn off the service either using –del option or –level option, the corresponding symbolic link file under rcx.d directory will be deleted as shown below.

# chkconfig --level 5 nfsserver off

# ls /etc/rc.d/rc5.d  | grep nfsserver
Add your comment

If you enjoyed this article, you might also like..

  1. 50 Linux Sysadmin Tutorials
  2. 50 Most Frequently Used Linux Commands (With Examples)
  3. Top 25 Best Linux Performance Monitoring and Debugging Tools
  4. Mommy, I found it! – 15 Practical Linux Find Command Examples
  5. Linux 101 Hacks 2nd Edition eBook Linux 101 Hacks Book

Bash 101 Hacks Book Sed and Awk 101 Hacks Book Nagios Core 3 Book Vim 101 Hacks Book

Comments on this entry are closed.

  • Nishith June 21, 2011, 4:45 am

    Really Great Article. Sure will help linuxers a lot….

  • RO June 21, 2011, 5:26 am

    chkconfig is only for RedHat based Linux distros as I recall – definitely not in my Ubuntu-based Mint installation (could it be added from repositories?).

  • pier June 21, 2011, 5:50 am

    Hi,

    @RO
    I am quite sure you can add the chkconfig prog to an ubuntu box with a simple
    apt-get install chkconfig

  • ron June 21, 2011, 9:49 am

    for ubuntu there is something called BUM (Boot-Up Manager ) which can be downloaded and installed thru aptitude or apt-get

  • jalal hajigholamali June 21, 2011, 11:59 am

    Very useful and Great Article

  • sean June 22, 2011, 1:24 am

    nice work.

  • Patrick TenHoopen June 22, 2011, 3:04 pm

    Thanks for another great article.

    I believe the service’s definition file in /etc/rc.d/ determines the run levels that a service will be enabled for, and chkconfig reads and honors those settings.

    Also, running chkconfig without any options provides an overall on|off status:

    acpid on
    alsasound on
    atd off
    cron on

  • Shan June 30, 2011, 12:58 pm

    ntsysv command can be used to managing services/dameons along with –level 35 option

  • rathin May 21, 2012, 1:40 am

    it’s one of the good site for the linux aspirants

  • Ivaylo June 14, 2012, 11:45 am

    Very Useful !!!
    Thank You

  • Lewis January 12, 2016, 6:36 pm

    Argh, I really don’t like Linux. Everything is so unnecessarily complicated. It definitely has it’s place though.

  • Robert January 25, 2016, 7:20 pm

    Thanks for a helpful article.

  • shashi March 21, 2016, 6:33 am

    nice article
    thanks.

  • sreekanth Basani June 23, 2017, 12:40 pm

    very useful document. Thank you a lot