| | |

LFCA 47 ๐Ÿง Checking Open Ports โ€” ss, netstat

A port is a number that identifies a service on a host. The web server listens on the 80 or the 443, the SSH daemon listens on the 22, the database listens on the 5432. When a connection arrives, the kernel uses the port to route the packet to the right process. The two commands that show the open ports, the listening sockets, and the active connections are ss and its predecessor netstat. The ss is the modern, and the netstat is the legacy โ€” it is deprecated on most distributions but still appears in older documentation and on the older systems. The two answer the questions that matter in the diagnosis: what is listening, on which interface, on which port, and which process owns it. This chapter covers the socket’s model, the ss‘s output, the netstat‘s output, the common options, the TCP’s states, the process’s attribution, the patterns for the security audit and the diagnosis, and the migration from the netstat to the ss. It builds on LFCA 41 through 46 and prepares the ground for the firewall’s material.

Key point: A socket is the combination of the IP address and the port. The ss and the netstat show the sockets, and the two have the similar output. The ss -tlnp shows the TCP’s listening sockets, and the -u adds the UDP, the -a adds all, the -n shows the numbers instead of the names, and the -p shows the process. The LISTEN state is the server waiting for the connection, the ESTABLISHED is the active connection, the TIME_WAIT is the recently closed, and the CLOSE_WAIT is the connection waiting for the local application to close. The ss is the faster and the modern; the netstat is the slower and the legacy. The ports below the 1024 are the privileged, and the 0.0.0.0 is the all interfaces, and the 127.0.0.1 is the loopback only.


The socket’s model

A socket is the endpoint of a connection, and it is the combination of the IP address and the port. The server’s socket is the listening, and the client’s is the connected. The two are the pair, and the pair is the connection.

The five-tuple. A connection is identified by the five-tuple: the protocol, the local’s address, the local’s port, the remote’s address, the remote’s port. The five are the unique, and the unique is the connection’s.

The listening’s socket. The server’s socket is the listening, and the listening is the LISTEN‘s state. The local’s address is the 0.0.0.0 (the all) or the specific, and the local’s port is the service’s. The two are the pair, and the pair is the listening’s.

The connected’s socket. The client’s socket is the connected, and the connected is the ESTABLISHED‘s state. The local’s and the remote’s are the pair, and the pair is the connection’s.

Why the socket’s model matters. The socket’s model is the connection’s, and the connection’s is the diagnosis. The ss and the netstat show the sockets, and the sockets are the model. The two are the pair, and the pair is the diagnostic.

Why the port’s number matters. The port’s number is the service’s, and the service’s is the process’s. The 22 is the SSH’s, the 80 is the HTTP’s, the 443 is the HTTPS’s. The three are the common, and the common is the vocabulary.

Why the privileged’s ports matter. The ports below the 1024 are the privileged, and the privileged is the root’s. The binding requires the root, and the root is the privilege’s. The two are the pair, and the pair is the security’s.

Why the all-interfaces’s address matters. The 0.0.0.0 is the all’s, and the all’s is the every’s. The server binds the 0.0.0.0, and the every interface is the listening’s. The two are the pair, and the pair is the exposure’s.

Why the loopback’s address matters. The 127.0.0.1 is the loopback’s, and the loopback’s is the local’s. The server binds the 127.0.0.1, and the local only is the listening’s. The two are the pair, and the pair is the safe’s.

Why the address’s choice matters. The address’s choice is the exposure’s, and the exposure’s is the security’s. The 0.0.0.0 is the exposed’s, and the 127.0.0.1 is the local’s. The two are the choice, and the choice is the design.

Why the socket’s family matters. The socket’s family is the IPv4’s or the IPv6’s, and the family is the specific’s. The tcp is the IPv4’s, and the tcp6 is the IPv6’s. The two are the pair, and the pair is the diagnostic.


The ss‘s basic usage

The ss is the modern, and it is the iproute2‘s. The basic usage is the ss, and the output is the sockets’.

ss
# Netid  State   Recv-Q  Send-Q  Local Address:Port   Peer Address:Port
# tcp    ESTAB   0       0       192.168.1.100:22     192.168.1.50:54321
# tcp    ESTAB   0       0       192.168.1.100:443    192.168.1.60:54322

The Netid is the protocol’s, the State is the socket’s, the Recv-Q and the Send-Q are the queues’, and the Local Address:Port and the Peer Address:Port are the addresses’.

Why the ss‘s output matters. The ss‘s output is the sockets’, and the sockets’ is the model. The Netid, the State, the Recv-Q, the Send-Q, the Local, the Peer are the six. The six are the pair, and the pair is the diagnostic.

