Linux – How to check which ports are busy and which ports are free on the Linux machine

command linefedoralinuxport

Is there any command line command or any other way to find and list out the busy and free port numbers on my Linux machine?

Best Answer

The command

netstat -antu

will show all tcp and udp ports in use. The output will look something like this:

Proto Recv-Q Send-Q Local Address           Foreign Address         State
tcp        0      0 *               LISTEN

The number after the colon in the Local Address field shows the port in use. If the state is "LISTEN" it means a port that is using for incoming connections. If the IP address in the Local Address field is it means incoming connections will be accepted on any IP address assigned to an interface - so this means from connections originating outside of your machine.

If it said localhost or it would be only accepting connections from your machine.

Additionally, if you add the -p parameter, and run it as root, it will show the process that opened the port:

$ sudo netstat -antup
Active Internet connections (servers and established)
Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name
tcp        0      0 *               LISTEN      860/rpc.statd

Anything not shown as being in use is free, however users (unprivileged accounts) can only open ports above 1023.

Related Question