Nslookup fails with localhost

Hi,

i noticed failure with 'nslookup localhost' command on target .
{{
/# nslookup localhost
nslookup: write to '127.0.0.1': Connection refused
Server: 8.8.8.8
Address: 8.8.8.8:53

** server can't find localhost: NXDOMAIN
** server can't find localhost: NXDOMAIN
}}
I referred /etc/resolv.conf and observed domain details as given below.
{{
/# cat /etc/resolv.conf
nameserver 127.0.0.1
nameserver 8.8.8.8
domain
}}
where as 'nslookup google.com' is pinging successfully but still observed 'localhost' connection refusal message

{{
/# nslookup google.com
nslookup: write to '127.0.0.1': Connection refused
Server: 8.8.8.8
Address: 8.8.8.8:53

Non-authoritative answer:
Name: google.com
Address: 142.250.189.206

Non-authoritative answer:
Name: google.com
Address: 2607:f8b0:4005:80d::200e

}}
any input to resolve 'nslookup localhost' issue? please let me know.

Regards
Koti

is there a DNS running locally, and bound to 127.0.0.1 / localhost ?

1 Like

Dear Frollic,

How to check whether DNS running locally and bound to 127.0.0.1/localhost ? can you please share commands to verify it if possible?

Regards
Koti

it was a rhetorical question, since there's no answer, it would be a no ...

should there be one ?

btw, the error in itself isn't critical, unless you should have a DNS running on the device.

i understood, the error is not critical and of course DNS is running on the device otherwise For example:
'nslookup google.com' also fails if DNS is not running. So DNS server is OK but 'localhost' is not connected hence it's throwing error mentioned in the first comment?

it would not fail, since you have nameserver 8.8.8.8 in there as well.

googles DNS server is ok, yours, who knows ...

if you just want to get rid of the error, remove nameserver 127.0.0.1 from resolv.conf

2 Likes

netstat -nlp | grep ':53' and you can verify which process is listening on port 53. if none then remove nameserver 127.0.0.1 from resolv.conf, or adjust according to your setup if for example you are listening on specific IP address.

1 Like

Hi,

{{
/# netstat -nlp | grep ':53'
/#
}}
I removed 127.0.0.1 from resolv.conf , still the below error message is seen
with command 'nslookup localhost'.
{{
/# nslookup localhost
Server: 8.8.8.8
Address: 8.8.8.8:53

** server can't find localhost: NXDOMAIN

** server can't find localhost: NXDOMAIN

}}

Regards

Post the output of the commands below (copy/paste the entire block and press Enter).
Use the preformatted text button (</>) and redact the public IP addresses if any.

uci show dhcp; /etc/init.d/log restart; /etc/init.d/dnsmasq restart; \
sleep 3; logread -e dnsmasq; netstat -nlp | grep dnsmasq
1 Like

it means you don't run local dns server and 8.8.8.8 google dns server will not resolve localhost, which is correct.

if you want localhost to be resolved you'll need a local dns resolver. by default owrt configures one for you, what did you do with that? did you disable it? yeah, pls copy the output @pavelgl suggested.

note: please use preformatted text option while posting, for your console output for better readability.

1 Like

this is as it should be, localhost isn't a FQDN.

what's the real issue here ?

not running a local DNS is fine
google (or any other public DNS provider) not resolving localhost, is also fine

what are you trying to achieve ?

Hi,

I just want to ensure 'nslookup locahost' doesn't throw error message mentioned in my first comment. in my host ubuntu machine, 'nslookup localhost' command is OK where as on target device x86-64 , its failing.
my target (x86-64) , doesn't contains dnsmasq service in /etc/ directory to execute the steps mentioned in one of previous comments.

Regards.

who is the Ubuntu host querying, when it gets the reply back ?

which is why it doesn't work ...

  1. so you are using a custom owrt, otherwise dnsmasq should be there.you don't have local dns resolver, it is your choice.
  2. public DNS servers will not resolve "localhost", as should, it is correct.

so no issue i see.

1 Like

Shouldn't localhost be resolveable bacause it's set to 127.0.0.1 in /etc/hosts?

But nslookup will probably not look this up. Have you tried host localhost or ping localhost ?

ping will work with hosts, nslookup.won't.

Hi,

ping localhost is ok.

/# ping localhost
PING localhost (127.0.0.1): 56 data bytes
64 bytes from 127.0.0.1: seq=0 ttl=64 time=0.027 ms
64 bytes from 127.0.0.1: seq=1 ttl=64 time=0.026 ms
64 bytes from 127.0.0.1: seq=2 ttl=64 time=0.031 ms
64 bytes from 127.0.0.1: seq=3 ttl=64 time=0.023 ms
^C

ping != nslookup

Then yeah what's the issue? Others have already pointed out. Nslokup will ask the nameserver set on the system or specified as argument. Public resolver can but mostly will not resolve localhost. If you have no local resolver which knows about the record localhost or is configured to not resolve that then it will simply never resolve.

1 Like

what @_bernd said.

works as designed.