Why the Netid matters. The Netid is the protocol’s, and the protocol’s is the tcp, the udp, the tcp6, the udp6, the unix. The five are the common, and the common is the vocabulary.

Why the State matters. The State is the socket’s, and the socket’s is the LISTEN, the ESTAB, the TIME-WAIT, the CLOSE-WAIT. The four are the common, and the common is the diagnosis.

Why the Recv-Q and the Send-Q matter. The Recv-Q is the receive’s queue, and the Send-Q is the send’s queue. The two are the buffers’, and the buffers’ is the performance’s. The two are the pair, and the pair is the backlog’s.

Why the queues matter for the listening’s socket. The listening’s Recv-Q is the backlog’s, and the Send-Q is the max’s. The two are the pair, and the pair is the backlog’s.

Why the queues matter for the connected’s socket. The connected’s Recv-Q is the unread’s, and the Send-Q is the unsent’s. The two are the pair, and the pair is the application’s.

Why the Local Address:Port matters. The Local Address:Port is the local’s, and the local’s is the server’s. The 192.168.1.100:22 is the SSH’s, and the 192.168.1.100:443 is the HTTPS’s. The two are the pair, and the pair is the diagnostic.

Why the Peer Address:Port matters. The Peer Address:Port is the remote’s, and the remote’s is the client’s. The 192.168.1.50:54321 is the client’s, and the 192.168.1.60:54322 is the other’s. The two are the pair, and the pair is the connection’s.

Why the ss‘s default output matters. The ss‘s default is the connected’s, and the connected’s is the ESTAB‘s. The -a is the all’s, and the all’s is the listening’s and the connected’s. The two are the pair, and the pair is the option’s.

Why the ss‘s -a matters. The -a is the all’s, and the all’s is the complete’s.

ss -a
# Netid  State   Recv-Q  Send-Q  Local Address:Port   Peer Address:Port
# tcp    LISTEN  0       128     0.0.0.0:22           0.0.0.0:*
# tcp    ESTAB   0       0       192.168.1.100:22     192.168.1.50:54321

The -a is the all’s, and the all’s is the complete’s. The LISTEN and the ESTAB are the both’s, and the both is the complete’s. The two are the pair, and the pair is the option’s.

Why the ss‘s -l matters. The -l is the listening’s, and the listening’s is the server’s.

ss -l
# Netid  State   Recv-Q  Send-Q  Local Address:Port   Peer Address:Port
# tcp    LISTEN  0       128     0.0.0.0:22           0.0.0.0:*
# tcp    LISTEN  0       511     0.0.0.0:80           0.0.0.0:*
# tcp    LISTEN  0       511     0.0.0.0:443          0.0.0.0:*

The -l is the listening’s, and the listening’s is the server’s. The three are the LISTEN‘s, and the LISTEN‘s is the server’s. The two are the pair, and the pair is the option’s.

Why the ss‘s -t matters. The -t is the TCP’s, and the TCP’s is the stream’s.

ss -t

The -t is the TCP’s, and the TCP’s is the stream’s. The two are the pair, and the pair is the option’s.

Why the ss‘s -u matters. The -u is the UDP’s, and the UDP’s is the datagram’s.

ss -u

The -u is the UDP’s, and the UDP’s is the datagram’s. The two are the pair, and the pair is the option’s.

Why the ss‘s -n matters. The -n is the numeric’s, and the numeric’s is the no-DNS’s.

ss -n
# tcp    ESTAB   0       0       192.168.1.100:22     192.168.1.50:54321

The -n is the numeric’s, and the numeric’s is the no-DNS’s. The 22 is the number’s, and the ssh is the name’s. The two are the pair, and the pair is the speed’s.

Why the -n matters. The -n is the speed’s, and the speed’s is the no-reverse-DNS’s. The reverse’s DNS is the slow’s, and the slow is the delay’s. The two are the pair, and the pair is the fast’s.

Why the ss‘s -p matters. The -p is the process’s, and the process’s is the attribution’s.

ss -p
# tcp    ESTAB   0       0       192.168.1.100:22     192.168.1.50:54321
#      users:(("sshd",pid=1234,fd=3))

The -p is the process’s, and the process’s is the attribution’s. The users:(("sshd",pid=1234,fd=3)) is the process’s, and the process’s is the attribution’s. The two are the pair, and the pair is the option’s.

Why the -p matters. The -p is the attribution’s, and the attribution’s is the diagnosis’s. The process’s is the service’s, and the service’s is the port’s. The two are the pair, and the pair is the diagnostic.

Why the -p requires the root. The -p requires the root, and the root is the process’s. The other user’s processes are the hidden, and the hidden is the privacy’s. The two are the pair, and the pair is the permission’s.

