You are not logged in.

#1 2021-01-13 15:25:47

BrianKopp
Member
Registered: 2020-08-17
Posts: 4

Why is host not resolving using /etc/hosts

Hi everyone! I have a question about name resolution. I'm trying to run an application locally using a custom hostname. I've got the entry listed in /etc/hosts, but when I try to run a nslookup for that host, I get nothing.

Here is my /etc/hosts file

```
# Static table lookup for hostnames.
# See hosts(5) for details.
127.0.0.1 localhost
::1 localhost
127.0.1.1 archlinux.host.local
127.0.0.1 foo.private
```

/etc/resolv.conf
```
# Generated by NetworkManager
search hsd1.co.comcast.net host.local
nameserver 75.75.75.75
nameserver 75.75.76.76
nameserver 2001:558:feed::1
# NOTE: the libc resolver may not support more than 3 nameservers.
# The nameservers listed below may not be recognized.
nameserver 2001:558:feed::2
```

And /etc/nsswitch.conf

```
# Name Service Switch configuration file.
# See nsswitch.conf(5) for details.

passwd: files systemd
group: files systemd
shadow: files

publickey: files

hosts: files mymachines myhostname resolve [!UNAVAIL=return] dns
networks: files

protocols: files
services: files
ethers: files
rpc: files

netgroup: files
```

Here is the output of the nslookup query

```
> nslookup foo.private
Server:         75.75.75.75
Address:        75.75.75.75#53

** server can't find foo.private: NXDOMAIN
```

I'm confused - what I've been able to find so far tells me that the /etc/nsswitch.conf should try "file" first for hosts.

All the relevant files (I think) have correct permission:

```
> ls -ahl /etc | grep -E 'hosts|nsswitch|resolv'
-rw-r--r--  1 root root   554 Jan 13 08:21 hosts
-rw-r--r--  1 root root   312 Sep  2 16:30 nsswitch.conf
-rw-r--r--  1 root root   291 Jan 13 08:02 resolv.conf
```

I'm at a bit of a loss as to where to start digging into this. Does anyone have any tips?

Offline

#2 2021-01-13 15:36:39

Ropid
Member
Registered: 2015-03-09
Posts: 952

Re: Why is host not resolving using /etc/hosts

What happens if you run "ping foo.private"?

nslookup says it asked server 75.75.75.75. This means the 75.75.75.75 machine tried to find "foo.private". The 75.75.75.75 machine can't know what's happening in your /etc/hosts file.

Offline

#3 2021-01-13 15:38:26

RagnarOlafsson
Member
Registered: 2021-01-11
Posts: 6

Re: Why is host not resolving using /etc/hosts

Nslookup by default does not query the /etc/hosts file. It does only a proper name-resolution (querying the set up DNS server).

You can test whether the translation is working by pinging the name or just navigating to the hostname in your web browser.

Offline

#4 2021-01-13 15:42:27

BrianKopp
Member
Registered: 2020-08-17
Posts: 4

Re: Why is host not resolving using /etc/hosts

Wow, major fail. Thanks yall. Yes, ok, it's working fine - I'm just being an idiot lol. Ping and curl do in fact resolve that host to localhost.

> curl -v http://foo.private
*   Trying 127.0.0.1:80...
* connect to 127.0.0.1 port 80 failed: Connection refused
* Failed to connect to foo.private port 80: Connection refused
* Closing connection 0
curl: (7) Failed to connect to foo.private port 80: Connection refused



Thanks RagnarOlafsson! I forgot that nslookup doesn't query the /etc/hosts file. That was what was tripping me up.

Offline

#5 2021-01-13 15:59:07

RagnarOlafsson
Member
Registered: 2021-01-11
Posts: 6

Re: Why is host not resolving using /etc/hosts

You're most welcome. Also please do not forget to mark the thread as [SOLVED].

Offline

Board footer

Powered by FluxBB