curl http://example.comto connect to your local server instead of the actual server.
/etc/hostson Linux and Unix-like systems) and adding, for example,
127.0.0.1 example.comto redirect the host to your localhost. However this edit requires admin access and it has the downside that it affects all other applications at the same time.
Host:header is the normal way an HTTP client tells the HTTP server which server it speaks to, as typically an HTTP server serves many different names using the same software instance.
Host:header you can have the server respond with the contents of the site even when you did not actually connect to that host name.
www.example.comon your local machine and you want to have curl ask for the index html:
Host:header and using cookies, curl will extract the custom name and use that as host when matching cookies to send off.
Host:header is not enough when communicating with an HTTPS server. With HTTPS there is a separate extension field in the TLS protocol called SNI (Server Name Indication) that lets the client tell the server the name of the server it wants to talk to. curl will only extract the SNI name to send from the given URL.
example.comto instead reach your localhost:
--resolveswitches to provide multiple redirects of this sort, which can be handy if the URL you work with uses HTTP redirects or if you just want to have your command line work with multiple URLs.
--resolveinserts the address into curl's DNS cache, so it will effectively make curl believe that is the address it got when it resolved the name.
--connect-tooption provides a minor variation. It allows you to specify a replacement name and port number for curl to use under the hood when a specific name and port number is used to connect.
www.example.comthat in turn is actually served by three different individual HTTP servers: load1, load2 and load3, for load balancing purposes. In a typical normal procedure, curl resolves the main site and gets to speak to one of the load balanced servers (as it gets a list back and just picks one of them) and all is well. If you want to send a test request to one specific server out of the load balanced set (
load1.example.comfor example) you can instruct curl to do that.
--resolveto accomplish this if you know the specific IP address of load1. But without having to first resolve and fix the IP address separately, you can tell curl:
load1.example.comname and connect, but in all other ways still assume it is talking to
--dns-servers, you can specify exactly which DNS server curl should use instead of the default one. This lets you run your own experimental server that answers differently, or use a backup one if your regular one is unreliable or dead.
--dns-ipv6-addryou ask curl to "bind" its local end of the DNS communication to a specific IP address and with
--dns-interfaceyou can instruct curl to use a specific network interface to use for its DNS requests.
--dns-*options are advanced and are only meant for people who know what they are doing and understand what these options do. But they offer customizable DNS name resolution operations.