• Skip to main content
  • Skip to primary sidebar
  • Home
  • WordPress
  • web Hosting
  • linux
  • mysql
  • nginx
  • apache2
  • devops

Raju Ginni

wordpress tutorials seo hosting etc

You are here: Home / Linux sysadmin tutorials linux system administrator / Netstat & SS Commands cheat sheet with examples Interview Questions

Netstat & SS Commands cheat sheet with examples Interview Questions

top 20 Netstat and SS commands, along with their use cases:  netstat deprectated use ss.

Netstat Command SS Command Use Case
netstat -a ss -a Show all active connections (TCP/UDP) and listening ports.
netstat -at ss -t Show all active TCP connections.
netstat -au ss -u Show all active UDP connections.
netstat -l ss -l Show only listening ports.
netstat -lt ss -lt Show only listening TCP ports.
netstat -lu ss -lu Show only listening UDP ports.
netstat -n ss -n Display numeric IP addresses instead of resolving hostnames.
netstat -anp ss -tanp Show all active connections with process ID (PID).
netstat -i ip -s link Display network interface statistics (packets sent/received).
netstat -r ip route show Display the routing table (similar to route -n).
netstat -s ss -s Show network traffic statistics for all protocols.
netstat -c watch ss -s Continuously update and display network statistics.
netstat -tp ss -tp Show TCP connections with associated process names.
netstat -g ip maddr show Display multicast group memberships.
netstat -M ss -M Show NAT masqueraded connections.
netstat --tcp ss --tcp Show only TCP socket connections.
netstat --udp ss --udp Show only UDP socket connections.
netstat -o ss -o state established Show TCP connection timers.
netstat -p ss -p Display programs (PIDs) associated with connections.
netstat -g ss -g Display group memberships for sockets.

Table of Contents

Toggle
    • Netstat Commands (Deprecated in Favor of SS)
    • ⚡ SS (Socket Statistics) – A Faster Alternative to Netstat
  • Netstat & SS Commands with Examples Cheat Sheet
    • 🌐 Netstat Commands (Deprecated but Still Useful)
      • 1️⃣ Show All Active Connections
      • 2️⃣ Show Active TCP Connections
      • 3️⃣ Show Active UDP Connections
      • 4️⃣ Show Only Listening Ports
      • 5️⃣ Show Only Listening TCP Ports
      • 6️⃣ Show Only Listening UDP Ports
      • 7️⃣ Show Numeric Addresses Instead of DNS Names
      • 8️⃣ Show Active Connections with Process ID (PID)
      • 9️⃣ Show Network Interface Statistics
      • 🔟 Display the Routing Table
      • 1️⃣1️⃣ Show Network Statistics for All Protocols
      • 1️⃣2️⃣ Continuously Print Network Statistics
    • ⚡ SS (Socket Statistics) – Faster Alternative to Netstat
      • 1️⃣3️⃣ Show All Listening TCP & UDP Ports
      • 1️⃣4️⃣ Show All Active TCP Connections
      • 1️⃣5️⃣ Show All Active UDP Connections
      • 1️⃣6️⃣ Show Summary of All Network Connections
      • 1️⃣7️⃣ Show TCP Connections with Process Names
      • 1️⃣8️⃣ Show Only Established Connections
      • 1️⃣9️⃣ Show Established Connections with Timer Details
      • 2️⃣0️⃣ Show Listening UNIX Sockets
    • ss command Common options
    • Netstat & SS Command – Interview Questions and Answers
      • 1️⃣ What is the purpose of the netstat command?
      • 2️⃣ Why is ss preferred over netstat?
      • 3️⃣ How do you list all listening TCP and UDP ports?
      • 4️⃣ How do you check which process (PID) is using a specific port?
      • 5️⃣ How do you view all active TCP connections?
      • 6️⃣ How do you find all UDP connections?
      • 7️⃣ How do you check the routing table using Netstat?
      • 8️⃣ How do you display network statistics for all protocols?
      • 9️⃣ How do you continuously monitor network connections?
      • 🔟 What command shows connections in an “ESTABLISHED” state?
      • 1️⃣1️⃣ How do you check which user owns a network connection?
      • 1️⃣2️⃣ How do you find which ports are commonly used?
      • 1️⃣3️⃣ How do you find if a specific port (e.g., 443) is in use?
      • 1️⃣4️⃣ How do you list UNIX domain socket connections?
      • 1️⃣5️⃣ How do you identify orphaned sockets?
      • 1️⃣6️⃣ How do you check firewall-related network activity?
      • 1️⃣7️⃣ What is the difference between netstat -g and ss -g?
      • 1️⃣8️⃣ How do you check if a specific remote IP is connected?
      • 1️⃣9️⃣ How do you save the output of Netstat/SS for analysis?
      • 2️⃣0️⃣ How do you monitor real-time connections?

