>_ IzzyLab

Hands-on task

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

Who responds

easy~6 min

A colleague left a list of services in /root/services.txt in the form address:port and asks you to find out which of them are accepting connections right now. Check each one and write the ones that responded to /root/alive.txt — in the same address:port form, one per line, in any order.

What you'll practise:
  • host reachability
  • curl --connect-timeout
  • Connection refused vs timeout

Topic breakdown

Before figuring out why a service doesn't work, you check whether it's reachable at all. On a regular server you'd start with ping address: it sends a small request packet and waits for a reply, which shows whether the machine responds. ping isn't allowed in the sandbox, so here we check reachability another way — by connecting to a port.

A service on a machine waits for connections on its port — the number after the colon in 10.0.0.5:8080. Try to connect, and the answer tells you what's going on:

  • an answer came back — the host is reachable and the service works;
  • Connection refused — the machine is up, but nobody is listening on this port;
  • silence until the timeout — the host doesn't respond: it's off, there's no route to it, or a firewall drops the connections.

For web services curl is handy:

$ curl --connect-timeout 3 http://10.0.0.5:8080/
<h1>It works</h1>
$ curl --connect-timeout 3 http://10.0.0.5:9999/
curl: (7) Failed to connect to 10.0.0.5 port 9999 ... Connection refused
$ curl --connect-timeout 3 http://10.9.9.9:80/
curl: (28) Connection timed out after 3002 milliseconds

--connect-timeout 3 means wait for the connection no longer than three seconds; otherwise a silent host will keep you waiting a minute or more. The sandbox has no internet access, so outside addresses won't respond from here.

What's checked

  1. File /root/alive.txt created
  2. The file holds only services that responded
  3. All the services that responded are there

What it looks like