How To Find The Port Number Of A Service In Linux

You might often need to find the port names and numbers for some reasons. If so, you’re in luck. Today, in this brief tutorial, we are going to see the easiest and quickest ways to find the port number of a service in Unix-like operating systems. There could be many methods to do it, but I am only aware of the following three methods at present. Read on.

As you can see, the above commands shows all port names and numbers for the given search term “ssh”, “http” and “ftp”. That means, you will get a quite long output of all port names that matches with the given search term.

You can, however, narrow down the result to exact output using “getent” command like below:

$ getent services ssh
ssh 22/tcp

$ getent services http
http 80/tcp www www-http

$ getent services ftp
ftp 21/tcp

If you don’t know the port name but the port number, simply replace the port name with number like below:

And, that’s all for now. You know now how to find the port names and numbers in Linux using three simple methods. If you know any other methods/commands, let me know in the comment section below. I will check and update this guide accordingly.