Why the ss‘s -s matters. The -s is the summary’s, and the summary’s is the statistics’.

ss -s
# Total: 123
# TCP:   45 (estab 20, closed 10, orphaned 0, timewait 5)
# UDP:   5

The -s is the summary’s, and the summary’s is the statistics’. The Total, the TCP, the UDP are the three, and the three are the summary’s. The two are the pair, and the pair is the option’s.

Why the -s matters. The -s is the summary’s, and the summary’s is the overview’s. The overview’s is the diagnostic’s, and the diagnostic’s is the first’s. The two are the pair, and the pair is the option’s.


The combined options

The ss‘s options are the combined, and the combined is the specific. The -tlnp is the TCP’s, the listening’s, the numeric’s, the process’s.

The ss -tlnp. The -t is the TCP’s, the -l is the listening’s, the -n is the numeric’s, the -p is the process’s.

sudo ss -tlnp
# State  Recv-Q  Send-Q  Local Address:Port  Peer Address:Port  Process
# LISTEN 0       128     0.0.0.0:22          0.0.0.0:*          users:(("sshd",pid=1234,fd=3))
# LISTEN 0       511     0.0.0.0:80          0.0.0.0:*          users:(("nginx",pid=5678,fd=6))
# LISTEN 0       511     0.0.0.0:443         0.0.0.0:*          users:(("nginx",pid=5678,fd=7))

The sudo ss -tlnp is the TCP’s, the listening’s, the numeric’s, the process’s. The three are the servers’, and the servers’ is the listening’s. The two are the pair, and the pair is the option’s.

Why the ss -tlnp matters. The ss -tlnp is the common, and the common is the security’s. The listening’s servers are the list’s, and the list’s is the audit’s. The two are the pair, and the pair is the diagnosis’s.

The ss -tunlp. The -u adds the UDP’s, and the UDP’s is the datagram’s.

sudo ss -tunlp
# The TCP's and the UDP's listening's.

The -tunlp is the both’s, and the both’s is the complete’s. The TCP’s and the UDP’s are the two, and the two are the complete’s. The two are the pair, and the pair is the option’s.

Why the -tunlp matters. The -tunlp is the both’s, and the both’s is the complete’s. The DNS’s UDP’s 53 is the example, and the example is the UDP’s. The two are the pair, and the pair is the diagnosis’s.

The ss -tanp. The -a is the all’s, and the all’s is the both’s.

sudo ss -tanp
# The listening's and the established's.

The -tanp is the all’s, and the all’s is the both’s. The listening’s and the established’s are the two, and the two are the complete’s. The two are the pair, and the pair is the option’s.

Why the -tanp matters. The -tanp is the all’s, and the all’s is the complete’s. The established’s are the active’s, and the active’s is the connection’s. The two are the pair, and the pair is the diagnostic’s.

The ss -s‘s summary. The -s is the summary’s, and the summary’s is the overview’s.

ss -s
# Total: 123
# TCP:   45 (estab 20, closed 10, orphaned 0, timewait 5)
# UDP:   5

The ss -s is the summary’s, and the summary’s is the overview’s. The Total, the TCP, the UDP are the three, and the three are the summary’s. The two are the pair, and the pair is the option’s.

Why the -s matters. The -s is the summary’s, and the summary’s is the overview’s. The overview’s is the diagnostic’s, and the diagnostic’s is the first’s. The two are the pair, and the pair is the option’s.

Why the options’s combination matters. The options’s combination is the specific’s, and the specific’s is the diagnosis’s. The -tlnp is the audit’s, the -tunlp is the complete’s, the -tanp is the both’s. The three are the common, and the common is the vocabulary.


The netstat‘s comparison

The netstat is the legacy, and it is the net-tools‘s. The output is the similar to the ss‘s, and the options are the similar too.

netstat -tlnp
# Active Internet connections (only servers)
# Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name
# tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN      1234/sshd
# tcp        0      0 0.0.0.0:80              0.0.0.0:*               LISTEN      5678/nginx
# tcp        0      0 0.0.0.0:443             0.0.0.0:*               LISTEN      5678/nginx

The netstat -tlnp is the TCP’s, the listening’s, the numeric’s, the process’s. The Proto, the Recv-Q, the Send-Q, the Local Address, the Foreign Address, the State, the PID/Program name are the seven. The seven are the pair, and the pair is the output’s.

Why the netstat matters. The netstat is the legacy, and the legacy is the older’s. The older’s is the documentation’s, and the documentation’s is the reference. The two are the pair, and the pair is the migration’s.

Why the netstat is deprecated. The netstat is the deprecated, and the deprecated is the net-tools‘s. The net-tools is the legacy, and the legacy is the iproute2‘s. The two are the pair, and the pair is the modern’s.

