Ports and connections
telnet
Opens a TCP connection to a port and says plainly whether it worked: the classic port check.
telnet HOST PORT opens a TCP connection and lets you type into it. Once a remote login, today it is the
quickest way to ask "does anything answer on this port?": it prints Connected to when the port accepts,
Connection refused at once when the machine is reached but nothing listens (or a rule rejects), and it hangs when
a firewall drops the packets. Its old use, logging in over the network in the clear, is replaced by SSH.
telnet command usage
telnet HOST PORT
telnet examples
-
telnet 10.0.2.10 80 - Checks whether port 80 on 10.0.2.10 accepts a TCP connection; Ctrl-] then quit leaves it.
-
telnet 10.0.2.10 9 - Tries a port with nothing on it: refused at once.
telnet: can't connect to remote host (10.0.2.10): Connection refused
-
telnet mail.corp.lab 25 - Connects to a mail server and shows its greeting; SMTP can then be typed by hand.
Reading the output
$ telnet 10.0.2.10 8080 telnet: can't connect to remote host (10.0.2.10): Connection refused
Connection refused, instantly: the machine answered the SYN with a reset. Nothing listens on that address and port.- A hang instead means the packets are dropped on the way: a firewall, or a machine that is down.
Pitfalls
- It only speaks TCP: a UDP port cannot be checked this way.
- Never log in with it: the password crosses the network in the clear.