This article will answer the question, what is netstat command? We will demonstrate how to list open ports, show all sockets, find processes by port and port by process, and other examples using netstat utility. The examples in this article are based on Ubuntu, but will work on Redhat as well.
Netstat is a command line utility on Linux that will print network connections and other network related information. To see the full documentation on netstat, run man netstat on the command line.
Install netstat on Ubuntu
To install netstat on Ubuntu, run the following command. The examples in this article assume you have root privileges.
apt install net-tools
If you are using a different Operating System, use the package manager for that OS.
netstat show all sockets
To show all sockets, including those listening and not listening, use the -a command.
netstat -a | more
netstat show process port
To show the port that a known process is running on, use the -ap options.
netstat -ap | grep <process name>
netstat find process by port
Alternatively, if you know the port but not the process, run the following command. Replace the port with the port you are searching for.
netstat -an | grep ':80'
netstat show network interfaces
To list the network interfaces on your computer.
netstat check open ports
To check open ports on your local computer, with netstat installed, run the following command.
netstat -tulpn | grep LISTEN
This command will also show if the socket is open over IPv6.
Here’s a breakdown of the netstat options in the command.
|-t (or –tcp)||Show the TCP connections|
|-u (or –udp)||Show the UDP connections|
|-l (or –listening)||Show only the sockets that are listening|
|-p (or –program)||Show the process id (PID) and the name of the program that owns the socket|
|-n (or –numeric)||Show numerical addresses and do not resolve the name|
Conclusion – What is netstat command
This article has demonstrated how to use netstat to perform various functions in Linux, including checking open ports. Let us know in the comments if you would like to see more example using netstat.
If you found this article useful, please check out more of our content.