Why the netstat‘s output differs. The netstat‘s output has the Proto, the Recv-Q, the Send-Q, the Local Address, the Foreign Address, the State, the PID/Program name. The ss‘s has the Netid, the State, the Recv-Q, the Send-Q, the Local Address:Port, the Peer Address:Port, the Process. The two are the similar, and the similar is the migration’s.

Why the netstat‘s -r matters. The netstat -r is the route’s, and the route’s is the ip route‘s.

netstat -r
# Kernel IP routing table
# Destination     Gateway         Genmask         Flags   MSS Window  irtt Iface
# 0.0.0.0         192.168.1.1     0.0.0.0         UG        0 0          0 eth0

The netstat -r is the route’s, and the route’s is the ip route‘s. The two are the pair, and the pair is the migration’s.

Why the netstat -i matters. The netstat -i is the interface’s, and the interface’s is the ip -s link‘s.

netstat -i
# Kernel Interface table
# Iface   MTU     RX-OK RX-ERR RX-DRP RX-OVR    TX-OK TX-ERR TX-DRP TX-OVR Flg
# eth0    1500    12345     0      0 0          12345     0      0      0 BMRU

The netstat -i is the interface’s, and the interface’s is the ip -s link‘s. The two are the pair, and the pair is the migration’s.

Why the migration matters. The migration is the net-tools‘s to the iproute2‘s, and the iproute2‘s is the modern’s. The ss is the netstat‘s replacement, and the ip is the ifconfig‘s and the route‘s. The three are the pair, and the pair is the modern’s.

Why the netstat‘s install matters. The netstat‘s install is the net-tools‘s, and the net-tools‘s is the optional’s.

sudo apt install net-tools  # the Debian's
sudo dnf install net-tools  # the Fedora's

The net-tools is the optional, and the optional is the legacy’s. The two are the pair, and the pair is the install’s.

Why the install matters. The install is the modern’s, and the modern’s is the ss‘s. The ss is the installed, and the installed is the iproute2‘s. The two are the pair, and the pair is the default’s.


The TCP’s states

The TCP’s states are the LISTEN, the ESTABLISHED, the TIME_WAIT, the CLOSE_WAIT, the SYN_SENT, the SYN_RECV, the FIN_WAIT1, the FIN_WAIT2, the CLOSING, the LAST_ACK, the CLOSED. The eleven are the complete, and the complete is the TCP’s.

The LISTEN. The LISTEN is the server’s, and the server’s is the waiting’s. The server is the waiting for the connection, and the waiting is the socket’s. The two are the pair, and the pair is the listening’s.

The ESTABLISHED. The ESTABLISHED is the connected’s, and the connected’s is the active’s. The connection is the open, and the open is the data’s. The two are the pair, and the pair is the active’s.

The TIME_WAIT. The TIME_WAIT is the recently’s, and the recently’s is the closed’s. The connection is the closed, and the closed is the waiting for the 2MSL. The two are the pair, and the pair is the timeout’s.

Why the TIME_WAIT matters. The TIME_WAIT is the recently’s, and the recently’s is the normal’s. The high’s count is the normal for the busy’s server, and the normal is the expected’s. The two are the pair, and the pair is the diagnostic’s.

Why the TIME_WAIT‘s count matters. The TIME_WAIT‘s count is the high’s, and the high’s is the ports’s. The ports’s is the exhausted’s, and the exhausted is the problem’s. The two are the pair, and the pair is the diagnosis’s.

The CLOSE_WAIT. The CLOSE_WAIT is the waiting’s, and the waiting’s is the application’s. The remote is the closed, and the closed is the local’s waiting. The two are the pair, and the pair is the application’s.

Why the CLOSE_WAIT matters. The CLOSE_WAIT is the application’s, and the application’s is the leak’s. The high’s count is the application’s bug, and the bug is the not-closing’s. The two are the pair, and the pair is the diagnostic’s.

Why the CLOSE_WAIT‘s count matters. The CLOSE_WAIT‘s count is the application’s, and the application’s is the resource’s. The high’s count is the leak, and the leak is the bug. The two are the pair, and the pair is the diagnosis’s.

The SYN_SENT. The SYN_SENT is the connecting’s, and the connecting’s is the client’s. The client is the sent the SYN, and the sent is the waiting for the SYN-ACK. The two are the pair, and the pair is the connecting’s.

The SYN_RECV. The SYN_RECV is the receiving’s, and the receiving’s is the server’s. The server is the received the SYN, and the received is the waiting for the ACK. The two are the pair, and the pair is the half-open’s.

