Menu
Coddy logo textTech

Refused or Timed Out

Lesson 18 of 47 in Coddy's Networking with the Terminal course.

When a connection fails it fails in one of a few specific ways, and each one points somewhere different. curl reports which by its exit code, the number a command leaves behind, readable as $?.

curl -s http://127.0.0.1:9999/
echo $?

Three are worth memorising:

  • 0: success
  • 7: connection refused, the machine answered and said nothing is listening there
  • 28: timed out, nothing answered at all

7 is fast and 28 is slow, and that difference is the diagnosis. Refused means you reached the machine and got a straight no, so the address is right and the service is not running. A timeout means your request vanished, which usually means a firewall dropped it or the address is wrong.

challenge icon

Challenge

Hard

Make both failures happen and read the codes.

  1. Ask http://127.0.0.1:9999/ for a page, with nothing listening there, and print refused= followed by the exit code
  2. Do the same against http://10.255.255.1/, an address that swallows traffic, with --max-time 2, and print timeout= and its exit code

Expected output:

refused=7
timeout=28

$? holds the exit code of the command that just ran, so read it immediately.

Try it yourself

Terminal
quiz iconTest yourself

This lesson includes a short quiz. Start the lesson to answer it and track your progress.

All lessons in Networking with the Terminal

Practice on your own: Terminal playground