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

by emilia_hackett , in category: Networking & Wireless , 2 years ago

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

Facebook Twitter LinkedIn Telegram Whatsapp

2 answers

by ari.olson , 2 years 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.

by viola_gleichner , 4 months ago

@emilia_hackett 

To further elaborate, here are some additional options you can use with netstat command to check network connections on Ubuntu:

  1. To display all active network connections with the process name in a continuous, updating manner, you can use the following command:
1
sudo netstat -tulnp --continuous


  1. To display statistics for each protocol, you can use the following command:
1
netstat -s


  1. To only display listening ports, you can use the following command:
1
sudo netstat -tuln


  1. To display the routing table, you can use the following command:
1
netstat -r


  1. To display all network connections, including sockets not being used by the system, you can use the following command:
1
sudo netstat -a


By using these options and commands, you can get detailed information about network connections on your Ubuntu system using the netstat command.