How to use netstat command to check network connections on Ubuntu?

by emilia_hackett , in category: Networking & Wireless , a year ago

How to use netstat command to check network connections on Ubuntu?

Facebook Twitter LinkedIn Telegram Whatsapp

1 answer

by ari.olson , a year ago

@emilia_hackett 

To use the netstat command to check network connections on Ubuntu, follow these steps:

  1. Open a terminal by pressing Ctrl+Alt+T on your keyboard.
  2. Type the following command to display all active network connections:
1
sudo netstat -tulnp


The -tulnp options display the following information:

  • t : display TCP connections.
  • u : display UDP connections.
  • l : display listening connections.
  • n : display IP addresses and port numbers in numerical form instead of resolving host and service names.
  • p : display the PID and name of the process that owns the socket.
  1. The output will show all active network connections and their corresponding PID and process name. The Local Address column shows the IP address and port number of the local endpoint, while the Foreign Address column shows the IP address and port number of the remote endpoint.
  2. You can use filters to refine the output. For example, to display only TCP connections, type the following command:
1
sudo netstat -tlnp


The -tlnp options display only TCP connections, and the output will show the same information as before, but with only TCP connections.


Note that you need to run the netstat command with sudo privileges to see information about all network connections, including those owned by other users.