You are not logged in.

#1 2022-09-18 18:51:02

mdcclxv
Member
Registered: 2022-04-26
Posts: 207

[SOLVED] Hosts file is being ignored randomly

Hi there,

So, I have a host name configured in /etc/hosts that points to a a Linode IP, let's call these somehost.com and IP1. Then there is the same somehost.com name configured in a GoDaddy DNS pointing to another Linode IP, let's call it IP2. The reason for the /etc/hosts IP1 is to test a new version of the site that's live on IP2.

My problem is that sometimes somehost.com resolves to IP1, some other times it resolves to IP2, with no apparent rule. This is happening for ping&host commands and browser as well.

My /etc/nsswitch.conf has the following content:

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

passwd: files systemd
group: files [SUCCESS=merge] systemd
shadow: files systemd
gshadow: files systemd

publickey: files

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

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

netgroup: files

Notice the "hosts:" entry having "files" as the first item.

It's driving me mad. Any ideas? Thanks in advance.

Last edited by mdcclxv (2022-09-19 13:17:06)

Offline

#2 2022-09-18 19:12:38

tucuxi
Member
From: Switzerland
Registered: 2020-03-08
Posts: 291

Re: [SOLVED] Hosts file is being ignored randomly

Not an explanation for the situation you described, but not all software respects /etc/nsswitch.conf. Some programs read /etc/resolv.conf directly.

Offline

#3 2022-09-18 19:17:25

mdcclxv
Member
Registered: 2022-04-26
Posts: 207

Re: [SOLVED] Hosts file is being ignored randomly

tucuxi wrote:

Not an explanation for the situation you described, but not all software respects /etc/nsswitch.conf. Some programs read /etc/resolv.conf directly.

I've been reading about that, but then at least ping&host should be consistent. They are not.

Offline

#4 2022-09-18 19:21:55

mdcclxv
Member
Registered: 2022-04-26
Posts: 207

Re: [SOLVED] Hosts file is being ignored randomly

This is a capture of the host output, with certain text removed for anonymity.

/zork: host www.___________care.com
www.___________care.com is an alias for ___________care.com.
___________care.com has address __.__.223.158
/zork: host www.___________care.com
www.___________care.com is an alias for ___________care.com.
___________care.com has address ___.___.0.85

The first output is IP2, the second output is IP1 (from my original post).

Offline

#5 2022-09-18 21:10:55

seth
Member
From: Won't reply 2 private help req
Registered: 2012-09-03
Posts: 76,485

Re: [SOLVED] Hosts file is being ignored randomly

Do you use systemd-resolved or any other caching daemon?
Can you reliably redirect hte domain to 127.0.0.1 or 0.0.0.0
On

strace ping idnet.ua-corp.com 2>&1 | grep -E '(hosts|nss)'

does /etc/hosts get read even when it's ignored?

Offline

#6 2022-09-19 12:57:58

mdcclxv
Member
Registered: 2022-04-26
Posts: 207

Re: [SOLVED] Hosts file is being ignored randomly

seth wrote:

Do you use systemd-resolved or any other caching daemon?

No, plain arch installation.

seth wrote:

Can you reliably redirect hte domain to 127.0.0.1 or 0.0.0.0

Yes, 127.0.0.1 works 100%.

seth wrote:

On

strace ping idnet.ua-corp.com 2>&1 | grep -E '(hosts|nss)'

does /etc/hosts get read even when it's ignored?

Looks like it does:

/zork: strace ping idnet.ua-corp.com 2>&1 | grep -E '(hosts|nss)'
newfstatat(AT_FDCWD, "/etc/nsswitch.conf", {st_mode=S_IFREG|0644, st_size=359, ...}, 0) = 0
openat(AT_FDCWD, "/etc/nsswitch.conf", O_RDONLY|O_CLOEXEC) = 4
openat(AT_FDCWD, "/etc/hosts", O_RDONLY|O_CLOEXEC) = 4
openat(AT_FDCWD, "/usr/lib/libnss_mymachines.so.2", O_RDONLY|O_CLOEXEC) = 4
openat(AT_FDCWD, "/usr/lib/libnss_resolve.so.2", O_RDONLY|O_CLOEXEC) = 4
openat(AT_FDCWD, "/usr/lib/libnss_myhostname.so.2", O_RDONLY|O_CLOEXEC) = 4

Offline

#7 2022-09-19 13:16:46

mdcclxv
Member
Registered: 2022-04-26
Posts: 207

Re: [SOLVED] Hosts file is being ignored randomly

Found the issue, please don't laugh.
1. There was a typo in /etc/hosts, a comma instead of a dot before the com part. So the entry from /etc/hosts was being ignored all the time as it was invalid.
2. The reason for mixed resolving, which now it's not happening anymore, is that a colleague of mine performed a DNS migration from one GoDaddy account to another, without informing me, so for a while both DNS entries were valid, the old one from caches, the new one from the migrated DNS. This only hit me after I spotted the comma mistake (after reverting from the above 127.0.0.1 test) and questioned the said colleague about DNS migration status.

But as there is a little good in all evil, this post was useful for I learned about this neat strace utility, thank you Seth.

And thank you all for your time.

Offline

#8 2022-09-19 13:17:08

seth
Member
From: Won't reply 2 private help req
Registered: 2012-09-03
Posts: 76,485

Re: [SOLVED] Hosts file is being ignored randomly

Edit: moot.

Last edited by seth (2022-09-19 13:17:28)

Offline

Board footer

Powered by FluxBB