This guide explains how to manage network services in Linux by starting, stopping, and checking their status using various tools.
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.
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.
To list all programs that are ready to accept incoming connections, issue the following command:
Copy
Ask AI
sudo ss -ltunp
This command provides output similar to the partial example below. In later sections, we will examine a complete output listing all the fields.
Copy
Ask AI
$ sudo ss -ltunpNetid State Recv-Q Send-Q Local Address:Porttcp LISTEN 0 128 0.0.0.0:22
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:
Let’s inspect the output in detail, focusing on the local address and port columns:
Copy
Ask AI
$ sudo ss -ltunpNetid State Recv-Q Send-Q Local Address:Porttcp LISTEN 0 128 0.0.0.0:22$ sudo ss -tunlp$ ss --helpUsage: ss [ OPTIONS ] ss [ OPTIONS ] [ FILTER ] -h, --help this message -V, --version output version information -n, --numeric don't resolve service names -r, --resolve resolve host names -a, --all display all sockets -l, --listening display listening sockets -e, --options show timer information -E, --extended show detailed socket information -m, --memory show socket memory usage -p, --processes show process using socket
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:
Copy
Ask AI
$ sudo ss -ltunpNetid State Recv-Q Send-Q Local Address:Port Peer Address:Port Processtcp LISTEN 0 80 127.0.0.1:3306 0.0.0.0:* users:(("mariadb",pid=738,fd=20))tcp LISTEN 0 128 0.0.0.0:22 0.0.0.0:* users:(("sshd",pid=679,fd=3))tcp LISTEN 0 128 [::]:22 [::]:* users:(("sshd",pid=679,fd=4))
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:
Copy
Ask AI
$ sudo ss -ltunpNetid State Recv-Q Send-Q Local Address:Port Peer Address:Port Processtcp LISTEN 0 80 127.0.0.1:3306 0.0.0.0:* users:(("mariadb",pid=738,fd=20))tcp LISTEN 0 128 0.0.0.0:22 0.0.0.0:* users:(("sshd",pid=679,fd=3))tcp LISTEN 0 128 :::22 :::* users:(("sshd",pid=679,fd=4))
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: