I'm wondering if there's any way to get telnet to send only a \n, not a \r\n.

For example, if one process is listening on a port like this, to print the bytes of any traffic received:

nc -l 1234 |  xxd -c 1 

Connecting to it from netcat with nc localhost 1234, and typing "hi[enter]":

0000000: 68  h
0000001: 69  i
0000002: 0a  .

Connecting to it from telnet with telnet localhost 1234, and typing "hi[enter]"

0000000: 68  h
0000001: 69  i
0000002: 0d  .
0000003: 0a  .

Telnet is sending 0x0d0a instead of 0x0a for the newline. I understand that this is a CRLF as opposed to LF. It also sends the CRLF if I use ^M or ^J.

I thought I had found a solution that directly addresses this problem, by using toggle crlf, but even with this option set, Telnet is always sending the \r\n. I've also tried this on various telnet clients, so I'm guessing I'm misunderstanding what the toggling is supposed to do.

Any way to send just a \n through telnet, with enter or otherwise?


You can negotiate binary mode. Once in this mode you cannot leave it. Negotiation means the telnet client will send a special byte sequence to the server, which you will have to ignore if you are not implementing the protocol.

Subsequent data is sent unchanged, in line mode. Client:

$ telnet localhost 1234
Connected to localhost.
Escape character is '^]'.
telnet> set binary
Negotiating binary mode with remote host.
telnet> quit

and server

$ nc -l 1234 |  xxd -c 1 
00000000: ff  .
00000001: fd  .
00000002: 00  .
00000003: ff  .
00000004: fb  .
00000005: 00  .
00000006: 68  h
00000007: 69  i
00000008: 0a  .

Your telnet client may have an option to start off in binary mode, or you can put an entry in ~/.telnetrc

 set binary

You can apply the binary mode independently in each direction, so you might prefer set outbinary.

| improve this answer | |

Not in telnet, since the applicable RFC specifies carriage-return/line-feed as the line-ending. See Appendix C in RFC 5198.

| improve this answer | |
  • There is another 'applicable RFC' that specifies a binary mode option, when there is no translation. – Marquis of Lorne Dec 17 '16 at 23:18
  • RFC 856 doesn't mention line-endings. – Thomas Dickey Dec 17 '16 at 23:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.