>_ IzzyLab

Hands-on task

This task is step 3 of the course “Networking: first steps”

Which port nginx listens on

easy~5 min

Two web servers run on this server: nginx and a small Python server. Each waits for connections on its own TCP port. Find out which port nginx listens on and write the number to /root/nginx_port.txt — just the number.

What you'll practise:
  • ss -tlnp
  • ports
  • LISTEN

Topic breakdown

One machine can run many network services at once: a website, a database, SSH. So that a connection reaches the right program, each service has a port — a number from 1 to 65535. The address says which machine to go to, the port says which program on it. Common numbers: 22 — SSH, 80 — HTTP, 443 — HTTPS, but a service can listen on any free port.

A program waiting for connections listens on a port — the LISTEN state. ss helps you see these ports:

$ ss -tlnp
State   Recv-Q  Send-Q  Local Address:Port  Peer Address:Port  Process
LISTEN  0       128           0.0.0.0:22         0.0.0.0:*      users:(("sshd",pid=612,fd=3))
LISTEN  0       4096        127.0.0.1:5432       0.0.0.0:*      users:(("postgres",pid=880,fd=6))

The flags: -t — TCP, -l — listening ports only, -n — show numbers, not service names (22, not ssh), -p — show the program. To see the programs of all users you need root rights — and in the sandbox you have them.

In Local Address:Port the address and the port are separated by the last colon. 0.0.0.0 means "on all of the machine's addresses", 127.0.0.1 means "only for connections from this same machine".

What's checked

  1. File /root/nginx_port.txt created
  2. The file holds a single number
  3. It's the nginx port

What it looks like