Skip to main content
In this guide, we explore how to manage network services in Linux by starting, stopping, and checking their status. Many servers run multiple services—such as the SSH daemon—that listen for incoming network connections. The SSH daemon, for example, runs in the background, enabling remote login capabilities. Let’s begin by examining the programs currently active and waiting for incoming network connections.
The image shows a diagram with a user icon connected to a server running three services: sshd, mariadbd, and nginx.

Viewing Active Network Connections

Two commonly used utilities for viewing active network connections are SS and Netstat. While SS is the modern alternative, Netstat is older and may eventually be deprecated in future Linux releases.
The image shows a dark interface labeled "Utilities" with two icons: "ss" and "netstat," each represented by a gear symbol.

Using the SS Utility

To list all programs that are ready to accept incoming connections, issue the following command:
This command provides output similar to the partial example below. In later sections, we will examine a complete output listing all the fields.
Below is a brief overview of the options used:
  • -l: Only display sockets currently listening for connections.
  • -t: Filter to show only TCP connections.
  • -u: Include UDP connections.
  • -n: Show numeric values (such as port numbers) instead of resolving service names.
  • -p: Display the process using each socket (root privileges are required to view processes owned by root).
Using the -n option ensures that you see exact port numbers. For example, port 22 in the output confirms the SSH daemon’s listening port.
A useful mnemonic to remember these options is L-T-U-N-P (Listening, TCP, UDP, Numeric, Process). Alternatively, arrange them as TUNLP (Tunnel Programs) for ease of recall. If you are ever uncertain about the available options, check the SS help page:

Detailed Analysis of SS Output

Let’s inspect the output in detail, focusing on the local address and port columns:
An IP address like 127.0.0.1 in the Local Address column indicates that the service is only accepting connections from the local machine (localhost). For example, a web server (NGINX) connecting to a database server (MariaDB) on the same machine typically uses 127.0.0.1 on port 3306. Consider the following enhanced SS output:
In this example:
  • MariaDB listens on 127.0.0.1:3306, limiting its access to the localhost.
  • SSHD listens on both IPv4 (0.0.0.0:22) and IPv6 ([::]:22), allowing both local and external connections.
Another SS output reiterates these points:

Checking Service Status with systemctl

To verify the status of these network services, you can use the systemctl command as follows:
On Ubuntu, the SSH service is often listed as ssh (without a trailing “d”). In contrast, other distributions like Red Hat may refer to it as sshd.
Below is an example of the output for both MariaDB and SSH services:

Stopping and Disabling Services

To stop the MariaDB service, use the following command. After you stop it, re-run the SS command to verify that port 3306 no longer appears.
The SS output after stopping MariaDB might look like this:
Prevent MariaDB from starting automatically at boot with:
You can later re-enable and start the service as needed.

Inspecting Process Details

After confirming the SSH daemon’s process ID from the SS output (e.g., PID 679), you can use the ps command to inspect it further:
Further details about the process, including open files and sockets, can be retrieved using lsof:

Using the Netstat Utility

Although SS offers modern functionality, you can also use the Netstat utility to produce a similar output:
Below is an example of Netstat’s formatted output:
While Netstat’s output is often neatly formatted for readability, remember that it may not be installed by default on every system.

Conclusion

This article detailed the processes involved in starting, stopping, and checking the status of network services on Linux using both SS and Netstat tools, as well as systemctl for service management. Understanding these fundamentals will help you effectively monitor your system’s network services and troubleshoot connectivity issues when they arise. For further reading, consider exploring: Happy troubleshooting!

Watch Video

Practice Lab