linux name resolution and go binaries
I encountered a problem when trying to setup backup with restic. I run restserver on one of my computer and tried to run backup from other computer. I have zeroconf using avahi on each computer in my home network. When I run backup command(tmp directory is just for illustration) I received error message:
restic backup -r rest:http://plechy.local:8000/tmp /tmp
Fatal: unable to open config file: client.Head: Head http://plechy.local:8000/tmp/config: dial tcp: lookup plechy.local on 127.0.1.1:53: no such host
Is there a repository at the following location?
rest:http://plechy.local:8000/tmp
Ping command on the other hand worked as expected:
ping plechy.local
PING plechy.local (192.168.2.7) 56(84) bytes of data.
Finally I found out here and here that go can be compiled to call just DNS lookup and bypass linux resolution. I downloaded binaries from restic web page. Setting GODEBUG variable revealed that binaries are not compiled with cgo and DNS lookup only is proceed. Binaries included in opensuse distribution behaves correctly.
export GODEBUG=netdns=cgo+1
restic backup -r rest:http://plechy.local:8000/tmp /tmp
go package net: built with netgo build tag; using Go's DNS resolver
Fatal: unable to open config file: client.Head: Head http://plechy.local:8000/tmp/config: dial tcp: lookup plechy.local on 127.0.1.1:53: no such host
Is there a repository at the following location?
rest:http://plechy.local:8000/tmp
As a temporal solution I use getent utility in script to find out ip address and then supply it to command. getent resolve name according nsswitch.conf - nice explanation how this all works is here.
getent hosts plechy.local
192.168.2.7 plechy.local
Utility nslookup resolve name via DNS only. And of course I got same result as restic program. So for debugging net problems is good to know both those utilities and how they work.
nslookup plechy.local
Server: 127.0.1.1
Address: 127.0.1.1#53
** server can't find plechy.local: NXDOMAIN