[opensuse] Questions about name resolving using /etc/hosts
I am running OpenSuSE Leap 42.3 on a machine with 2 NICs. I am also running a Bind DNS server on the same system. I did an experiment in order to assign a unique hostname to each of the NIC interface cards by simply editing my /etc/hosts file as shown below: (sorry, I am not sure how to format this for a newsgroup.) bigbang:/etc # cat /etc/hosts 127.0.0.1 localhost # added for each nic 192.168.10.100 bigbangInternal.mydomainname.com bigbangInternal 10.10.10.100 bigbangExternal.mydomainname.com bigbangExternal ::1 localhost ipv6-localhost ipv6-loopback fe00::0 ipv6-localnet ff00::0 ipv6-mcastprefix ff02::1 ipv6-allnodes ff02::2 ipv6-allrouters ff02::3 ipv6-allhosts My host.conf file is configured to look at the hosts file first when resolving names: bigbang:/etc # cat /etc/host.conf ## file comments deleted for brevity... order hosts, bind multi on My nsswitch.conf file is also configured to look at the hosts file first when resolving names: bigbang:/etc # cat /etc/nsswitch.conf ## file comments deleted for brevity... passwd: compat group: compat hosts: files mdns_minimal [NOTFOUND=return] dns networks: files dns services: files protocols: files rpc: files ethers: files netmasks: files netgroup: files nis publickey: files bootparams: files automount: files nis aliases: files After editing the /etc/hosts file I flushed the name service cache: bigbang:/etc # systemctl restart nscd.service and when I test things out I get the following "surprising" results which appear at first glance to show that the name resolving order specified in nsswitch.conf is not being honored. But something else even deeper is going on as well that really has me baffled: bigbang:/etc # ping bigbangInternal ping: unknown host bigbangInternal ??? I didn't expect that! bigbang:/etc # getent hosts 127.0.0.1 localhost 192.168.10.100 bigbangInternal.mydomainname.com bigbangInternal 10.10.10.100 bigbangExternal.mydomainname.com bigbangExternal that looks good... bigbang:/etc # getent hosts localhost ::1 localhost ??? I am a bit surprised by this as I did not enable IPv6 addresses in YaST bigbang:/etc # getent hosts bigbangInternal bigbang:/etc # getent hosts bigbangInternal.mydomainname.com ??? no response! why not? bigbang:/etc # getent hosts 10.10.10.100 10.10.10.100 mydomainname.com ??? huh? Why did I get my dns domain name? bigbang:/etc # getent hosts 192.168.10.100 ??? no response! My guess is that these attempts to resolve these names and ip addresses is being done by my bind dns server and not by looking things up in the /etc/hosts file. But I don't understand why given that I am specifying that the order of lookup is to be done first via the /etc/hosts file and then by the bind dns server if the lookup in the hosts file fails. What am I missing and/or not understanding? Thanks in advance for any guidance/clues as to why I am seeing these results. Marc... -- Linux Counter -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org To contact the owner, e-mail: opensuse+owner@opensuse.org
On 30/10/2018 22.32, Marc Chamberlin wrote: ...
My guess is that these attempts to resolve these names and ip addresses is being done by my bind dns server and not by looking things up in the /etc/hosts file. But I don't understand why given that I am specifying that the order of lookup is to be done first via the /etc/hosts file and then by the bind dns server if the lookup in the hosts file fails. What am I missing and/or not understanding?
Thanks in advance for any guidance/clues as to why I am seeing these results.
I don't know, but I know that some commands ignore the hosts file; specifically the host command. I believe the ping command does honour it. -- Cheers / Saludos, Carlos E. R. (from 42.3 x86_64 "Malachite" at Telcontar)
Carlos E. R. wrote:
On 30/10/2018 22.32, Marc Chamberlin wrote:
...
My guess is that these attempts to resolve these names and ip addresses is being done by my bind dns server and not by looking things up in the /etc/hosts file. But I don't understand why given that I am specifying that the order of lookup is to be done first via the /etc/hosts file and then by the bind dns server if the lookup in the hosts file fails. What am I missing and/or not understanding?
Thanks in advance for any guidance/clues as to why I am seeing these results.
I don't know, but I know that some commands ignore the hosts file; specifically the host command. I believe the ping command does honour it.
Most things use the regular resolver, which will look at /etc/hosts when instructed to by /etc/nsswitch.conf. Utilities such as host and dig are _DNS_ utilities, they do DNS lookups, they don't use the resolver. -- Per Jessen, Zürich (9.5°C) http://www.hostsuisse.com/ - virtual servers, made in Switzerland. -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org To contact the owner, e-mail: opensuse+owner@opensuse.org
I found the cause of why I am seeing these anomalies but it is indicative of another problem (bug?) Because I am doing some experimentation and running OpenSuSE in a couple of different configurations I had changed /etc/hosts so that it was a link to another file instead of just a straightforward file in /etc. My guess is that the libraries, which are designed to resolve host names and IP addresses, using the /etc/hosts file are not capable of following links? Once I removed the link and replaced it with the actual file things worked pretty much as expected (except for the lookup of localhost which is still returning an IPv6 address instead of an IPv4 address as I was expecting) So is this a bug? If not shouldn't there at least be a warning/error message that is helpful to unsuspecting users such as myself? This was really hard to track down! Marc. On 10/30/2018 02:32 PM, Marc Chamberlin wrote:
I am running OpenSuSE Leap 42.3 on a machine with 2 NICs. I am also running a Bind DNS server on the same system. I did an experiment in order to assign a unique hostname to each of the NIC interface cards by simply editing my /etc/hosts file as shown below: (sorry, I am not sure how to format this for a newsgroup.)
bigbang:/etc # cat /etc/hosts
127.0.0.1 localhost # added for each nic 192.168.10.100 bigbangInternal.mydomainname.com bigbangInternal 10.10.10.100 bigbangExternal.mydomainname.com bigbangExternal
::1 localhost ipv6-localhost ipv6-loopback fe00::0 ipv6-localnet ff00::0 ipv6-mcastprefix ff02::1 ipv6-allnodes ff02::2 ipv6-allrouters ff02::3 ipv6-allhosts
My host.conf file is configured to look at the hosts file first when resolving names:
bigbang:/etc # cat /etc/host.conf
## file comments deleted for brevity...
order hosts, bind multi on
My nsswitch.conf file is also configured to look at the hosts file first when resolving names:
bigbang:/etc # cat /etc/nsswitch.conf
## file comments deleted for brevity...
passwd: compat group: compat
hosts: files mdns_minimal [NOTFOUND=return] dns networks: files dns
services: files protocols: files rpc: files ethers: files netmasks: files netgroup: files nis publickey: files
bootparams: files automount: files nis aliases: files
After editing the /etc/hosts file I flushed the name service cache:
bigbang:/etc # systemctl restart nscd.service
and when I test things out I get the following "surprising" results which appear at first glance to show that the name resolving order specified in nsswitch.conf is not being honored. But something else even deeper is going on as well that really has me baffled:
bigbang:/etc # ping bigbangInternal ping: unknown host bigbangInternal
??? I didn't expect that!
bigbang:/etc # getent hosts 127.0.0.1 localhost 192.168.10.100 bigbangInternal.mydomainname.com bigbangInternal 10.10.10.100 bigbangExternal.mydomainname.com bigbangExternal
that looks good...
bigbang:/etc # getent hosts localhost ::1 localhost
??? I am a bit surprised by this as I did not enable IPv6 addresses in YaST
bigbang:/etc # getent hosts bigbangInternal bigbang:/etc # getent hosts bigbangInternal.mydomainname.com
??? no response! why not?
bigbang:/etc # getent hosts 10.10.10.100 10.10.10.100 mydomainname.com
??? huh? Why did I get my dns domain name?
bigbang:/etc # getent hosts 192.168.10.100
??? no response!
My guess is that these attempts to resolve these names and ip addresses is being done by my bind dns server and not by looking things up in the /etc/hosts file. But I don't understand why given that I am specifying that the order of lookup is to be done first via the /etc/hosts file and then by the bind dns server if the lookup in the hosts file fails. What am I missing and/or not understanding?
Thanks in advance for any guidance/clues as to why I am seeing these results.
Marc...
-- Linux Counter -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org To contact the owner, e-mail: opensuse+owner@opensuse.org
Marc Chamberlin wrote:
Once I removed the link and replaced it with the actual file things worked pretty much as expected (except for the lookup of localhost which is still returning an IPv6 address instead of an IPv4 address as I was expecting)
It should return both really, but it depends on your setup. -- Per Jessen, Zürich (9.5°C) http://www.dns24.ch/ - your free DNS host, made in Switzerland. -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org To contact the owner, e-mail: opensuse+owner@opensuse.org
Marc Chamberlin wrote:
I found the cause of why I am seeing these anomalies but it is indicative of another problem (bug?) Because I am doing some experimentation and running OpenSuSE in a couple of different configurations I had changed /etc/hosts so that it was a link to another file instead of just a straightforward file in /etc. My guess is that the libraries, which are designed to resolve host names and IP addresses, using the /etc/hosts file are not capable of following links?
Whee, indeed. I just replaced my hosts with a link to the copied content. No info from getent anymore... Doing a strace on the getent call shows openat(AT_FDCWD, "/etc/hosts", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory) Maybe a security thing? Does O_CLOEXEC prevent following links? -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org To contact the owner, e-mail: opensuse+owner@opensuse.org
On Thu, Nov 1, 2018 at 12:20 PM Peter Suetterlin <pit@astro.su.se> wrote:
Does O_CLOEXEC prevent following links?
No. More likely AppArmor kicks in. -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org To contact the owner, e-mail: opensuse+owner@opensuse.org
Peter Suetterlin wrote:
Whee, indeed. I just replaced my hosts with a link to the copied content. No info from getent anymore...
Aargh! Mea maxima culpa :( Always watch out for typos. Of course it doesn't look for a file called 'hotsts' :P. So with proper naming of the link, getent follows it and uses the linked file (both TW 20181022 and Leap 42.3). @TO: Were the permissions of the linked file correct? -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org To contact the owner, e-mail: opensuse+owner@opensuse.org
On 11/01/2018 03:10 AM, Peter Suetterlin wrote:
Peter Suetterlin wrote:
Whee, indeed. I just replaced my hosts with a link to the copied content. No info from getent anymore... Aargh! Mea maxima culpa :( Always watch out for typos. Of course it doesn't look for a file called 'hotsts' :P.
So with proper naming of the link, getent follows it and uses the linked file (both TW 20181022 and Leap 42.3).
@TO: Were the permissions of the linked file correct?
Hi Peter, Thanks for responding and fair question! Here is the permissions on the files in question, I don't see anything wrong with them... bigbang:/etc # ll hosts lrwxrwxrwx 1 root root 14 Nov 1 13:32 hosts -> /srv/etc/hosts bigbang:/etc # ll /srv/etc/hosts -rw-r--r-- 1 root root 776 Oct 29 07:31 /srv/etc/hosts Marc... -- Linux Counter -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org To contact the owner, e-mail: opensuse+owner@opensuse.org
participants (5)
-
Andrei Borzenkov
-
Carlos E. R.
-
Marc Chamberlin
-
Per Jessen
-
Peter Suetterlin