Home > System Tutorial > LINUX > How to check if a remote port is open

How to check if a remote port is open

WBOY
Release: 2024-01-08 09:05:45
forward
917 people have browsed it

A port is a logical entity that is a communication endpoint with an application or process on the Linux operating system. Before use, it is useful to know which ports are open and services are running on the target machine.

We can easily list the open ports in Linux on the local machine using netstat or several other Linux commands like NMAP.

How to check if a remote port is open

In this guide, we'll show you how to use the simple netcat (nc for short) command to determine if a port on a remote host is accessible/open.

netcat (or nc for short) is a powerful and easy-to-use program that can be used in Linux for anything related to TCP, UDP, or UNIX domain sockets.

# yum install nc                  [在 CentOS/RHEL 中]
# dnf install nc                  [在 Fedora 22+ 中]
$ sudo apt-get install netcat     [在 Debian/Ubuntu 中]
Copy after login

We can use it to: open TCP connections, listen on any TCP and UDP ports, send UDP packets, perform port scans on IPv4 and IPv6.

Using netcat, you can check a single or multiple or a range of open ports as shown below. The following command will help us check if port 22 is open on host 192.168.56.10:

$ nc -zv 192.168.1.15 22
Copy after login

In the above command, these flags are:

  1. -z – Set nc to just scan for listening daemons and not actually send any data to them.
  2. -v – Enable verbose mode

The following command will check if ports 80, 22 and 21 are open on the remote host 192.168.5.10 (we can also use the hostname):

nc -zv 192.168.56.10 80 22 21
Copy after login

You can also specify the range of port scanning:

$ nc -zv 192.168.56.10 20-80
Copy after login

For more examples and usage of the netcat command, read our article below.

  1. Use the netcat command to transfer files between Linux servers
  2. Linux network configuration and troubleshooting debugging commands

That's it. In this article, we explained how to use the netcat command to detect whether a remote host port is reachable/open.


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

source:linuxprobe.com
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