0
0
Linux CLIscripting~10 mins

netstat and ss (connection listing) in Linux CLI - Step-by-Step Execution

Choose your learning style9 modes available
Concept Flow - netstat and ss (connection listing)
Start command: netstat or ss
Read system network info
Filter connections based on options
Format output as table
Display connection list to user
End
The command reads network info, filters connections, formats, and shows them.
Execution Sample
Linux CLI
ss -tuln
netstat -tuln
List all TCP and UDP listening connections without resolving names.
Execution Table
StepCommand RunActionOutput ExampleNotes
1ss -tulnReads TCP/UDP listening socketsNetid State Recv-Q Send-Q Local Address:Port Peer Address:PortShows raw socket info without DNS lookup
2ss -tulnFilters only listening socketstcp LISTEN 0 128 0.0.0.0:22 0.0.0.0:*Shows SSH listening on port 22
3ss -tulnFormats output as tableudp UNCONN 0 0 127.0.0.53%lo:53 0.0.0.0:*Shows DNS service listening on localhost
4netstat -tulnReads TCP/UDP listening socketsProto Recv-Q Send-Q Local Address Foreign Address StateOlder tool, similar output
5netstat -tulnFilters listening socketstcp 0 0 0.0.0.0:80 0.0.0.0:* LISTENShows web server listening on port 80
6netstat -tulnFormats outputudp 0 0 0.0.0.0:123 0.0.0.0:*Shows NTP service listening
7EndDisplay complete listFull list of active listening connectionsUser sees all open ports and protocols
💡 All listening connections displayed; command ends.
Variable Tracker
VariableStartAfter 1After 2After 3Final
Commandnoness -tulnss -tulnnetstat -tulnnetstat -tuln
Connections Listemptyraw socket infofiltered listening socketsraw socket infofiltered listening sockets
Output Formatnonetable formattable formattable formattable format
Key Moments - 3 Insights
Why do ss and netstat show different column names but similar info?
Both read network info but format output differently; see execution_table rows 1-3 vs 4-6.
Why use -n option in these commands?
-n avoids resolving IPs to names, making output faster and clearer; shown in all rows.
What does the 'LISTEN' or 'UNCONN' state mean in output?
'LISTEN' means socket waits for connections; 'UNCONN' means UDP socket not connected; see rows 2 and 3.
Visual Quiz - 3 Questions
Test your understanding
Look at the execution_table row 2, what does the 'tcp LISTEN 0 128 0.0.0.0:22' line represent?
AA UDP socket sending data on port 22
BA TCP socket listening on port 22 for any IP
CA closed TCP connection on port 22
DA TCP socket connected to port 22
💡 Hint
Check the 'State' column and 'Local Address:Port' in row 2.
At which step does netstat filter only listening sockets?
AStep 1
BStep 4
CStep 5
DStep 7
💡 Hint
Look for 'Filters listening sockets' action in execution_table.
If you remove the -n option, how would the output change?
AIP addresses would be replaced by hostnames
BOutput would show more connections
COutput would be empty
DOutput would show only UDP connections
💡 Hint
The -n option disables name resolution; see key_moments about -n.
Concept Snapshot
netstat and ss list network connections
Use -tuln to show TCP/UDP listening sockets without names
ss is newer and faster; netstat is older
-n disables name resolution for speed
Output shows protocol, state, local address, and port
Useful to check open ports and services
Full Transcript
This visual guide shows how the Linux commands netstat and ss list network connections. Both commands read system network info, filter for listening TCP and UDP sockets, format the output as a table, and display it. The example commands 'ss -tuln' and 'netstat -tuln' show all listening TCP and UDP ports without resolving IP addresses to names. The execution table traces each step: reading sockets, filtering listening ones, formatting output, and displaying it. Variables track the command used, the connections list state, and output format. Key moments clarify why outputs differ, the purpose of the -n option, and meaning of socket states like LISTEN and UNCONN. The quiz tests understanding of output lines, filtering steps, and effects of options. The snapshot summarizes usage and options for quick reference.