nmap
what is open on that hostnmap — network mapper — probes a host’s ports and reports which are open, closed or filtered. Asked to, it also identifies the service and version behind each open port. It is how administrators check what their own machines expose.
Scan your own server from outside: what nmap sees is what an attacker sees.
At the terminal
Read the session first, then the notes: each numbered line in the output is answered by the note with the same number.
What the numbered lines are telling you
The host is up and replied in under a millisecond, so it is on the local network.
997 of the 1000 ports tried were closed: the host replied, but nothing was listening.
Port and protocol, state, the service usually found there, and — because of -sV — the software and version actually answering.
Port 445 is SMB. Fine on a file server inside a network; it should never be reachable from the internet.
Switches
A switch changes how the command behaves. These are the ones used day to day; man nmap lists the rest. Single-letter switches can usually be joined, so -l -a may be written -la.
-sV- Detect the service and version on each open port.
-sn- Host discovery only: no port scan.
-p PORTS- Ports to scan: 22,80 or 1-1000. -p- means all.
-sS- TCP SYN scan, the default as root.
-sU- Scan UDP ports.
-O- Guess the operating system. Needs root.
-A- Aggressive: versions, OS, scripts and traceroute together.
-Pn- Skip the ping and treat the host as up.
-oN FILE- Save the output to a file.
Variations worth knowing
The same tool, pointed at a narrower question. These four cover most of what it is reached for day to day.
nmap -sn 192.168.1.0/24Finds which hosts on a network are up, without scanning ports.
nmap -p 22,80,443 192.168.1.20Scans only the ports named.
nmap -p- 192.168.1.20Scans all 65535 TCP ports.
sudo nmap -sU --top-ports 20 192.168.1.20Scans the twenty most common UDP ports.
In cybersecurity
Scanning is the first step of an attack and the first step of a defence — what differs is permission.
Scanning networks you do not own or have written permission to test can break the law and will trip intrusion detection. Practise on your own machines or a lab.
Scan your servers from outside the firewall and compare with the previous result. A newly open port is either a mistake or an intrusion.
What -sV reads is what an attacker matches against known vulnerabilities. Keep services patched, and close what is not needed.