How to Utilize the netstat Tool to Monitor Network Connections on Cloud Servers?

20-02-2024 03:14:18

The netstat tool is a utility for querying current network connections, available for use across Linux, Windows, and MacOS operating systems. It can be executed from the command-line interface by simply running the netstat command.

Common parameters for netstat include:

  • -p: Displays the name and PID number of the application associated with each connection.
  • -l: Lists only the connections that are currently listening.
  • -t: Shows TCP connections.
  • -u: Displays UDP connections.
  • -n: Presents numerical addresses.

For example:

$ netstat -uplnt

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      1491/sshd
tcp6       0      0 :::22                   :::*                    LISTEN      1491/sshd
udp        0      0 127.0.0.1:323           0.0.0.0:*                           655/chronyd
udp        0      0 0.0.0.0:68              0.0.0.0:*                           1312/dhclient
udp6       0      0 ::1:323                 :::*                                655/chronyd

To check if a specific application is running on port 1000, the following command can be used. If a record appears, it indicates that both the application and port configuration are correct.

netstat -nlp | grep 1000