Random Musings

Sporadic thoughts on tech, economics, business, finance and trading

netstat vs ss

,

Below is a side-by-side comparison of the netstat and ss commands, along with an extensive list of examples for each option. Both are used to display network connections, routing tables, interface statistics, etc., but ss is often seen as a faster and more modern alternative to netstat.

Comparison: netstat vs ss

OptionnetstatssDescription
Show all socketsnetstat -ass -aShows all connections (listening, non-listening).
Show listening socketsnetstat -lss -lShow only listening sockets (server-side).
Show numeric addressesnetstat -nss -nShow numeric addresses instead of resolving hostnames.
Show process infonetstat -pss -pShow the process associated with each socket.
Show TCP connectionsnetstat -tss -tShow only TCP connections.
Show UDP connectionsnetstat -uss -uShow only UDP connections.
Show raw connectionsnetstat -wss -wShow raw sockets (UDP, TCP, etc.).
Show route tablenetstat -rss -rDisplay the routing table.
Show interface statisticsnetstat -iss -iDisplay network interface statistics.
Show multicast connectionsnetstat -gss -gShow multicast connections.
Show kernel’s routing tablenetstat -rnss -rnDisplay routing table with numeric addresses.
Show all sockets and processesnetstat -tulnpss -tulnpDisplay TCP/UDP sockets with process info (port, pid, etc.).
Show all sockets with summarynetstat -sss -sShow summary of socket usage, including protocol statistics.
Show the state of socketsnetstat -oss -oShow timer information (socket’s state).
Show extended informationnetstat -ess -eShow detailed info like TCP states.
Show broadcast connectionsnetstat -bss -bDisplay broadcast addresses.

Examples for netstat and ss

1. Show all sockets

  • netstat -a
  • ss -a

2. Show listening sockets

  • netstat -l
  • ss -l

3. Show numeric addresses

  • netstat -n
  • ss -n

4. Show process info

  • netstat -p
  • ss -p

5. Show TCP connections

  • netstat -t
  • ss -t

6. Show UDP connections

  • netstat -u
  • ss -u

7. Show raw connections

  • netstat -w
  • ss -w

8. Show the route table

  • netstat -r
  • ss -r

9. Show interface statistics

  • netstat -i
  • ss -i

10. Show multicast connections

  • netstat -g
  • ss -g

11. Show kernel’s routing table (numeric)

  • netstat -rn
  • ss -rn

12. Show all sockets and processes

  • netstat -tulnp
  • ss -tulnp

13. Show summary of socket usage

  • netstat -s
  • ss -s

14. Show the state of sockets (with timer info)

  • netstat -o
  • ss -o

15. Show extended information (TCP states, etc.)

  • netstat -e
  • ss -e

16. Show broadcast connections

  • netstat -b
  • ss -b

Additional Comparisons

Show Connections for a Specific Address:

  • netstat -a | grep <ip-address>
  • ss -a | grep <ip-address>

Show Specific Port Connections:

  • netstat -tuln | grep 8080
  • ss -tuln | grep 8080

Show UDP Port Usage:

  • netstat -anu
  • ss -u -a

Show All Connections by State:

  • netstat -tuln
  • ss -tuln

Show UDP Ports and Associated Processes:

  • netstat -anu -p
  • ss -u -a -p

Performance and Usage

  • ss is more efficient than netstat, especially when dealing with large numbers of connections. It uses direct kernel access to retrieve information, whereas netstat retrieves data from a higher-level system interface.

Summary of Differences

  • Performance: ss is faster and more efficient than netstat, especially with large numbers of connections.
  • Modernity: ss is the newer tool and part of the iproute2 suite, while netstat is considered legacy.
  • Output: While both tools provide similar information, ss offers a more concise and readable output with fewer columns by default.