Cyberlium

Networking › Module 4 › Lesson 3

BeginnerModule 4Lesson 3/4

Lab — Port & Connection Check

Use ss and nc to see listeners and test ports locally

25 min+41 XP3 quiz
Module progress3 of 4

Opening

The only ports you probe are the ones you started

ss shows what your kernel is listening on. nc (netcat) can ask "will this TCP port accept a handshake?" python -m http.server can create a temporary door you own. Together they turn yesterday's port list into evidence — on 127.0.0.1. They also turn into unauthorized scanning the moment the target IP is not you. This lab never nmaps the LAN, the school, or the neighbors. If a command's destination is not 127.0.0.1 or localhost, it does not belong in this exercise.

1. ss first: inventory, then interpret three lines

ss -tuln is still the opening move: TCP/UDP, listening, numeric. Before you start extra processes, snapshot what is already there. Name three listeners if you can: port, protocol, bind address, likely service. 127.0.0.53:53 on Ubuntu is often the local stub, not "a public DNS server you should test from the café." *:22 or 0.0.0.0:22 is SSH on all IPv4 NICs. 127.0.0.1:anything is local-only. nc -zv 127.0.0.1 PORT asks your own stack whether that port completes a TCP connect. "succeeded" means a local listener accepted. "Connection refused" means nothing is listening on that address/port — a normal result, not a broken lab. nc -zv against a LAN IP, a classmate, or a printer is out of scope even if the command "just works."

You will then start a tiny HTTP server bound only to 127.0.0.1 on port 8000, curl it, watch it appear in ss, then stop it. Binding 127.0.0.1 is the whole point: a forgotten python http.server on 0.0.0.0:8000 is the 8080 story from the last lesson. When the server is gone, ss should no longer show 8000. Cleanup is part of the lab, not extra credit.

2. Wrong vs right: nmap the floor "because nc felt small"

Worked failure mode — expanding localhost practice into a campus scan. Permission is the first packet.

  • Wrong

    nmap -sS 192.168.1.0/24, nc -zv 192.168.1.1 22, or python -m http.server 8000 with no --bind so it advertises on every NIC at a meetup. You call it "port lab" because the subtitle mentioned nc. Unauthorized scanning is still unauthorized. An unbound lab server is still a LAN door.

  • Right

    ss -tuln. python3 -m http.server 8000 --bind 127.0.0.1. curl -I http://127.0.0.1:8000/. nc -zv 127.0.0.1 8000. Ctrl+C the server. Confirm 8000 is gone. Notes in $HOME/cyberlium-lab/port-check.txt mode 600. Destination addresses stay loopback.

3. Hands-on: snapshot, bind localhost, curl, stop

Use two terminals if you can: one holds the server in the foreground so you remember to kill it; the other runs ss/curl/nc. If python3 is missing, skip the server and still complete ss plus nc -zv 127.0.0.1 on a port that already exists (or a port that refuses). Refused is data. Do not install random "port scanners" to fill the screenshot.

Localhost-only port lab — ss, python HTTP, curl, nc

mkdir -p "$HOME/cyberlium-lab"
NOTES="$HOME/cyberlium-lab/port-check.txt"

# 1) Snapshot YOUR listeners
{
  echo '=== ss -tuln (before) ==='
  ss -tuln
} > "$NOTES"

# 2) Optional: nc against loopback only (refused is OK)
#    Do NOT change 127.0.0.1 to a LAN address.
{
  echo
  echo '=== nc -zv 127.0.0.1 (examples) ==='
  nc -zv 127.0.0.1 22 || true
  nc -zv 127.0.0.1 80 || true
} >> "$NOTES" 2>&1

# 3) Temporary HTTP door bound ONLY to loopback
# Two-terminal version (do NOT paste the next line into a full-script run):
#   python3 -m http.server 8000 --bind 127.0.0.1
# Other terminal while it runs: ss -tuln | grep 8000; curl -I http://127.0.0.1:8000/; nc -zv 127.0.0.1 8000
# Then Ctrl+C the server.

# One-shot version (background, curl, kill) — still 127.0.0.1
python3 -m http.server 8000 --bind 127.0.0.1 >/tmp/cyberlium-http8000.log 2>&1 &
HTTP_PID=$!
sleep 1
{
  echo
  echo '=== ss during python http.server 8000 --bind 127.0.0.1 ==='
  ss -tuln | grep -E '8000|Local' || ss -tuln
  echo
  echo '=== curl -I http://127.0.0.1:8000/ ==='
  curl -I http://127.0.0.1:8000/ || true
  echo
  echo '=== nc -zv 127.0.0.1 8000 ==='
  nc -zv 127.0.0.1 8000 || true
} >> "$NOTES" 2>&1
kill "$HTTP_PID" 2>/dev/null || true
wait "$HTTP_PID" 2>/dev/null || true

{
  echo
  echo '=== ss -tuln (after stop) — 8000 should be gone ==='
  ss -tuln
} >> "$NOTES"
chmod 600 "$NOTES"
cat "$NOTES"

# NEVER: nmap the LAN, school, work, or neighbors
# NEVER: python -m http.server 8000  without --bind 127.0.0.1 on a shared network
# NEVER: nc -zv 192.168.x.x or other people's IPs "for comparison"

Mission: localhost HTTP on 8000, then tear it down

On your own VM or WSL: run ss -tuln and record at least three listeners (or all, if fewer). Start python3 -m http.server 8000 --bind 127.0.0.1, curl -I http://127.0.0.1:8000/, and optionally nc -zv 127.0.0.1 8000. Stop the server and confirm 8000 disappeared from ss. Save evidence in $HOME/cyberlium-lab/port-check.txt. Never nmap other hosts; never bind the lab server to 0.0.0.0.

Stuck? Ask Cyberlium AI Mentor

If python bind fails or nc is missing, ask Cyberlium AI Mentor for a hint — not an nmap substitute. Try: "Hint only: python3 -m http.server 8000 --bind 127.0.0.1 says address already in use — what should I check with ss before picking another high port on localhost?"

You inventoried your own sockets, proved a loopback TCP door with curl/nc, and destroyed the door so it would not follow you to a café. That is the entire ethical port lab. Next — Quiz — Transport & Ports — APPLY TCP vs UDP, the short port list, bind addresses, and this localhost-only discipline, then Topic 3 continues with NAT, Firewalls & Routers.

Knowledge Check

1

APPLY: The lab offers python3 -m http.server 8000 --bind 127.0.0.1 instead of the same server with no bind flag. Why is the flag the security control?

Multiple choice

Knowledge Check

2

APPLY: nc -zv 127.0.0.1 22 says Connection refused; ss has no :22. What failed?

Multiple choice

Knowledge Check

3

APPLY: True or False: nmap of the school /24, nc to a neighbor's IP, or capturing their services is outside this lab even if the goal is "learning ports."

True or False

← Previous

Answer all 3 knowledge checks to continue. (0/3 answered)