4

I'm trying to have local tests working without running consul as DNS server. Which means I'm trying to map web.service.consul to localhost.

I've tried creating HOSTALIASES file but it seems it doesn't support dot in the alias name. I also tried playing with LOCALDOMAIN and RES_OPTIONS=ndots:10 but can't get this to work.

$ HOSTALIASES=/tmp/ha RES_OPTIONS=ndots:10 LOCALDOMAIN='consul' curl web.services.consul:8080
curl: (6) Could not resolve host: web.services.consul
$

Where /tmp/ha is

web.services.consul 127.0.0.1

Any ideas? Thanks.

  • Hmm, env LOCALDOMAIN=microsoft.com curl www gets the goods (bads?) for me. I'm not sure a fully qualified web.services.consul will fly, as that would be looking for web.services.consul.consul with your LOCALDOMAIN setting. – thrig Aug 21 '16 at 15:15
  • 2
    FWIW in reasonably recent curl specifically --resolve overrides other resolution and uses exactly what you specify. In any other program that doesn't help. – dave_thompson_085 Aug 21 '16 at 20:08

1 Answers1

2

Put in /tmp/ha:

web localhost

then you cam call curl with:

 HOSTALIASES=/tmp/ha curl web:8080

Format of HOSTALIASES is explained in hostname(7) - it is not a same thing as /etc/hosts !

If you can edit /etc/hosts, you could simply put 127.0.0.1 web.services.consul in it and then just use your test programs normally... Another way would be use iptables ... -j REDIRECT to force traffic to go to localhost instead... But both of those require root access.

Matija Nalis
  • 3,111
  • 1
  • 14
  • 27
  • 1
    Thanks. However this does not work for me with the above command line. From what I understand you cannot have aliases with . in the HOSTALIAS file. – Miki Tebeka Aug 22 '16 at 12:47