Network Administration: Linux Package and Service Commands

As a Linux administrator, you frequently need to start and stop services and check the status of installed packages or install new packages. The following describes the Linux commands that help you to perform these tasks.

The service command

You use the service command to check the status of services and to start, stop, or restart services. You need to restart a service whenever you make a configuration change in order for your changes to take effect. Here’s the basic syntax:

service [service] [ start |  stop | restart ]

The following paragraphs describe some typical uses of the service command:

  • To check the status of the httpd service (Apache), use this command:

    $ service httpd status
  • To stop the httpd service:

    $ service httpd stop
  • To start the httpd service:

    $ service httpd start
  • To restart the httpd service:

$ service httpd restart

The only trick to using the service command is that you have to know the name of the service. If you’re not sure of the name, you can run the service command to display the status of all services, like this:

$ service --status-all

It will take a few moments to list all the services, but after the command is done, you can scroll through the list to find the service that you’re looking for.

Common Linux Services
Service Description
atd Runs commands scheduled by the at command.
autof Automatically mounts file systems.
crond Runs programs at specified times.
dhcpd The DHCP server.
finger The Internet finger service.
httpd The Apache Web server.
imap The IMAP mail protocol.
imaps Secure IMAP service (SSL).
ipop3 The POP3 mail protocol.
iptables Automatic packet filtering for firewalls.
isdn ISDN services.
named The Bind DNS server.
netf The network file system.
network Activates and deactivates all network interfaces.
nfs Native Unix/Linux network file sharing.
pop3s Secure POP3 service (SSL).
sendmail The Sendmail service.
smb The Samba file and printer sharing service.
snmpd Simple Network Management Protocol.
telnet The Telnet server.

The rpm command

The rpm command is the Red Hat Package Manager, a tool that simplifies the task of managing packages on your Linux system. Although rpm was originally developed for Red Hat Linux, it’s now found on many Linux distributions, including Fedora (which is, of course, based on the Red Hat distribution).

Here’s the basic syntax for querying the status of a package:

rpm -q [options] package

To install, upgrade, or remove a package, the basic syntax is more like this:

rpm [ -i | -u | -e ] [options] package-file

You can use quite a few options with the rpm command, but the most common are

  • -v: Displays verbose output. You may as well know what rpm is doing while it chugs along.

  • -h: Displays hash marks (#) periodically to reassure you that the program hasn’t died.

You can use rpm to determine the status of installed packages on your system by using the -q switch. For example, to find out what version of Sendmail is installed, use this command:

$ rpm -q send*
Sendmail-8.12.8-4

Notice that you can use a wildcard with the package name. If you don’t have a package whose name matches the package name you supply, you get the message package not installed.

To install a package, you use the -i switch and specify a wildcard filename that indicates the location of the package file. It’s also a good idea to use the -v and -h switches. For example, to install Sendmail from a mounted CD-ROM drive, you use this command:

$ rpm -ivh /mnt/cdrom/Fedora/Packages/sendmail*

If you want to update to a newer version of a package, you can use the -u switch instead of the -i switch:

$ rpm -uvh /mnt/cdrom/Fedora/Packages/sendmail*

Finally, you can remove a package by using the -e switch:

$ rpm -e send*

Note that to use the rpm command, you should log on as root.