Why the SYN_RECV matters. The SYN_RECV is the receiving’s, and the receiving’s is the half-open’s. The high’s count is the SYN flood’s, and the flood is the attack’s. The two are the pair, and the pair is the security’s.

Why the states matter. The states are the TCP’s, and the TCP’s is the connection’s. The eleven are the complete, and the complete is the diagnosis’s. The two are the pair, and the pair is the vocabulary.


The patterns

The patterns are the audit’s, the diagnosis’s, and the monitoring’s. The three are the common, and the common is the use.

The pattern 1: the listening’s audit. The ss -tlnp is the audit’s, and the audit’s is the security’s.

sudo ss -tlnp
# The listening's servers.

The sudo ss -tlnp is the audit’s, and the audit’s is the security’s. The listening’s servers are the list’s, and the list’s is the review’s. The two are the pair, and the pair is the audit’s.

Why the pattern 1 matters. The pattern 1 is the audit’s, and the audit’s is the security’s. The unexpected’s listener is the risk’s, and the risk’s is the review’s. The two are the pair, and the pair is the diagnosis’s.

The pattern 2: the established’s view. The ss -tanp is the established’s, and the established’s is the active’s.

sudo ss -tanp
# The listening's and the established's.

The sudo ss -tanp is the established’s, and the established’s is the active’s. The active’s is the connection’s, and the connection’s is the diagnostic’s. The two are the pair, and the pair is the pattern’s.

Why the pattern 2 matters. The pattern 2 is the active’s, and the active’s is the connection’s. The established’s is the remote’s, and the remote’s is the diagnostic’s. The two are the pair, and the pair is the diagnosis’s.

The pattern 3: the process’s finding. The ss -tlnp | grep <port> is the process’s, and the process’s is the port’s.

sudo ss -tlnp | grep :80
# LISTEN 0 511 0.0.0.0:80 0.0.0.0:* users:(("nginx",pid=5678,fd=6))

The sudo ss -tlnp | grep :80 is the process’s, and the process’s is the port’s. The nginx is the process’s, and the process’s is the attribution’s. The two are the pair, and the pair is the pattern’s.

Why the pattern 3 matters. The pattern 3 is the port’s, and the port’s is the process’s. The “which process owns the port?” is the question’s, and the question’s is the diagnosis’s. The two are the pair, and the pair is the pattern’s.

The pattern 4: the count’s monitoring. The ss -s is the count’s, and the count’s is the monitoring’s.

ss -s
# Total: 123
# TCP:   45 (estab 20, closed 10, orphaned 0, timewait 5)

The ss -s is the count’s, and the count’s is the monitoring’s. The Total, the TCP, the UDP are the three, and the three are the count’s. The two are the pair, and the pair is the pattern’s.

Why the pattern 4 matters. The pattern 4 is the count’s, and the count’s is the monitoring’s. The count’s is the baseline’s, and the baseline’s is the change’s. The two are the pair, and the pair is the pattern’s.

The pattern 5: the state’s filter. The ss -tan state established is the state’s, and the state’s is the specific’s.

ss -tan state established
# The established's only.

The ss -tan state established is the state’s, and the state’s is the specific’s. The two are the pair, and the pair is the pattern’s.

Why the pattern 5 matters. The pattern 5 is the state’s, and the state’s is the specific’s. The time-wait is the specific’s, and the specific’s is the diagnosis’s. The two are the pair, and the pair is the pattern’s.

Why the patterns matter. The patterns are the vocabulary, and the vocabulary is the fluency. The five are the common, and the common is the practice. The two are the pair, and the pair is the skill.


Complete Example Session

# ============================================
# PART 1: THE BASIC SS
# ============================================

ss
# Netid  State   Recv-Q  Send-Q  Local Address:Port   Peer Address:Port
# tcp    ESTAB   0       0       192.168.1.100:22     192.168.1.50:54321
# tcp    ESTAB   0       0       192.168.1.100:443    192.168.1.60:54322

# ============================================
# PART 2: THE LISTENING'S AUDIT
# ============================================

sudo ss -tlnp
# State  Recv-Q  Send-Q  Local Address:Port  Peer Address:Port  Process
# LISTEN 0       128     0.0.0.0:22          0.0.0.0:*          users:(("sshd",pid=1234,fd=3))
# LISTEN 0       511     0.0.0.0:80          0.0.0.0:*          users:(("nginx",pid=5678,fd=6))
# LISTEN 0       511     0.0.0.0:443         0.0.0.0:*          users:(("nginx",pid=5678,fd=7))

# ============================================
# PART 3: THE TCP AND THE UDP
# ============================================

sudo ss -tunlp
# The TCP's and the UDP's listening's.

# ============================================
# PART 4: THE ALL'S
# ============================================

sudo ss -tanp
# The listening's and the established's.