Netstat Commands (Deprecated in Favor of SS)

Netstat (Network Statistics) is a command-line tool for monitoring network connections, routing tables, and interface statistics.

Command Description
netstat -a Show all active connections and listening ports.
netstat -at Show all active TCP connections.
netstat -au Show all active UDP connections.
netstat -l Show only listening ports.
netstat -lt Show only listening TCP ports.
netstat -lu Show only listening UDP ports.
netstat -n Display addresses and ports in numeric format.
netstat -anp Show all active connections with PID and process name.
netstat -i Show network interface statistics.
netstat -r Display the routing table.
netstat -s Show network statistics for all protocols.
netstat -c Continuously print network statistics.

⚡ SS (Socket Statistics) – A Faster Alternative to Netstat

ss is a modern replacement for netstat, providing faster and more detailed socket statistics.

Command Description
ss -tuln Show all listening TCP & UDP ports in numeric format.
ss -tan Show all active TCP connections.
ss -uan Show all active UDP connections.
ss -s Display a summary of all network connections.
ss -tp Show TCP connections with process names.
ss -n state established Show only established connections.
ss -o state established Show established connections with timer details.
ss -lt Show listening TCP ports.
ss -lu Show listening UDP ports.
ss -lx Show listening UNIX sockets.

Netstat & SS Commands with Examples Cheat Sheet

This guide covers the top Netstat and SS (Socket Statistics) commands with practical examples. Netstat is now largely replaced by SS due to its speed and efficiency.


🌐 Netstat Commands (Deprecated but Still Useful)

Netstat (Network Statistics) is used to display network connections, routing tables, interface statistics, masquerade connections, and multicast memberships.

1️⃣ Show All Active Connections

bash
netstat -a

📌 Example Output:
Lists all active connections and listening ports.

2️⃣ Show Active TCP Connections

bash
netstat -at

📌 Example Output:
Displays all TCP connections.

3️⃣ Show Active UDP Connections

bash
netstat -au

📌 Example Output:
Displays all UDP connections.

4️⃣ Show Only Listening Ports

bash
netstat -l

📌 Example Output:
Shows ports that are actively listening for incoming connections.

5️⃣ Show Only Listening TCP Ports

bash
netstat -lt

📌 Example Output:
Lists only TCP ports that are in the listening state.

6️⃣ Show Only Listening UDP Ports

bash
netstat -lu

📌 Example Output:
Lists only UDP ports that are in the listening state.

7️⃣ Show Numeric Addresses Instead of DNS Names

bash
netstat -n

📌 Example Output:
Displays IP addresses and port numbers without resolving domain names.

8️⃣ Show Active Connections with Process ID (PID)

bash
netstat -anp

📌 Example Output:
Lists all active connections with process ID and process name.

9️⃣ Show Network Interface Statistics

bash
netstat -i

📌 Example Output:
Displays network interface statistics such as sent/received packets.

🔟 Display the Routing Table

bash
netstat -r

📌 Example Output:
Shows the kernel routing table (same as route -n).

1️⃣1️⃣ Show Network Statistics for All Protocols

bash
netstat -s

📌 Example Output:
Summarizes network traffic and errors for all protocols.

1️⃣2️⃣ Continuously Print Network Statistics

bash
netstat -c

📌 Example Output:
Keeps updating network statistics in real-time.


⚡ SS (Socket Statistics) – Faster Alternative to Netstat

The ss command is a modern replacement for netstat, offering faster performance and more details.

1️⃣3️⃣ Show All Listening TCP & UDP Ports

bash
ss -tuln

📌 Example Output:
Lists all listening TCP and UDP ports.

1️⃣4️⃣ Show All Active TCP Connections

bash
ss -tan

📌 Example Output:
Displays active TCP connections without resolving hostnames.

1️⃣5️⃣ Show All Active UDP Connections

bash
ss -uan

📌 Example Output:
Displays active UDP connections.

1️⃣6️⃣ Show Summary of All Network Connections

bash
ss -s

📌 Example Output:
Provides a summary of all active connections.

1️⃣7️⃣ Show TCP Connections with Process Names

bash
ss -tp

📌 Example Output:
Lists TCP connections along with process names and PIDs.

1️⃣8️⃣ Show Only Established Connections

bash
ss -n state established

📌 Example Output:
Displays only established connections.

1️⃣9️⃣ Show Established Connections with Timer Details

bash
ss -o state established

📌 Example Output:
Shows TCP timer details for established connections.

2️⃣0️⃣ Show Listening UNIX Sockets

bash
ss -lx

📌 Example Output:
Lists listening UNIX domain sockets.

