Scan specific ports with nmap -sS -sU -p 22,53 127.0.0.1
In the previous step, you performed a combined TCP and UDP scan on a target host. Now, you will learn how to scan specific ports using Nmap. This is useful when you want to focus your scan on particular services or vulnerabilities.
The -p
option in Nmap allows you to specify the ports you want to scan. You can specify a single port, a range of ports, or a comma-separated list of ports.
In this step, you will scan ports 22 (SSH) and 53 (DNS) on the localhost (127.0.0.1).
Open your Xfce terminal and enter the following command:
sudo nmap -sS -sU -p 22,53 127.0.0.1
Again, you will be prompted for your password. Since the labex
user has sudo
privileges without a password, just press Enter
.
This command tells Nmap to perform a TCP SYN scan and a UDP scan on ports 22 and 53 of the localhost.
Example output (the actual output may vary):
Starting Nmap 7.80 ( https://nmap.org ) at 2023-10-27 10:05 UTC
Nmap scan report for localhost (127.0.0.1)
Host is up (0.000027s latency).
PORT STATE SERVICE
22/tcp open ssh
Nmap scan report for localhost (127.0.0.1)
Host is up (0.000027s latency).
PORT STATE SERVICE
53/udp open|filtered domain
Nmap done: 1 IP address (1 host up) scanned in 1.50 seconds
In this example, Nmap found TCP port 22 (SSH) open and UDP port 53 (DNS) open or filtered. The open|filtered
state means that Nmap couldn't determine whether the port is open or filtered due to network conditions or firewall rules. Since we are scanning localhost, it is likely that the service is running, but a firewall might be interfering with the scan.
By specifying the ports to scan, you can significantly reduce the scan time and focus on the services you are interested in.