9.2 Telnet

Telnet is another program that comes installed with every Unix operating system. Ordinarily, it is used to login to remote hosts , but it can also be a valuable tool for network administration. Many networking protocols are designed so that you can participate in the protocol using the telnet program. HTTP (for loading Web pages), IMAP (for retrieving email), and SMTP (for sending email) are a few services that fit into this category. For example, the following will retrieve the root Web page from www.example.com:

 
 Solaris% telnet www.example.com 80    Trying 192.0.34.166...    Connected to www.example.com (192.0.34.166).    Escape character is '^]'.    GET / HTTP/1.0    HTTP/1.1 200 OK    Date: Wed, 26 Feb 2003 13:47:13 GMT    Server: Apache/1.3.27 (Unix)  (Red-Hat/Linux)    Last-Modified: Wed, 08 Jan 2003 23:11:55 GMT    ETag: "3f80f-1b6-3e1cb03b"    Accept-Ranges: bytes    Content-Length: 438    Connection: close    Content-Type: text/html    <HTML>    ... 

The only lines typed by the user are the telnet command and the GET / HTTP/1.0 line, which must be followed by an extra blank line; that is, press enter a second time. The text after that is the response from the server, most of which has been removed here for the sake of brevity.

The 80 on the end of the telnet line informs the program to connect to port 80 on the remote host, which is the port that Web servers listen on. The GET command is the HTTP command for retrieving a Web page; we ask it for the Web page named / and specify the version of HTTP we speak as version 1.0. If you replace the word GET with the word HEAD, the Web server will print only the HTTP headers, leaving off the actual HTML content.

In this example, everything worked as it should. But what kind of problems would telnet have alerted you to? First, it would have told you if it was not possible to contact the service:

 
 Solaris% telnet www.example.com 80    Trying 192.0.34.166...    telnet: Unable to connect to remote host: Connection refused 

This means that www.example.com is on the network, [5] but for some reason, it will not respond to requests on port 80. The most likely reason is that the Web server software is not running. However, you do know that the server is alive on the network because the operating system received our packet destined for port 80 and sent a response indicating that it will not accept connections on that port.

[5] As you can test with ping.

Under different circumstances, telnet might hang waiting for a response instead of coming back immediately with the connection refused message:

 
 Solaris% telnet www.example.com 80    Trying 192.0.34.166... 

Your prompt does not return until you break the process with <ctrl>-C. This means either that www.example.com is not on the network at all or that packets on port 80 are not making it to or from the machine, likely because of a filter or a firewall between you and the server.

If telnet makes it as far as the "Connected to ..." line but stalls after that, the problem is likely on the server. It could, for example, be experiencing an abnormally heavy load. However, this could also be an indication of a network problem such as a path MTU mismatch, so further debugging is required before the blame can be placed immediately on the server.

The telnet program can connect to only text-based TCP services and then only if the service is appropriately line oriented. The exact specifications for many of these protocols are listed in RFCs available from http://www.ietf.org/. HTTP version 1.1 is described in RFC 2068, SMTP is described in RFC 2821, and the base IMAP protocol is described in RFC 1730.



Open Source Network Administration
Linux Kernel in a Nutshell (In a Nutshell (OReilly))
ISBN: 130462101
EAN: 2147483647
Year: 2002
Pages: 85

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net