# Unbound intermittently slow with @localhost



## usdmatt (Mar 24, 2017)

I'm just setting up an unbound server as a local resolver for our network.

I'm not really seeing any actual issues but when running lookups from localhost, it's a bit disconcerting that the lookup sometimes hangs for over 10 seconds before finally returning a response. Even with the delay, the query time reports 0 msec.

I've found that it's only if I use drill @ localhost ... (and even then it's intermittent). If I use @127.0.0.1 or its real address/hostname, there's no delay.

Anyone got any ideas on what I can do to stop this happening, or should I just ignore it?


----------



## obsigna (Mar 24, 2017)

To begin with, I never saw this.

I left /etc/nsswitch.conf and /etc/hosts at their respective default settings. That means localhost should be looked up in the Hosts file. The difference that you found between looking up localhost without specifying the DNS server vs. @127.0.0.1 might come from unbound tries to recursively resolve the first one, and responds quickly if it is in the cache and otherwise it takes its time.


----------



## SirDice (Mar 24, 2017)

localhost might resolve to ::1 and 127.0.0.1, so it'll try to access it on IPv6 first. When that fails, after a time-out, it'll switch to IPv4. This might be the cause of the delay.


----------



## usdmatt (Mar 24, 2017)

Thanks SirDice, looks like that was it.


```
# drill @::1 www.google.co.uk
Error: error sending query: Could not send or receive, because of network error
```
Adding interface: ::0 to unbound conf seems to have sorted it (not that I need ipv6 support).


```
# drill @::1 www.google.co.uk
;; ->>HEADER<<- opcode: QUERY, rcode: NOERROR, id: 12328
;; flags: qr rd ra ; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 0
;; QUESTION SECTION:
;; www.google.co.uk.    IN      A

;; ANSWER SECTION:
www.google.co.uk.       272     IN      A       216.58.198.227

;; AUTHORITY SECTION:

;; ADDITIONAL SECTION:

;; Query time: 0 msec
;; SERVER: ::1
;; WHEN: Fri Mar 24 12:47:50 2017
;; MSG SIZE  rcvd: 50
```
Can't reproduce the delay now when doing lookups {AT}localhost.

Edit: Looks like removing the `::1` line from /etc/hosts would probably "fix" it as well. By default I see responses from both ::1 and 127.0.0.1, so it must be alternating between the two entries in hosts. That'll be why I was seeing the delay intermittently. With the IPv6 address removed from hosts, I only see DNS responses from 127.0.0.1.


----------

