Home > Operation and Maintenance > Linux Operation and Maintenance > How to check if a port is open in Linux?

How to check if a port is open in Linux?

青灯夜游
Release: 2019-04-16 09:10:58
Original
59026 people have browsed it

In Linux, we can check whether the port is open by using the lsof command and netstat command on the command line.

How to check if a port is open in Linux?

Method 1: Use the lsof command

We can use the lsof command to check whether a certain port Open, the basic syntax is as follows:

lsof -i:端口号
Copy after login

If there is no output, it means that the port number is not open

The following figure takes port 80 and port 53 as an example to check whether port 80 and port 53 are open

How to check if a port is open in Linux?

You can also use the lsof -i command to directly output the open ports to check whether certain ports are open.

Method 2: Use the netstat command

The netstat command can provide network-related information about the host.

We can use netstat -atu to check open ports in linux

How to check if a port is open in Linux?

Netstat flags we use: -a, -t and -u Introduction

-a: All sockets.

-t: TCP connection of the program

-u: UDP connection of the program

You can also add the -p flag to display the related PID of the process or program name.

How to check if a port is open in Linux?

To display only UDP ports, you can use the following command:

How to check if a port is open in Linux?

To display only TCP ports, you can use the following Command:

How to check if a port is open in Linux?

Related video tutorial recommendation: "Linux Tutorial"

The above is the entire content of this article, I hope it will be helpful to everyone's study. For more exciting content, you can pay attention to the relevant tutorial columns of the PHP Chinese website! ! !

The above is the detailed content of How to check if a port is open in Linux?. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template