Four Methods for querying whether a port is occupied in Linux and four methods for linux

Source: Internet
Author: User

Four Methods for querying whether a port is occupied in Linux and four methods for linux

One interview question uses three different methods to check which process occupies 8080. The familiar methods are netstat and lsof, but what else can be done.

1. netstat or ss Command

netstat -anlp | grep 80

2. lsof command

This command is used to view the files occupied by the process.

lsof -i:80

3. fuser command

The fuser command is the opposite of the lsof command to check which process occupies a file. In Linux, everything is a file, so you can view common files, socket files, and file systems. The socket file contains the port number. For example, check port 22.

fuser 22/tcp -v                     USER        PID ACCESS COMMAND22/tcp:              root       1329 F.... sshd                     root       1606 f.... sshd

4. nmap Tool

Nmap always scans ports by default. It is very convenient to scan local ports.

nmap localhostStarting Nmap 5.51 ( http://nmap.org ) at 2018-03-03 18:00 CSTNmap scan report for localhost (127.0.0.1)Host is up (0.0000020s latency).Other addresses for localhost (not scanned): 127.0.0.1Not shown: 998 closed portsPORT   STATE SERVICE22/tcp open  ssh25/tcp open  smtpNmap done: 1 IP address (1 host up) scanned in 0.06 seconds

 

Note: If you think this article is not bad, please click the recommendation in the lower right corner. Your support can stimulate the author's enthusiasm for writing. Thank you very much!

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.