Search code examples
curldnshostsservice-discovery

Is there a curl command to do an inline hosts file replacement for that command?


I'm testing a service-discovery tool, and I'd like to test dns entries that will point to it before I set them up.

Ordinarily I'd do that by:

  1. adding them to the hosts file,
  2. running the curl command, and then
  3. removing them from the hosts file.

The thought occurs I should be able to do this inline with curl.

My question is: Is there a curl command to do an inline hosts file replacement for that command?

EDIT: I believe this is not a duplicate of this or this as I'm asking a different question that happens to have the same answer.


Solution

  • For part of this you actually want to test dns using dig.

    The benefit of this is you can specify the dns server and the host you're trying to resolve.

    dig @127.0.0.1 -p 8600 web.service.consul
    

    Where @127.0.0.1 is the dns server parameter and web.service.consul is a service configured on the dns server, consul. Then pass the resulting IP address to your curl command.

    To answer the original question - you want to pass a header using curl

    curl -H 'Host: static.example.com' http://dnsserveripaddress/
    

    Some kind gents have pointed out --resolve

    But it is looking like I actually needed

    curl --dns-servers
    

    Note that this has issues on OS X. There appears to be a workaround, but I couldn't get that working.

    It might even be that you start your own dns server, and then point your machine to that dns server.