How to test HTTP using telnet

What you need

What to do

In order to retrieve the document as well as the headers, use GET instead of HEAD.

If you want the root document, use GET / HTTP/1.1 (or HEAD / HTTP/1.1).

The intial client: > symbolizes your shell prompt.

telnet: > telnet www.example.com http
telnet: Trying 192.0.2.2...
telnet: Connected to www.example.com.
telnet: Escape character is '^]'.
client: HEAD /example/example.shtml HTTP/1.1
client: Host: www.example.com
client: Connection: close
client: 
server: HTTP/1.1 200 OK
server: Date: Wed, 21 Jan 2004 22:13:05 GMT
server: Server: Apache/1.3.12-Turbo
server: Connection: close
server: Content-Type: text/html

Related FAQ: How can I host several web sites with different domain names on one server?

This is called virtual hosting. There are two ways to do it (your particular HTTP server software may support neither, one, or both):

Assign a unique IP address to every site

In this scenario, you give every site its own IP address, and whoever runs the primary DNS servers for the relevant domains updates the name server zone files as in these examples:

; from the database file for example.com
www	IN	A	192.0.2.2
; from the database file for example.net
www	IN	A	192.0.2.3
; from the database file for example.org
www	IN	A	192.0.2.4

You then configure your HTTP server to map the different IP addresses to the relevant directories (or other resources), e.g.:
192.0.2.2/usr/local/htdocs
192.0.2.3/home/client2/public_html
192.0.2.4/home/client3/public_html

The above approach works with any browser.

Host several domains on the same IP address

This is often called "name-based" or "HTTP/1.1" virtual hosting. On the DNS, all the domains point to the same IP address:

; from the database file for example.com
www	IN	A	192.0.2.2
; from the database file for example.net
www	IN	A	192.0.2.2
; from the database file for example.org
www	IN	A	192.0.2.2

Again, you configure the sites on your HTTP server, but this time using domain names, such as:

www.example.com/usr/local/htdocs
www.example.net/home/client2/public_html
www.example.org/home/client3/public_html

This is the economical and recommended way to go, especially if you're short on IP addresses. In fact, whichever entity you receive IP addresses from may have a policy mandating this form of web hosting only.

But how does the HTTP server know what to serve, now that all requests are received on the same IP address? This is where the Host: header comes in, as in the example above.

Most prevalent browsers know how to use the Host: headers, but to accommodate for the rare ones who do not, it's a good idea to have a default site as well, with hyperlinks to the virtual site directories:

<title>Welcome to www.example.com!</title>
<h1>Customer sites</h1>
<a href="/~client2/">www.example.net</a>
<a href="/~client3/">www.example.org</a>

If you do this, browsers that do not send Host: headers will be directed to the default front page, from where their users will be able to browse to the site of their choice using the directory path instead of the virtual host name. (This technique can, of course, also be used as an alternative to virtual hosting altogether - on the DNS, just point all the host names to the same IP address).

The 192.0.2.0 network IP addresses and the domain names example.com, example.net and example.org are - you guessed it - examples only.

All content © 2000–2008 Thor Kottelin, unless otherwise indicated. Any trademarks or registered trademarks mentioned on this site belong to their respective owners. Content and techniques used on this site may be available for licensing; for details, please contact the webmaster.

Conventional hyperlinking to any content on this site is highly welcomed. However, the work you are viewing must not be shown, even partly, in a context inferring or claiming it to be part of, or sponsored by, any other organization or site. Such prohibited techniques include (but are not limited to) framesets, interstitial pages, kiosk mode pop-ups, and reverse proxies.

38.103.63.18 (none)
(none) CCBot/1.0 (+http://www.commoncrawl.org/bot.html)
/misc/telnet-troubleshooting/http.shtml /misc/telnet-troubleshooting/http.shtml