Four Methods for querying whether a port is occupied in Linux

Source: Internet
Author: User

Four Methods for querying whether a port is occupied in 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 COMMAND
22/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 localhost

Starting Nmap 5.51 (http://nmap.org) at CST
Nmap scan report for localhost (127.0.0.1)
Host is up (0.0000020 s latency ).
Other addresses for localhost (not scanned): 127.0.0.1
Not shown: 998 closed ports
PORT STATE SERVICE
22/tcp open ssh
25/tcp open smtp

Nmap done: 1 IP address (1 host up) scanned in 0.06 seconds

Use the Netstat command to view the number of concurrent requests on the Web Server

Detailed status of the netstat command

This article permanently updates link: https://www.bkjia.com/Linux/2018-03/151170.htm

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.