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

How to check if a remote port is open

WBOY
WBOYforward
2024-01-08 09:05:45866browse

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 中]

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

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

You can also specify the range of port scanning:

$ nc -zv 192.168.56.10 20-80

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!

Statement:
This article is reproduced at:linuxprobe.com. If there is any infringement, please contact admin@php.cn delete