Refer to Telnet mode

背景

Telnet是常用的远程设备远程登录协议,通过如SecureCRT,Item2等终端软件,可以很容易的登录各种支持Telnet协议的设备,但有时候根据不同的终端设备,会需要一些特殊的设置,这就涉及Telnet协商,此篇文章就是整理下Telnet的几种模式及之间的区别,也包含如何更改这些模式的操作方法;

问题

我们可以通过一个问题来展开讨论,如下环境:

PC---(SSH)---CentOS---(Telnet)---KVM(vNE40E)

我们发现登录vNE40E后无法退格,连续回车会有断行,如下所示:

[root@beihe-terminal-server ~]# CR1
Trying 172.16.211.165...
Connected to 172.16.211.165.
Escape character is '^]'.


<HUAWEI>
<HUAWEI>

<HUAWEI>
<HUAWEI>dis ver^H^H^H^H  <<< 4个退格键

通过“Crtl + ]”退出当前session,然后通过“status”来查看当前Telnet连接的模式,可以看到是 “obsolete linemode”, 过时的Line mode?😂:

<HUAWEI>^]
telnet> status
Connected to 172.16.211.165.
Operating in obsolete linemode
Local character echo
Escape character is '^]'.

那么需要怎么做才能修复此问题呢?

Telnet Mode

在解决问题前,先来看下Telnet的模式分几种,常用的模式主要有如下4种:

  • “Half-duplex” mode(半双工模式)
  • “Character-at-a-time” mode(一次一个字符)
  • “Line-at-a-time” mode(一次一行)

“Half-duplex” mode

半双工模式,一次只能与一个客户端进行通信,现在的设备基本都不用这种模式了,所以不在此过多讨论;

“Character-at-a-time” mode

这个是大部分设备默认的行为,如下CentOS的Telnet客户端与Cisco和Juniper设备进行协商后的默认模式是一样的;这点不同于HuaWei的设备;目前看这种方式比较稳定,每个字符一个交互,需要比较大的带宽资源,对以前的网络可能是个问题,但对于现在的网络,已经不算什么问题,下面有抓包的信息,可以对比看下:

RP/0/0/CPU0:TG22#
telnet> status
Connected to 172.16.211.154.
Operating in single character mode
Catching signals locally
Remote character echo
Escape character is '^]'.
root@PR3:~ # 
telnet> status
Connected to 172.16.211.154.
Operating in single character mode
Catching signals locally
Remote character echo
Escape character is '^]'.

下面把同Cisco交互的信息抓了下来,选中交互报文,右键选择follow tcp stream,就可以看到整个交互的信息,红色是本地,蓝色是回显;大图是Raw格式显示,小图是Hex Dump显示;详细报文可以看这里:

下面是报文信息,与上面信息是对应的:

“Line-at-a-time” mode

本地按照”行“的单位来跟服务器进行交互,如HuaWei的抓包,内容跟上面Cisco的类似,详细报文看这里:

下面是报文信息,与上面信息是对应的,不过每个从服务端到客户端的PSH都跟着一个重传,实在没找到原因,可能跟vNE40E有关:

解决方案

根据上面status的显示,vNE40E的Telnet模式是“obsolete linemode”,尝试用mode改变Line模式,显示的是”LINEMODE“,因此默认协商出来的应该是”old line by line“:

Once a connection has been opened, telnet will attempt to enable the TELNET LINEMODE option. If this fails, telnet will revert to one of two input modes: either ”character at a time” or ”old line by line” depending on what the remote system supports.

https://linux.die.net/man/1/telnet
<HUAWEI>^]
telnet> status
Connected to 172.16.211.165.
Operating in obsolete linemode
Local character echo
Escape character is '^]'.


<HUAWEI>
<HUAWEI>^]
telnet> mode line


<HUAWEI>
<HUAWEI>^]
telnet> status
Connected to 172.16.211.165.
Operating with LINEMODE option
Local line editing
Local catching of signals
Special characters are local values
Local character echo
Escape character is '^]'.


<HUAWEI>
<HUAWEI>

鉴于其他两个厂商均协商”Character-at-a-time“模式,因此需要强行指定此模式,改变方式类似:

<HUAWEI>^]
telnet> mode ?
format is:  'mode Mode', where 'Mode' is one of:

character       Disable LINEMODE option
                (or disable obsolete line-by-line mode)
line            Enable LINEMODE option
                (or enable obsolete line-by-line mode)

                These require the LINEMODE option to be enabled
isig            Enable signal trapping
-isig           Disable signal trapping
edit            Enable character editing
-edit           Disable character editing
softtabs        Enable tab expansion
-softtabs       Disable character editing
litecho         Enable literal character echo
-litecho        Disable literal character echo

?               Print help information
telnet> mode character

<HUAWEI>
<HUAWEI>

但每个session都单独改,实在太麻烦了,是否有更为方便的解决方法?当时是有的,通过更改“.telnetrc”文件即可,关于此文件的语法,可以参考下面网页:

The telnet client looks for the configuration files in /etc/telnetrc and ~/.telnetrc – in this order exactly.

https://anch.dev/en/tools/telnet/telnetrc/
[root@beihe-terminal-server ~]# more .telnetrc 
DEFAULT
   mode character
[root@beihe-terminal-server ~]# CR1
Trying 172.16.211.165...
Connected to 172.16.211.165.
Escape character is '^]'.

<HUAWEI>
<HUAWEI>
<HUAWEI>
telnet> status
Connected to 172.16.211.165.
Operating in single character mode
Catching signals locally
Remote character echo
Escape character is '^]'.

如果使用的是SecureCRT进行Telnet登录,那么可以通过更改下面参数实现同样的效果:

本文出自 Frank's Blog

版权声明:


本文链接:Refer to Telnet mode
版权声明:本文为原创文章,仅代表个人观点,版权归 Frank Zhao 所有,转载时请注明本文出处及文章链接
你可以留言,或者trackback 从你的网站

留言哦

blonde teen swallows load.xxx videos