Use TCP ping on ports with nmap -PS22,80 192.168.1.1
In this step, you will learn how to use Nmap to perform a TCP ping scan on specific ports of a target host. This technique is useful for determining if a host is online and if specific services are running on those ports.
Before we begin, let's clarify what a TCP ping is. Unlike a traditional ICMP ping, a TCP ping sends a TCP SYN packet to a specified port on the target host. If the port is open, the target host will respond with a SYN/ACK packet. If the port is closed, the target host will respond with a RST packet. Nmap uses this behavior to determine if a host is online and if a port is open or closed.
The -PS
option in Nmap is used to perform a TCP SYN ping scan. You can specify one or more ports to scan using a comma-separated list.
Let's try an example. We will use Nmap to perform a TCP ping scan on ports 22 and 80 of the host 192.168.1.1
.
Open your terminal in the LabEx VM. Remember that your default directory is ~/project
. Execute the following command:
nmap -PS22,80 192.168.1.1
This command tells Nmap to send TCP SYN packets to ports 22 and 80 of the host 192.168.1.1
.
You should see output similar to the following:
Starting Nmap 7.80 ( https://nmap.org ) at 2023-10-27 10:00 UTC
Nmap scan report for 192.168.1.1
Host is up (0.0013s latency).
PORT STATE SERVICE
22/tcp open ssh
80/tcp open http
Nmap done: 1 IP address (1 host up) scanned in 0.05s
In this example, Nmap reports that the host 192.168.1.1
is up and that ports 22 (SSH) and 80 (HTTP) are open. If a port was closed, the output would show "closed" instead of "open". If the host was down, Nmap would report "Host is down".
Now, let's consider a scenario where the target host is not reachable or firewalled. In such cases, Nmap might not receive any response, and the output would indicate that the host is down or that the ports are filtered.
nmap -PS22,80 192.168.1.2
If 192.168.1.2
is not reachable, you might see:
Starting Nmap 7.80 ( https://nmap.org ) at 2023-10-27 10:00 UTC
Nmap scan report for 192.168.1.2
Host is down (no responses received).
Nmap done: 1 IP address (0 hosts up) scanned in 5.03s
This indicates that Nmap did not receive any response from the target host, suggesting that it might be down or unreachable due to network issues or firewall rules.