# ============================================
# PART 5: THE SUMMARY
# ============================================

ss -s
# Total: 123
# TCP:   45 (estab 20, closed 10, orphaned 0, timewait 5)
# UDP:   5

# ============================================
# PART 6: THE NETSTAT
# ============================================

netstat -tlnp
# Active Internet connections (only servers)
# Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name
# tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN      1234/sshd
# tcp        0      0 0.0.0.0:80              0.0.0.0:*               LISTEN      5678/nginx
# tcp        0      0 0.0.0.0:443             0.0.0.0:*               LISTEN      5678/nginx

# ============================================
# PART 7: THE PORT'S PROCESS
# ============================================

sudo ss -tlnp | grep :80
# LISTEN 0 511 0.0.0.0:80 0.0.0.0:* users:(("nginx",pid=5678,fd=6))

# ============================================
# PART 8: THE STATE'S FILTER
# ============================================

ss -tan state established
# The established's only.

ss -tan state time-wait
# The time-wait's only.

# ============================================
# PART 9: THE STATES
# ============================================

# LISTEN       โ†’ the server's waiting
# ESTABLISHED  โ†’ the active's connection
# TIME_WAIT    โ†’ the recently's closed
# CLOSE_WAIT   โ†’ the local's waiting

# ============================================
# PART 10: WHAT NOT TO DO
# ============================================

# Don't use the netstat on the modern
# The ss is the modern.                                      // โš ๏ธ

# Don't forget the -n for the speed
# The reverse's DNS is the slow's.                           // โš ๏ธ

# Don't forget the -p for the process
# The process's is the attribution's.                        // โš ๏ธ

# Don't forget the root for the -p
# The -p requires the root.                                  // โš ๏ธ

# Don't ignore the TIME_WAIT's count
# The high's is the normal's, but the very high's is the problem's.โ”‚# โš ๏ธ

# Don't ignore the CLOSE_WAIT's count
# The high's is the application's bug.                       // โš ๏ธ

The ten parts cover the basic ss, the listening’s audit, the TCP and the UDP, the all’s, the summary, the netstat, the port’s process, the state’s filter, the states, and the anti-patterns.


Quick Reference

The ss‘s Options

The optionThe purpose
The -tThe TCP
The -uThe UDP
The -lThe listening
The -aThe all
The -nThe numeric
The -pThe process
The -sThe summary
The -4The IPv4
The -6The IPv6

The Common Combinations

The combinationThe purpose
The -tlnpThe TCP’s listening’s
The -tunlpThe TCP’s and the UDP’s
The -tanpThe all’s
The -tlnp | grep :80The port’s process

The TCP’s States

The stateThe meaning
The LISTENThe server’s waiting
The ESTABLISHEDThe active’s connection
The TIME_WAITThe recently’s closed
The CLOSE_WAITThe local’s waiting
The SYN_SENTThe client’s connecting
The SYN_RECVThe server’s half-open

The netstat‘s Options

The optionThe purpose
The -tThe TCP
The -uThe UDP
The -lThe listening
The -aThe all
The -nThe numeric
The -pThe process
The -rThe route
The -iThe interface

The Addresses

The addressThe meaning
The 0.0.0.0The all interfaces
The 127.0.0.1The loopback only
The ::The all interfaces (the IPv6)
The ::1The loopback only (the IPv6)

The Migration

The legacyThe modern
The netstat -tlnpThe ss -tlnp
The netstat -rThe ip route
The netstat -iThe ip -s link
The ifconfigThe ip addr

Best Practices

โœ… Do This:

# Use the ss for the modern
sudo ss -tlnp                                                  # โœ…

# Use the -n for the speed
sudo ss -tlnpn                                                 # โœ…

# Use the -p for the process
sudo ss -tlnp                                                  # โœ…

# Use the grep for the port
sudo ss -tlnp | grep :80                                       # โœ…

# Use the -s for the summary
ss -s                                                          # โœ…

# Use the state's filter
ss -tan state established                                      # โœ…

# Use the netstat only when needed
netstat -tlnp  # the legacy                                    # โœ…

# Use the -n on the netstat too
netstat -tlnp                                                  # โœ…

โŒ Don’t Do This:

# Don't use the netstat on the modern
netstat -tlnp  # the deprecated                                // โš ๏ธ

# Don't forget the -n
sudo ss -tlp  # the slow                                       // โš ๏ธ

# Don't forget the -p
sudo ss -tln  # the no process                                 // โš ๏ธ

# Don't forget the root for the -p
ss -tlnp  # the no process for the other users                 // โš ๏ธ

# Don't ignore the TIME_WAIT's count
# The very high's is the problem's.                          // โš ๏ธ

