2

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.

Community
  • 1
  • 1
hawkeye
  • 34,745
  • 30
  • 150
  • 304
  • Effectively duplicate of http://stackoverflow.com/questions/3390549/set-curl-to-use-local-virtual-hosts?rq=1 and the specific answer is `--resolve` *if* you have (or get) a recent version of curl. – dave_thompson_085 May 14 '16 at 15:54
  • Does this answer your question? [Set cURL to use local virtual hosts](https://stackoverflow.com/questions/3390549/set-curl-to-use-local-virtual-hosts) – OrangeDog Sep 01 '21 at 14:34

1 Answers1

2

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.

hawkeye
  • 34,745
  • 30
  • 150
  • 304