软件启动界面:我使用过的Linux命令之telnet

来源:百度文库 编辑:中财网 时间:2024/04/27 07:26:27

我使用过的Linux命令之telnet - 基于TELNET协议的远程登录工具

本文链接:http://codingstandards.iteye.com/blog/835485   (转载请注明出处)

用途说明

  telnet命令通常用来远程登录。telnet程序是基于TELNET协议的远程登录客户端程序,最新的TELNET协议版本是RFC854。Telnet协议是TCP/IP协议族中的一员,是Internet远程登陆服务的标准协议和主要方式。它为用户提供了在本地计算机上完成远程主机工作的能力。在终端使用者的电脑上使用telnet程序,用它连接到服务器。终端使用者可以在telnet程序中输入命令,这些命令会在服务器上运行,就像直接在服务器的控制台上输入一样。可以在本地就能控制服务器。要开始一个 telnet会话,必须输入用户名和密码来登录服务器。Telnet是常用的远程控制Web服务器的方法。

  但是,telnet因为采用明文传送报文,安全性不好,很多Linux服务器都不开放telnet服务,而改用更安全的ssh方式了。但仍然有很多别的系统可能采用了telnet方式来提供远程登录,因此弄清楚telnet客户端的使用方式仍是很有必要的。
  telnet命令还可做别的用途,比如确定远程服务的状态,比如确定远程服务器的某个端口是否能访问。

常用参数

格式:telnet hostname

远程登录到hostname指定的机器,采用默认端口23。

 

格式:telnet hostname port

远程登录到hostname指定的机器,采用端口port。

 

在连接成功之后的使用过程中,还可以使用Ctrl+]来进入命令模式。

help 帮助

q 退出,关闭telnet连接。

 

使用示例

示例一 远程服务器无法访问的情形

[root@new55 ~]# telnet 192.168.6.6
Trying 192.168.6.6...
telnet: connect to address 192.168.6.6: No route to host
telnet: Unable to connect to remote host: No route to host
[root@new55 ~]#

怎么处理这种情况:

(1)确认ip地址是否正确?

(2)确认ip地址对应的主机是否已经开机?

(3)如果主机已经启动,确认路由设置是否设置正确?(使用route命令查看)

(4)如果主机已经启动,确认主机上是否开启了telnet服务?(使用netstat命令查看,TCP的23端口是否有LISTEN状态的行)

(5)如果主机已经启动telnet服务,确认防火墙是否放开了23端口的访问?(使用iptables-save查看)

 

示例二 域名无法解析的情形

[root@new55 ~]# telnet www.11111.com
www.11111.com/telnet: Name or service not known
[root@new55 ~]#

怎么处理这种情况:

(1)确认域名是否正确?

(2)确认本机的域名解析有关的设置是否正确?(/etc/resolv.conf中nameserver的设置是否正确,如果没有,可以使用nameserver 8.8.8.8)

(3)确认防火墙是否放开了UDP53端口的访问?(DNS使用UDP协议,端口53,使用iptables-save查看)

 

示例三 目标主机没有开启telnet服务的情形

[root@new55 ~]# telnet www.163.com
Trying 58.242.249.26...
telnet: connect to address 58.242.249.26: Connection refused
telnet: Unable to connect to remote host: Connection refused
[root@new55 ~]#

怎么处理这种情况:

(1)确认ip地址或者主机名是否正确?

(2)确认端口是否正确,是否默认的23端口?

 

示例四 怎样启动telnet服务?(不推荐开放telnet服务,要使用更安全的ssh服务)

启动telnet服务的步骤:

(1)到 /etc/xinetd.d 下打开 telnet 文件,将其中的 disable = yes 改成 disable = no,保存。

(2)重新启动xinetd服务:service xinetd restart

这样就可以允许非root用户从远程访问了。注意:root账号不允许登录。

 

示例五 正常telnet的情形

一般情况下不允许root从远程登录,可以先用普通账号登录,然后再用su -切到root用户。

[root@new55 ~]# telnet 192.168.6.115
Trying 192.168.6.115...
Connected to 192.168.6.115 (192.168.6.115).
Escape character is '^]'.
Red Hat Linux release 7.3 (Valhalla)
Kernel 2.4.18-3 on an i686
login: root
Password:
Login incorrect

login: root
Password:
Login incorrect

login: web
Password:
[web@localhost web]$
[web@localhost web]$

[web@localhost web]$ su -
Password:
[root@localhost root]#
[root@localhost root]#
[root@localhost root]#
[root@localhost root]# exit
logout

[web@localhost web]$

[web@localhost web]$
[web@localhost web]$ exit
logout