# Don't ignore the CLOSE_WAIT's count
# The high's is the application's bug.                       // โš ๏ธ

Common Pitfalls

PitfallProblemSolution
The netstat‘s useThe deprecatedThe ss
The missing -nThe slowThe -n
The missing -pThe no processThe -p
The missing rootThe no processThe sudo
The TIME_WAIT‘s highThe ports’sThe check
The CLOSE_WAIT‘s highThe bugThe application
The wrong addressThe exposureThe 0.0.0.0 vs the 127.0.0.1
The family’sThe separateThe -4 or the -6

Real-World Examples

1. The basic ss

ss

2. The listening’s

sudo ss -tlnp

3. The TCP and the UDP

sudo ss -tunlp

4. The all’s

sudo ss -tanp

5. The summary

ss -s

6. The port’s process

sudo ss -tlnp | grep :80

7. The state’s filter

ss -tan state established

8. The netstat

netstat -tlnp

9. The route

netstat -r

10. The interface

netstat -i

Visual: The Socket’s Model

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚  THE FIVE-TUPLE                                          โ”‚
โ”‚    The protocol                                          โ”‚
โ”‚    The local's address                                   โ”‚
โ”‚    The local's port                                      โ”‚
โ”‚    The remote's address                                  โ”‚
โ”‚    The remote's port                                     โ”‚
โ”‚                                                          โ”‚
โ”‚  THE LISTENING'S                                         โ”‚
โ”‚    The local: 0.0.0.0:22                                 โ”‚
โ”‚    The remote: 0.0.0.0:*                                 โ”‚
โ”‚    The state: LISTEN                                     โ”‚
โ”‚                                                          โ”‚
โ”‚  THE ESTABLISHED'S                                       โ”‚
โ”‚    The local: 192.168.1.100:22                           โ”‚
โ”‚    The remote: 192.168.1.50:54321                        โ”‚
โ”‚    The state: ESTAB                                      โ”‚
โ”‚                                                          โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

Visual: The ss -tlnp‘s Output

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚  State  Recv-Q  Send-Q  Local Address:Port  Peer Address:Port  Processโ”‚
โ”‚  โ”‚      โ”‚       โ”‚       โ”‚                   โ”‚                  โ”‚
โ”‚  โ”‚      โ”‚       โ”‚       โ”‚                   โ”‚                  โ””โ”€โ”€ The processโ”‚
โ”‚  โ”‚      โ”‚       โ”‚       โ”‚                   โ””โ”€โ”€ The remote's     โ”‚
โ”‚  โ”‚      โ”‚       โ”‚       โ””โ”€โ”€ The local's                          โ”‚
โ”‚  โ”‚      โ”‚       โ””โ”€โ”€ The send's queue                             โ”‚
โ”‚  โ”‚      โ””โ”€โ”€ The receive's queue                                  โ”‚
โ”‚  โ””โ”€โ”€ The state                                                   โ”‚
โ”‚                                                          โ”‚
โ”‚  LISTEN 0 128 0.0.0.0:22 0.0.0.0:* users:(("sshd",pid=1234,fd=3))โ”‚
โ”‚  LISTEN 0 511 0.0.0.0:80 0.0.0.0:* users:(("nginx",pid=5678,fd=6))โ”‚
โ”‚                                                          โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

Visual: The TCP’s States

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚  THE SERVER'S SIDE                                       โ”‚
โ”‚    LISTEN       โ†’ the waiting for the connection         โ”‚
โ”‚    SYN_RECV     โ†’ the half-open                          โ”‚
โ”‚    ESTABLISHED  โ†’ the connected                          โ”‚
โ”‚    CLOSE_WAIT   โ†’ the remote's closed, the local's wait   โ”‚
โ”‚    LAST_ACK     โ†’ the final's ACK                        โ”‚
โ”‚    CLOSED       โ†’ the closed                             โ”‚
โ”‚                                                          โ”‚
โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค
โ”‚  THE CLIENT'S SIDE                                       โ”‚
โ”‚    SYN_SENT     โ†’ the connecting                         โ”‚
โ”‚    ESTABLISHED  โ†’ the connected                          โ”‚
โ”‚    FIN_WAIT1    โ†’ the local's closed                      โ”‚
โ”‚    FIN_WAIT2    โ†’ the remote's ACK'd                      โ”‚
โ”‚    TIME_WAIT    โ†’ the 2MSL's wait                         โ”‚
โ”‚    CLOSED       โ†’ the closed                             โ”‚
โ”‚                                                          โ”‚
โ”‚  The TIME_WAIT is the normal's, and the CLOSE_WAIT is    โ”‚
โ”‚  the application's.                                      โ”‚
โ”‚                                                          โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

