Tuesday, October 8, 2024

How to Monitor Socket Interfaces on Linux

The ss command is a powerful tool for investigating network connections and sockets on Linux systems. It offers a versatile set of options to customize its output and provide detailed insights into network activity.

Here's a breakdown of some common ss command usages:

  • Listing All Sockets:

          $ ss
        

    This command displays a comprehensive list of all active socket connections, regardless of their state (established, listening, etc.).

  • Filtering by Socket Type:

    • TCP Sockets: $ ss -t

    • UDP Sockets: $ ss -u

    • RAW Sockets: $ ss -w

    • UNIX Sockets: $ ss -x

  • Listing Listening Sockets:

          $ ss -l
        

    This command lists sockets currently in the listening state, meaning they are awaiting incoming connections.

  • Filtering Listening Sockets by Type:

    • TCP Listening: $ ss -lt

    • UDP Listening: $ ss -lu

    • RAW Listening: $ ss -lw

    • UNIX Listening: $ ss -lx

  • Displaying Summary Statistics:

          $ ss -s
        

    This command provides a summary of statistics for different socket types, such as the total number of connections, listening sockets, and more.

  • Filtering by IP Version:

    • IPv4 Connections: $ ss -4

    • IPv6 Connections: $ ss -6

  • Listing Sockets on a Specific Port:

          $ ss -lt src :80
        

    This command displays all TCP sockets listening on port 80.

  • Identifying SSH Connections:

          $ ss -atp | grep ssh
        

    This command lists all TCP socket connections (including process information) and filters them to show only those related to SSH. This can help identify users connected to your system via SSH.

  • Displaying Process Name for a Specific Port:

          $ sudo ss -tulpn | grep :80
        

    This command, using sudo for elevated privileges, displays the process name associated with a specific port (in this case, port 80). This can be helpful when trying to identify the service running on a particular port.

  • Exploring Documentation:

    • $ man ss

    • $ ss --help

These commands provide a glimpse into the ss command's power. Remember that the full range of options and capabilities is documented in the manual page.

0 comments:

Post a Comment