telnet: Usage, Options & Common CI Errors
telnet opens a plain TCP session - handy as a quick "is this port open?" probe.
telnet predates dedicated port-check tools but is still used to test TCP reachability: "telnet host port" succeeds if the port is open. The CI hazard is that on success it stays connected interactively and hangs the job.
What it does
telnet opens an interactive TCP connection to a host and port. As a diagnostic it answers "can I reach this TCP port?" - a connect means the port is open; "Connection refused" means it is closed; a hang means a firewall is dropping packets. It is not scriptable cleanly, which is why nc -z is preferred in CI.
Common usage
telnet example.com 80 # is port 80 reachable?
telnet 10.0.0.5 5432 # test a Postgres port
# In CI, prefer a non-interactive probe instead:
nc -z -w 3 example.com 80 && echo open
timeout 5 bash -c '</dev/tcp/example.com/80' && echo openOptions
| Usage | What it does |
|---|---|
| telnet <host> <port> | Open a TCP connection to host:port |
| Ctrl-] then quit | Escape to the telnet prompt and exit |
| "Connected to ..." | Port is open and accepting |
| "Connection refused" | Port closed / nothing listening |
| (hang) | Packets dropped by a firewall |
Common errors in CI
On a successful connect telnet stays open waiting for input and hangs a non-interactive job - do NOT use bare telnet in scripts; use nc -z, curl, or a bash /dev/tcp redirect with timeout. "Connection refused" means nothing is listening (service not up). "Unable to connect to remote host: Connection timed out" / a long hang means a firewall is dropping SYNs. "telnet: command not found" - it is often not installed on slim images; the bash </dev/tcp/host/port builtin needs no package.