In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly introduces "how to view the port number of the service in Linux". In the daily operation, I believe that many people have doubts about how to view the port number of the service in Linux. The editor consulted all kinds of materials and sorted out a simple and easy-to-use operation method. I hope it will be helpful to answer the doubt of "how to view the port number of the service in Linux"! Next, please follow the editor to study!
Method 1: use the grep command
To find the default port number for the specified service in Linux using the grep command, simply run:
$grep / etc/services
For example, to find the default port for the SSH service, simply run:
$grep ssh / etc/services
It's that simple. This command should apply to most Linux distributions. The following is a sample output from my Arch Linux test machine:
Ssh 22/tcpssh 22/udpssh 22/sctpsshell 614/tcpsshell 614/udpnetconf-ssh 830/tcpnetconf-ssh 830/udpsdo-ssh 3897/tcpsdo-ssh 3897/udpnetconf-ch-ssh 4334/tcpsnmpssh 5161/tcpsnmpssh-trap 5162/tcptl1-ssh 6252/tcptl1-ssh 6252/udpssh-mgmt 17235/tcpssh-mgmt 17235/udp
As you can see in the output above, the default port number for the SSH service is 22.
Let's find the port number of the Apache Web server. To do this, the command is:
$grep http / etc/services# http://www.iana.org/assignments/port-numbershttp 80/tcp www www-http # WorldWideWeb HTTPhttp 80/udp www www-http # HyperText Transfer Protocolhttp 80/sctp # HyperText Transfer Protocolhttps 443/tcp # http protocol over TLS/SSLhttps 443/udp # http protocol over TLS/SSLhttps 443/sctp # http protocol over TLS/SSLgss-http 488/tcpgss-http 488/udpwebcache 8080/tcp http-alt # WWW caching servicewebcache 8080/udp http-alt # WWW caching service [...]
What is the FTP port number? There's nothing to it!
$grep ftp / etc/servicesftp-data 20/tcpftp-data 20/udp# 21 is registered to ftp, but also used by fspftp 21/tcpftp 21/udp fsp fspdtftp 69/tcp [...] Method 2: use the getent command
As you can see, the above command displays all port names and numbers for the specified search words "ssh", "http" and "ftp". This means that you will get a fairly long output of all port names that match a given search term.
However, you can use the getent command to output the exact result, as shown below:
$whatportis ssh$ whatportis ftp$ whatportis http
If you don't know the port name, but you do know the port number, you just need to replace the port name with a number:
$getent services 80http 80/tcp
To display all port names and port numbers, simply run:
$getent services method 3: use the Whatportis program
Whatportis is a simple Python script to find the port name and port number. Unlike the above command, this program is output in beautiful tabular form.
Make sure that the pip package manager is installed. If not, please refer to the link below.
How to use pip to manage Python packages
After installing pip, run the following command to install the Whatportis program.
$pip install whatportis
Now you can find the port associated with the service, as shown below.
$whatportis ssh$ whatportis ftp$ whatportis http
Sample output from my CentOS 7 server:
Look up the port number of the service in Linux
If you don't know the exact name of the service, use the-like flag to display the results.
$whatportis mysql-like
The above command helps you find the port associated with the service. You can also find services associated with the port number, as shown below.
$whatportis 993
You can even display the results in JSON format.
Whatportis 993-json at this point, the study on "how to view the port number of a service in Linux" is over. I hope I can solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.