Saturday, June 25, 2016

How to close telnet terminal in Linux and Windows (quit, exit not working)

The telnet is one of the most useful networking commands, which is used to check if a server is listening on a particular port on the remote host, but it's a little bit tricky to use, especially, if you are not using it daily. Though I have used telnet before, but when I use it after a long time, I actually forget how to close the telnet terminal and how to get out of it. I tried every possible command I can think of which is used to close, cancel a command, or exit from VIM editor in UNIX, e.g. Ctrl + C, quit, exit, q! and even the escape character '^]', only to realize that nothing is working. I finally managed to come out from telnet command prompt after a bit of struggle, and trial and error but I was surprised how difficult it can be  to use one of the top 10 networking commands in UNIX.

So, not to forget again and to help anyone who stuck in the same situation, I decide to share my thoughts in this post. Let's see the exact command to close the telnet terminal in Linux and Windows 10.  Though, keep referring a good UNIX command book like. this one is also a good idea not to forget important commands like telnet.

How to close telnet terminal in Linux and Windows

Before looking at how to come out of telnet command prompt, let's first look how not paying enough attention and thinking that every command will work same way can confuse you easily. You can see below that I have tried everything I could to come out of telnet windows but nothing worked, but had I paid attention to the telnet message that  "Escape character is '^]'", I would probably be able to come out of telnet terminal earlier.

$ telnet 8080
Connected to (
Escape character is '^]'.


The trick here is you need to first type escape character e.g. '^]' which is 'Ctrl + ]' and then type quit to close the telnet terminal in Linux or any UNIX system.

I expect the same command will work on Windows and Mac also as telnet is ubiquitous and you will find telnet command in a host of the operating system including big three e.g. Linux, Windows, and Mac. See Practical Guide to Linux Commands 3rd Edition by Mark G to learn more about telnet command in UNIX.

How to exit from telnet editor in UNIX and Linux

Here are the exact steps to end a telnet session in Linux and Windows :

1. Open the telnet prompt by holding down the ‘Ctrl’ key and push the ‘]’ key. (prompt: Microsoft Telnet>)
2. Type quit.
3. Push the ‘Enter’ key.

The telnet is extremely useful command and used a lot in client-server application e.g. you can use this to solve connection refused error in Java, which is mostly due to incorrect client-server communication.  In the electronic trading and FIX protocol world, telnet is a great tool to diagnose FIX session connection issues as described in this article.

How to come out of telnet command prompt

You can even use telnet to check if your own HTTP server is running or not as I have discussed when talked about building HTTP server in Java, here.

That's all about how to exit from telnet terminal on Windows or Linux. As I told its one of the must know networking command and available on almost all operating system. When you don't use it regularly sometimes it becomes tricky to operate as shown in this article, but just remember that you need to first type escape character to actually type command in telnet, while it is connected to a server.

Further Learning
Linux Command Line Basics
Linux Command Line Interface (CLI) Fundamentals
Learn Linux in 5 Days and Level Up Your Career

Other Linux command tutorials for Java Programmers
  • 10 example of lsof commands in UNIX (examples)
  • 10 basic networking command in Linux (list)
  • How to send HTTP request from Linux command prompt? (command)
  • 10 examples of chmod command in UNIX (examples)
  • 10 examples of xargs command in UNIX? (examples)
  • 10 UNIX and Linux command based questions from Interviews (list)

No comments :

Post a Comment