Connection closed by foreign host.
[root@new55 ~]#

 

示例六 使用telnet来测试web服务器

[root@new55 ~]# telnet www.163.com 80
Trying 58.242.249.26...
Connected to www.163.com (58.242.249.26).
Escape character is '^]'.
GET / HTTP/1.0

HTTP/1.0 403 Forbidden
Server: Cdn Cache Server V2.0
Date: Tue, 07 Dec 2010 04:46:12 GMT
Content-Type: text/html
Content-Length: 1156
Expires: Tue, 07 Dec 2010 04:46:12 GMT
X-Via: 1.0 hf44:8104 (Cdn Cache Server V2.0)
Connection: close




错误:您所请求的网址(URL)无法获取


错误


您所请求的网址(URL)无法获取





当尝试读取以下网址(URL)时:
http://58.242.249.44/


发生了下列的错误:




  • Access Denied.

    拒绝访问


    Access control configuration prevents your request from
    being allowed at this time.  Please contact your service provider if
    you feel this is incorrect.


    当前的存取控制设定禁止您的请求被接受,
    如果您觉得这是错误的,请与您网路服务的提供者联系。



本缓存服务器管理员:cdnsupport@chinanetcenter.com







Generated Tue, 07 Dec 2010 04:46:12 GMT by cache.51cdn.com (Cdn Cache Server V2.0)


Connection closed by foreign host.
[root@new55 ~]# telnet www.163.com 80
Trying 58.242.249.26...
Connected to www.163.com (58.242.249.26).
Escape character is '^]'.
GET / HTTP/1.0

Host: www.163.com

 

这里会输出响应头和首页html文本,省略。

[root@new55 ~]#

 

示例七 进入telnet命令模式

[root@new55 ~]# telnet 192.168.6.115
Trying 192.168.6.115...
Connected to 192.168.6.115 (192.168.6.115).
Escape character is '^]'.
Red Hat Linux release 7.3 (Valhalla)
Kernel 2.4.18-3 on an i686
login: web
Password:
Last login: Tue Oct 19 21:53:15 from 192.168.6.55
[web@localhost web]$
[web@localhost web]$
[web@localhost web]$
[web@localhost web]$ Ctrl+]
telnet> help
Commands may be abbreviated.  Commands are:

close           close current connection
logout          forcibly logout remote user and close the connection
display         display operating parameters
mode            try to enter line or character mode ('mode ?' for more)
open            connect to a site
quit            exit telnet
send            transmit special characters ('send ?' for more)
set             set operating parameters ('set ?' for more)
unset           unset operating parameters ('unset ?' for more)
status          print status information
toggle          toggle operating parameters ('toggle ?' for more)
slc             change state of special charaters ('slc ?' for more)
auth            turn on (off) authentication ('auth ?' for more)
encrypt         turn on (off) encryption ('encrypt ?' for more)
forward         turn on (off) credential forwarding ('forward ?' for more)
z               suspend telnet
!               invoke a subshell
environ         change environment variables ('environ ?' for more)
               print help information
telnet> display
will flush output when sending interrupt characters.
won't send interrupt characters in urgent mode.
won't send login name and/or authentication information.
won't skip reading of ~/.telnetrc file.
won't map carriage return on output.
will recognize certain control characters.
won't turn on socket level debugging.
won't print hexadecimal representation of network traffic.
won't print user readable output for "netdata".
won't show option processing.
won't print hexadecimal representation of terminal traffic.

echo            [^E]
escape          [^]]
rlogin          [off]
tracefile       "(standard output)"
flushoutput     [^O]
interrupt       [^C]
quit            [^\]
eof             [^D]
erase           [^?]
kill            [^U]
lnext           [^V]
susp            [^Z]
reprint         [^R]
worderase       [^W]
start           [^Q]
stop            [^S]
forw1           [off]
forw2           [off]
ayt             [^T]
     DO   ECHO
resp WILL_WONT ECHO: 1
want WONT ECHO
     DO   SUPPRESS GO AHEAD
     DO   STATUS
     WILL TERMINAL TYPE
     WILL NAWS
     WILL TSPEED
     WILL LFLOW
resp WILL_WONT XDISPLOC: 1
want WONT XDISPLOC
     WILL NEW-ENVIRON

[web@localhost web]$
[web@localhost web]$
[web@localhost web]$ Ctrl+]
telnet> q
Connection closed.
[root@new55 ~]#

 

问题思考

相关资料

【1】百度百科    Telnet   
【2】维基百科    Telnet英文词条    Telnet中文词条   
【3】RFC854    Telnet Protocol Specification

【4】鸟哥的Linux私房菜  Telnet 伺服器