Visual: The Addresses

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚  0.0.0.0:22                                              โ”‚
โ”‚    The all interfaces.                                   โ”‚
โ”‚    The exposure's.                                       โ”‚
โ”‚                                                          โ”‚
โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค
โ”‚  127.0.0.1:22                                            โ”‚
โ”‚    The loopback only.                                    โ”‚
โ”‚    The local's.                                          โ”‚
โ”‚                                                          โ”‚
โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค
โ”‚  192.168.1.100:22                                        โ”‚
โ”‚    The specific interface.                               โ”‚
โ”‚    The specific's.                                       โ”‚
โ”‚                                                          โ”‚
โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค
โ”‚  [::]:22                                                 โ”‚
โ”‚    The all interfaces (the IPv6).                        โ”‚
โ”‚    The exposure's.                                       โ”‚
โ”‚                                                          โ”‚
โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค
โ”‚  [::1]:22                                                โ”‚
โ”‚    The loopback only (the IPv6).                         โ”‚
โ”‚    The local's.                                          โ”‚
โ”‚                                                          โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

Visual: The Migration

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚  THE LEGACY                                              โ”‚
โ”‚    netstat -tlnp      โ†’ the ss -tlnp                     โ”‚
โ”‚    netstat -tunlp     โ†’ the ss -tunlp                    โ”‚
โ”‚    netstat -r         โ†’ the ip route                     โ”‚
โ”‚    netstat -i         โ†’ the ip -s link                   โ”‚
โ”‚    ifconfig           โ†’ the ip addr                      โ”‚
โ”‚    route              โ†’ the ip route                     โ”‚
โ”‚                                                          โ”‚
โ”‚  THE MODERN                                              โ”‚
โ”‚    The ss is the netstat's replacement, and the ip is    โ”‚
โ”‚    the ifconfig's and the route's.                       โ”‚
โ”‚                                                          โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

Summary

ItemValue
The ssThe modern’s socket’s tool
The netstatThe legacy’s
The -tlnpThe TCP’s listening’s
The -tunlpThe TCP’s and the UDP’s
The -tanpThe all’s
The -sThe summary
The LISTENThe server’s
The ESTABLISHEDThe active’s
The TIME_WAITThe recently’s closed
The CLOSE_WAITThe application’s
The 0.0.0.0The all interfaces
The 127.0.0.1The loopback

Key takeaways:

  • The ss is the modern, and the netstat is the legacy โ€” the ss is faster and is the default on the modern distributions
  • The ss -tlnp shows the TCP’s listening’s sockets with the process โ€” it is the security audit’s first command
  • The -n shows the numbers instead of the names โ€” the reverse’s DNS is the slow, and the -n is the fast
  • The -p shows the process, and it requires the root โ€” the other users’ processes are hidden without the root
  • The LISTEN is the server’s waiting, and the ESTABLISHED is the active’s โ€” the two are the common
  • The TIME_WAIT is the recently’s closed and is the normal โ€” the very high’s count is the ports’ exhaustion’s
  • The CLOSE_WAIT is the application’s waiting โ€” the high’s count is the application’s bug
  • The 0.0.0.0 is the all interfaces, and the 127.0.0.1 is the loopback โ€” the exposure’s choice is the security’s
  • The ss -s is the summary โ€” the Total, the TCP, the UDP are the overview’s
  • The migration from the netstat to the ss is the iproute2‘s โ€” the ss replaces the netstat, and the ip replaces the ifconfig and the route

Remember: The ss and the netstat show the sockets, and the sockets are the connections. The -tlnp is the listening’s audit, and the -tanp is the all’s. The LISTEN and the ESTABLISHED are the common states, and the TIME_WAIT and the CLOSE_WAIT are the diagnostic’s. The 0.0.0.0 is the exposure’s, and the 127.0.0.1 is the safe’s. The ss is the modern, and the netstat is the legacy. The open ports are the security’s, and the security’s is the discipline.


Stop using slow, ad-bloated tool sites! ๐Ÿคฎ

๐Ÿ”Ž Search “KandZ Tools” on Google to use many professional utilities for free.

KandZ.me is the ultimate minimalist hub for:
โœ… Finance (Mortgage, Interest, Inflation)
โœ… Tech (Base64, JSON, Dev Suite, IP)
โœ… Health (BMI, BMR, TDEE)
โœ… Productivity (Timer, Workspace, QR)

โšก๏ธ Fast & Private
๐Ÿ”’ No data leaves your device
๐Ÿ’Ž 100% Free

๐Ÿ”— Use it now: https://tools.kandz.me
๐Ÿ”– Bookmark itโ€”youโ€™ll need it later!