ss command Common options

Long option Short option Related action
–all -a Show both listening and non-listening sockets
–events -E Show sockets that are destroyed (closed connections)
–info -i Internal TCP information
–ipv4 -4 Only IPv4 sockets displayed
–ipv6 -6 Only IPv6 sockets displayed
–listening -l Only show listening sockets
–no-header -H Do not show the header, great for one-liners and parsing the output
–numeric -n Numeric output, conversion of names (services, ports) is skipped
–processes -p Show related process that interacts with the socket
–resolve -r Try resolving numeric values for addresses and ports
–summary -s Display a summary with statistics at the top
–tcp -t Show TCP sockets
–udp -u Show UDP sockets

Netstat & SS Command – Interview Questions and Answers

Here are some commonly asked interview questions on Netstat and SS (Socket Statistics), along with their detailed answers.


1️⃣ What is the purpose of the netstat command?

✅ Answer:
netstat (Network Statistics) is a command-line tool used to display network connections, routing tables, interface statistics, and listening ports. It helps in diagnosing network-related issues and monitoring traffic.

Example:

bash
netstat -an

🔹 Use case: Show all active network connections with numeric IP addresses and ports.


2️⃣ Why is ss preferred over netstat?

✅ Answer:
The ss (Socket Statistics) command is a modern replacement for netstat. It provides faster and more detailed information about socket connections because it directly reads from kernel space instead of /proc.

Example Comparison:

bash
netstat -an | grep ESTABLISHED
ss -tan | grep ESTABLISHED

🔹 ss is faster and shows more detailed socket information.


3️⃣ How do you list all listening TCP and UDP ports?

✅ Answer:
Using netstat:

bash
netstat -tuln

Using ss:

bash
ss -tuln

🔹 Explanation:

  • -t → TCP

  • -u → UDP

  • -l → Listening

  • -n → Numeric format (no DNS resolution)


4️⃣ How do you check which process (PID) is using a specific port?

✅ Answer:
Using netstat:

bash
netstat -tulnp

Using ss:

bash
ss -tulnp

🔹 Use case: Helps identify which process is occupying a network port.


5️⃣ How do you view all active TCP connections?

✅ Answer:
Using netstat:

bash
netstat -at

Using ss:

bash
ss -t

🔹 Use case: Helps in monitoring active network sessions.


6️⃣ How do you find all UDP connections?

✅ Answer:
Using netstat:

bash
netstat -au

Using ss:

bash
ss -u

🔹 Use case: Useful for troubleshooting DNS and VoIP traffic.


7️⃣ How do you check the routing table using Netstat?

✅ Answer:

bash
netstat -r

🔹 Alternative:

bash
ip route show

🔹 Use case: Shows the system’s network routing table.


8️⃣ How do you display network statistics for all protocols?

✅ Answer:
Using netstat:

bash
netstat -s

Using ss:

bash
ss -s

🔹 Use case: Useful for monitoring packet transmission statistics.


9️⃣ How do you continuously monitor network connections?

✅ Answer:
Using netstat:

bash
netstat -c

Using ss:

bash
watch ss -s

🔹 Use case: Keeps an updated view of the network traffic.


🔟 What command shows connections in an “ESTABLISHED” state?

✅ Answer:
Using netstat:

bash
netstat -an | grep ESTABLISHED

Using ss:

bash
ss -tan | grep ESTABLISHED

🔹 Use case: Helps identify active and ongoing connections.


1️⃣1️⃣ How do you check which user owns a network connection?

✅ Answer:
Using netstat:

bash
netstat -p

Using ss:

bash
ss -p

🔹 Use case: Useful for security audits and debugging.


1️⃣2️⃣ How do you find which ports are commonly used?

✅ Answer:
Using netstat:

bash
netstat -tuln

Using ss:

bash
ss -tuln | awk '{print $5}' | cut -d: -f2 | sort -n | uniq -c

🔹 Use case: Helps detect frequently accessed ports.


1️⃣3️⃣ How do you find if a specific port (e.g., 443) is in use?

✅ Answer:
Using netstat:

bash
netstat -an | grep :443

Using ss:

bash
ss -tan | grep :443

🔹 Use case: Helps check whether a service is running on a specific port.


1️⃣4️⃣ How do you list UNIX domain socket connections?

✅ Answer:
Using netstat:

bash
netstat -lx

Using ss:

bash
ss -lx

🔹 Use case: Helps debug UNIX interprocess communication (IPC).


1️⃣5️⃣ How do you identify orphaned sockets?

✅ Answer:
Using netstat:

bash
netstat -o

Using ss:

bash
ss -o state established

🔹 Use case: Useful for detecting idle or abandoned connections.


1️⃣6️⃣ How do you check firewall-related network activity?

