1

I have inserted

domain test 

into resolv.conf and have then expected that

# getent ahosts srv
# getent ahosts srv.test
1.1.1.1         STREAM srv.test
1.1.1.1         DGRAM  
1.1.1.1         RAW    

will both provide same results.

Any idea why is it not happening?

Thank you!

Edit:

/etc/nsswitch

hosts:      files mdns4_minimal [NOTFOUND=return] dns myhostname 

srv.test record is stored in /etc/hosts.

arik
  • 13
  • 4

1 Answers1

1

The command getent makes a system call to getaddrinfo() and will try each service defined in /etc/nsswitch.conf, however, DNS resolution itself is a lower level call to gethostbyname() and is configured by /etc/resolv.conf.

In short, you can't define a fully-qualified hostname only in /etc/hosts because getaddrinfo() doesn't use search domains for hosts file look-ups. You can create a host alias in /etc/hosts by defining srv as;

1.1.1.1     srv.test srv
Aaron Copley
  • 12,525
  • 5
  • 47
  • 68