3

There are several nameserver entries in my /etc/resolv.conf, some public and some are my own:

search subdomain.example.com
nameserver 8.8.8.8
nameserver 10.20.30.1
nameserver 10.20.30.2

I want cURL to load a file from an address, that only my own DNS server can resolve:

curl subdomain.example.com/myfile

It fails with

curl: (6) Could not resolve host: subdomain.example.com

It looks to me like cURL tries the first nameserver and stops trying if that fails. I couldn't confirm though, because curl -v doesn't print what DNS server it uses.

So another question would be, how to determine which DNS server cURL uses by default, and ideally how to make it retry with the other entries from resolv.conf. I know the --dns-servers command line option. If possible, I'd prefer to use the DHCP provided DNS settings.

2 Answers2

9

"Will it retry" depends on the cause of failure. Curl will retry if the server doesn't respond; it will not retry if the server does respond with 'Unknown'.

Practically no software will retry a different server upon receiving a valid response from the first server, even if it got a "Domain unknown" response – that's still a valid response. The ability to list multiple servers is only for situations when the first server doesn't respond at all – not for situations where different servers know different data.

If you have an internal DNS domain, you'll need a separate resolver to unify both sets of servers into a single view. Usually the internal DNS servers already do that themselves, but if you don't want to send general Internet DNS queries to 10.20.30.1 for some reason, then you'll have to run another local DNS server on top of that.

For example, Dnsmasq on localhost is a common way of doing it; it provides both a local DNS cache and the ability to route different queries to different upstream servers. Unbound and systemd-resolved are also possible.

grawity
  • 501,077
0

I found https://serverfault.com/questions/398837/second-nameserver-in-etc-resolv-conf-not-picked-up-by-wget. Feel free to move or mark my question as duplicate. @grawity thanks for your answer, I went for export RES_OPTIONS="rotate", which I found in man resolv.conf, instead (not the DHCP provided DNS settings, but solves my problem)