title: golang's handling of localhost
body: <p>I have an alpine linux system which uses the musl libc and therefore has no <code>/etc/nsswitch.conf</code>.</p>
  
  <p>According to tcpdump on this system, <code>net.LookupIP("localhost")</code> actually does a query for <code>localhost.a.b.c</code>, where <code>a.b.c</code> is taken from <code>domain a.b.c</code> in <code>/etc/resolv.conf</code>.  But if I add an <code>/etc/nsswitch.conf</code> with <code>hosts: files dns</code>, it correctly looks up <code>localhost</code> from <code>/etc/hosts</code>.</p>
  
  <p>As far as I can tell, no libc implementation tries to add a domain to <code>localhost</code> when looking it up in DNS.  So (a) is there some good reason it's done this way or is it a bug?  and (b) is there a way to work around it without adding an nsswitch.conf and while still using just the name <code>localhost</code>?</p>
  
  <p><strong><em>Edit</em></strong> More details:</p>
  
  <pre><code>ldd ./dnstest
      /lib/ld-musl-armhf.so.1 (0x76f2c000)
      libc.so =&gt; /lib/ld-musl-armhf.so.1 (0x76f2c000)
  </code></pre>
  
  <p>So yes, there is a dependency on <code>libc.so</code>.  I have tried this with <code>CGO_ENABLED=1</code> and with <code>CGO_ENABLED=0</code> in the build commandline, too.</p>