✅ Answer:

bash
netstat -g
ss -g

🔹 Use case: Lists multicast group memberships.


1️⃣7️⃣ What is the difference between netstat -g and ss -g?

✅ Answer:
Both commands display multicast group memberships, but ss -g provides more detailed and faster output.


1️⃣8️⃣ How do you check if a specific remote IP is connected?

✅ Answer:
Using netstat:

bash
netstat -an | grep <IP>

Using ss:

bash
ss -tan | grep <IP>

🔹 Use case: Helps identify remote machine connections.


1️⃣9️⃣ How do you save the output of Netstat/SS for analysis?

✅ Answer:

bash
netstat -an > netstat_output.txt
ss -tan > ss_output.txt

🔹 Use case: Helps store network activity logs.


2️⃣0️⃣ How do you monitor real-time connections?

✅ Answer:
Using netstat:

bash
watch -d netstat -an

Using ss:

bash
watch -d ss -tan

🔹 Use case: Provides real-time network monitoring.

Netstat manual  https://man7.org/linux/man-pages/man8/netstat.8.html

ss manual  https://man7.org/linux/man-pages/man8/ss.8.html

netstat and ss command

Primary Sidebar

Linux sysadmin tutorials linux system administrator

  • top 10 apt & apt-get commands (most used) apt vs apt-get
  • If-Else Statements in Shell Scripting
  • linux commands pdf (files & Directories, zip & unzip process, search etc)
  • Find Files with Specific Text on Linux grep find command
  • linux performance tuning inode limit file descriptors tco, kernel etc
  • Variables and Data Types in Shell Scripting
  • Top 10 most used Cat commands with examples (create, view, append files)
  • Ip tables / ufw / firewall d commands for block port ip rate limiting
  • Top 10 zip / tar commands to compress & extract files in linux
  • TOP 10 mv & cp commands in linux to move & copy files in Linux
  • Top 10 GREP Commands in linux to search files directory words strings
  • lsof netstat commands to know listening ports in linux 3 ways
  • Upgrade Ubuntu from 18.04 (19.10) to 20.04 LTS command line or gui server | desktop
  • 3 Ways (SCP, rsync, Sftp) linux server migration between two remote server apache nginx
  • linux system specs commands (CPU, Memory, Disk )speed, type. manufacture
  • linux sysctl command tweaks & hardening
  • linux security limits.conf deciding user limits process limits for nginx server
  • ulimit linux unlimited command unlimto set & know user limits open files file descriptor max user process etc.
  • red hat linux certification cost jobs salary syllabus courses fees
  • ufw firewall commads allow port enable disable ubuntu 20.04
  • ddos attack prevention
  • change ssh port in linux - avoid sshd ddos attacks
  • ping command
  • memcached install ubuntu wordpress
  • check linux version (lsb_release -a) ubuntu debian 32 or 64 bit
  • rsync command linux with examples comparison to scp
  • how to uninstall package in linux ubuntu rpm, yum apt-get
  • increase open file limit linux File descriptor ft nginx , mysql, lemp
  • remove repository ubuntu
  • htop commad memory details virtual vs shard vs resident
  • chown command in Linux with Examples
  • Kill PHP process
  • VIrtual Memory vs RSS Memory vs Shared memory in Linux
  • oom killer fixing it by configuration linux ubuntu
  • Install Lemp nginx mysql php fpm Stack on Debian 11 with repository
  • connect two remote servers linux command line
  • auto start after oom killer Mysql & php fpm nginx etc ubuntu wth systemd or cron job
  • load average Linux 1, 5, 15 min 2,4,8 cores explained
  • Control Structures in Shell Scripting
  • Shell Scripting Roadmap for Beginners to Advanced
  • awk commands with practical examples
  • Shell Scripting Tutorial for Beginners 🚀
  • find Command in Linux with Examples
  • sed Command in Linux with Examples (Beginner to Advanced)
  • Linux Text processing commands in with Examples
  • linux disk management commands
  • fdisk command in linux with examples
  • how to add a new disk in linux
  • Linux mount Command with Examples
  • fstab options with examples
  • Top 50 Shell Scripting Interview Questions and Answers
  • Linux Networking Interview Questions and Answers
  • Linux Networking Commands Cheat Sheet with Examples pdf
  • Netstat & SS Commands cheat sheet with examples Interview Questions
  • Nmap Cheat Sheet – Network Scanning & Security
  • Bash Brackets ([], (), {}, $( ), $(( ))) – Types, Uses & Examples

hi i am raju ginni, primalry i manage wordpress websites on GCP cloud platform as a cloud engineer, and create content on passionate things.
you can follow me on youtbe

© 2025 - All Rights Reserved Disclaimer & Privacy Policy