≡ Menu

Linux / Unix: curl Command Pass Host Headers

For example, send Host header to www.cyberciti.biz to get HTML response from 75.126.153.206:80, run:

curl -H 'Host: www.cyberciti.biz' 75.126.153.206:80

This is also useful when 75.126.153.206 has multiple virtual host set. The default is not to response anything when virtual host header is not sent:
$ curl -I 75.126.153.206:80
Sample outputs:

HTTP/1.1 500 Internal Server Error
Server: nginx
Date: Wed, 31 Oct 2012 18:51:03 GMT
Content-Type: text/html
Connection: keep-alive
X-Whom: l1-biz-cyber

Now, sent www.cyberciti.biz as Host header:
$ curl -I -H 'Host: www.cyberciti.biz' 75.126.153.206:80
Sample outputs:

HTTP/1.1 200 OK
Server: nginx
Date: Wed, 31 Oct 2012 18:52:20 GMT
Content-Type: text/html
Connection: keep-alive
X-Whom: l2-com-cyber
Vary: Cookie
Last-Modified: Wed, 31 Oct 2012 18:48:58 GMT
Cache-Control: max-age=98, must-revalidate
X-Galaxy: Andromeda-1
X-Origin-Type: DynamicViaDAL

You can use this command to test Apache server node behind a load balancer (only work with your own VLAN/LAN setup):

## see if 192.168.1.11:95 apache node #1 is working or not ##
curl -I --header 'Host: www.cyberciti.biz' 'http://192.168.1.11:95/'

Sample outputs:

HTTP/1.1 200 OK
X-Whom: l1-com-cyber
Vary: Cookie
Last-Modified: Wed, 31 Oct 2012 18:54:00 GMT
Cache-Control: max-age=77, must-revalidate
Content-type: text/html
Date: Wed, 31 Oct 2012 18:57:43 GMT
Server: lighttpd

This option can be used multiple times to add/replace/remove multiple headers:

curl www.cyberciti.biz \
-H "Accept-Language: en" \
-H "Host www.cyberciti.biz" \
-H "User-Agent: curl"
References

See curl command man page for more options:
$ man curl

Share this tutorial on:
{ 3 comments… add one }
  • Ashish Jaiswal November 1, 2012, 1:58 am

    Plesase correct the url spelling “-sedning”

  • Shantanu Gadgil November 7, 2012, 2:26 pm

    HEDER should be HEADER

    :) :)

Security: Are you a robot or human?

Leave a Comment

You can use these HTML tags and attributes: <strong> <em> <pre> <code> <a href="" title="">


   Tagged with: , , , , , ,