Linux命令telnet – 基於TELNET協議的遠程登入

來源:互聯網
上載者:User
文章目錄
  • 樣本一 遠程伺服器無法訪問的情形
  • 樣本二 網域名稱無法解析的情形
  • 樣本三 目標主機沒有開啟telnet服務的情形
  • 樣本四 怎樣啟動telnet服務?(不推薦開放telnet服務,要使用更安全的ssh服務)
  • 樣本五 正常telnet的情形
  • 樣本六 使用telnet來測試web伺服器
  • 樣本七 進入telnet命令模式
用途說明

  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

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<HTML><HEAD>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=gb2312">
<TITLE>錯誤:您所請求的網址(URL)無法擷取</TITLE>
<STYLE type="text/css"><!--BODY{background-color:#ffffff;font-family:verdana,sans-serif}PRE{font-family:sans-serif}--></STYLE>
</HEAD><BODY>
<H1>錯誤</H1>
<H2>您所請求的網址(URL)無法擷取</H2>
<HR noshade size="1px">
<P>
當嘗試讀取以下網址(URL)時:
<A HREF="http://58.242.249.44/">http://58.242.249.44/</A>
<P>
發生了下列的錯誤:
<UL>
<LI>
<STRONG>
Access Denied.
<BR>拒絕訪問
</STRONG>
<P>
Access control configuration prevents your request from
being allowed at this time.  Please contact your service provider if
you feel this is incorrect.
<BR>
當前的存取控制設定禁止您的請求被接受,
如果您覺得這是錯誤的,請與您網路服務的提供者聯絡。
</UL>
</P>
<P>本快取服務器管理員:<A HREF="mailto:cdnsupport@chinanetcenter.com">cdnsupport@chinanetcenter.com</A>

<BR clear="all">
<HR noshade size="1px">
<ADDRESS>
Generated Tue, 07 Dec 2010 04:46:12 GMT by cache.51cdn.com (Cdn Cache Server V2.0)
</ADDRESS>
</BODY></HTML>
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 ~]#

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.