Linux / Unix: curl Command Pass Host Headers

How do I send a header to my Web server (such as Nginx / Lighttpd / Apache / ISS) on a Apple OS X or Unix or Linux based system using a curl command line option for testing and debugging my web apps or server nodes behind a load balancer?

Tutorial details
Difficulty Easy (rss)
Root privileges No
Requirements curl command
Time N/A
The curl command supports -H or --header option to pass extra HTTP header to use when getting a web page from your web server. You may specify any number of extra headers. When you add a custom header that has the same name as one of the internal ones curl would use, your externally set header will be used instead of the internal one. The syntax is:
curl -H 'YOUR-EXTRA-HEADER-HERE' apache-server-ip

For example, send Host header to to get HTML response from, run:

curl -H 'Host:'

This is also useful when has multiple virtual host set. The default is not to response anything when virtual host header is not sent:
$ curl -I
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 as Host header:
$ curl -I -H 'Host:'
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 apache node #1 is working or not ##
curl -I --header 'Host:' ''

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 \ 
-H "Accept-Language: en" \ 
-H "Host" \ 
-H "User-Agent: curl"

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

🐧 Get the latest tutorials on Linux, Open Source & DevOps via RSS feed or Weekly email newsletter.

🐧 3 comments so far... add one

CategoryList of Unix and Linux commands
File Managementcat
FirewallAlpine Awall CentOS 8 OpenSUSE RHEL 8 Ubuntu 16.04 Ubuntu 18.04 Ubuntu 20.04
Network Utilitiesdig host ip nmap
OpenVPNCentOS 7 CentOS 8 Debian 10 Debian 8/9 Ubuntu 18.04 Ubuntu 20.04
Package Managerapk apt
Processes Managementbg chroot cron disown fg jobs killall kill pidof pstree pwdx time
Searchinggrep whereis which
User Informationgroups id lastcomm last lid/libuser-lid logname members users whoami who w
WireGuard VPNAlpine CentOS 8 Debian 10 Firewall Ubuntu 20.04
3 comments… add one
  • Ashish Jaiswal Nov 1, 2012 @ 1:58

    Plesase correct the url spelling “-sedning”

  • Shantanu Gadgil Nov 7, 2012 @ 14:26

    HEDER should be HEADER

    :) :)

Leave a Reply

Your email address will not be published. Required fields are marked *

Use HTML <pre>...</pre> for code samples. Problem posting comment? Email me @