Scan for Open TCP and UDP Ports with nmap
In this step, you will learn how to use the nmap tool to scan your own system for open network ports. Network ports are the endpoints of communication in an operating system. When a program wants to receive information from the network, it "listens" on a specific port. Scanning for open ports is a fundamental first step in assessing the security of a machine, as each open port represents a potential entry point for an attacker.
First, you need to install nmap, as it is not included in the base environment. It's good practice to update your package list before installing new software.
Run the following command to update the package list:
sudo apt-get update
Now, install nmap by running:
sudo apt-get install -y nmap
You should see output indicating that nmap and its dependencies are being installed.
Next, you need to find your machine's IP address to tell nmap what to scan. You can find this using the ip command.
ip addr show
Look for an entry like eth0 or ens33. Your IP address will be listed next to inet. It will look something like 172.16.50.13/24.
How to identify your IP address from the output:
- Look for the interface that has
state UP (usually eth0)
- Find the line that starts with
inet (not inet6)
- Take only the IP address part before the
/ (e.g., if you see inet 172.16.50.13/24, your IP address is 172.16.50.13)
- Ignore the loopback interface (
lo) with IP 127.0.0.1
For the rest of this lab, we will use <your_IP_address> as a placeholder for your actual IP address.
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
valid_lft forever preferred_lft forever
inet6 ::1/128 scope host
valid_lft forever preferred_lft forever
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP group default qlen 1000
link/ether 00:16:3e:04:c3:1d brd ff:ff:ff:ff:ff:ff
altname enp0s5
altname ens5
inet 172.16.50.13/24 metric 100 brd 172.16.50.255 scope global dynamic eth0
valid_lft 1892159940sec preferred_lft 1892159940sec
inet6 fe80::216:3eff:fe04:c31d/64 scope link
valid_lft forever preferred_lft forever
3: docker0: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc noqueue state DOWN group default
link/ether 02:42:1d:45:49:f8 brd ff:ff:ff:ff:ff:ff
inet 172.17.0.1/16 brd 172.17.255.255 scope global docker0
valid_lft forever preferred_lft forever
Now you are ready to perform your first scan. Let's start by scanning for open TCP (Transmission Control Protocol) ports. TCP is a connection-oriented protocol that is used for many common services like SSH (port 22) and HTTP (port 80). The -sT option in nmap performs a TCP connect scan.
Important: Replace <your_IP_address> with the actual IP you found from the previous step. For example, if your IP is 172.16.50.13, the command would be nmap -sT 172.16.50.13.
Replace <your_IP_address> with the IP you found and run the command:
nmap -sT <your_IP_address>
The output will list the ports that are in the "open" state. Your system will likely have the SSH port (22) open by default, and may have additional services running on other ports.
Starting Nmap 7.80 ( https://nmap.org ) at 2025-07-01 14:08 CST
Nmap scan report for iZrj93qpoj98oqswu96cqfZ (172.16.50.13)
Host is up (0.00013s latency).
Not shown: 997 closed ports
PORT STATE SERVICE
22/tcp open ssh
3000/tcp open ppp
3001/tcp open nessus
Nmap done: 1 IP address (1 host up) scanned in 0.06 seconds
Next, let's scan for UDP (User Datagram Protocol) ports. UDP is a connectionless protocol used for services like DNS (port 53) and DHCP (port 67/68). UDP scans can be slower and less reliable than TCP scans. Using sudo provides better results for UDP scans. The -sU option tells nmap to perform a UDP scan.
Remember: Replace <your_IP_address> with your actual IP address from the previous step.
Replace <your_IP_address> with your IP and run the command:
sudo nmap -sU <your_IP_address>
The output might show ports as open|filtered. This means nmap cannot determine if the port is open or if a firewall is blocking the scan. This is a common result for UDP scans.
Starting Nmap 7.80 ( https://nmap.org ) at 2025-07-01 14:09 CST
Nmap scan report for iZrj93qpoj98oqswu96cqfZ (172.16.50.13)
Host is up (0.0000060s latency).
Not shown: 998 closed ports
PORT STATE SERVICE
68/udp open|filtered dhcpc
5353/udp open|filtered zeroconf
Nmap done: 1 IP address (1 host up) scanned in 1.29 seconds
By completing these scans, you have successfully identified the services listening for network connections on your machine.