1

Hi I been asked to check IP address by host name(or alias) in Redhat servers. In some sh scripts, there is a code of lftp opening connection to external ftp servers. First lftp connection uses "host1". ping host1 shows host1.domain.com. Another ping host2 shows unknows host. How can i check the ip address bind to host2 in Redhat ? i tried to check host file, no entry for it. Is there any other place to map host/alias to real IP ?

etc/nsswitch.conf:

#
# /etc/nsswitch.conf
#
# An example Name Service Switch config file. This file should be
# sorted with the most-used services at the beginning.
#
# The entry '[NOTFOUND=return]' means that the search for an
# entry should stop if the search in the previous entry turned
# up nothing. Note that if the search failed due to some other reason
# (like no NIS server responding) then the search continues with the
# next entry.
#
# Legal entries are:
#
#       nisplus or nis+         Use NIS+ (NIS version 3)
#       nis or yp               Use NIS (NIS version 2), also called YP
#       dns                     Use DNS (Domain Name Service)
#       files                   Use the local files
#       db                      Use the local database (.db) files
#       compat                  Use NIS on compat mode
#       hesiod                  Use Hesiod for user lookups
#       [NOTFOUND=return]       Stop searching if not found so far
#

# To use db, put the "db" in front of "files" for entries you want to be
# looked up first in the databases
#
# Example:
#passwd:    db files nisplus nis
#shadow:    db files nisplus nis
#group:     db files nisplus nis

passwd:     files
shadow:     files
group:      files

#hosts:     db files nisplus nis dns
hosts:      files dns

# Example - obey only what nisplus tells us...
#services:   nisplus [NOTFOUND=return] files
#networks:   nisplus [NOTFOUND=return] files
#protocols:  nisplus [NOTFOUND=return] files
#rpc:        nisplus [NOTFOUND=return] files
#ethers:     nisplus [NOTFOUND=return] files
#netmasks:   nisplus [NOTFOUND=return] files

bootparams: nisplus [NOTFOUND=return] files

ethers:     files
netmasks:   files
networks:   files
protocols:  files
rpc:        files
services:   files

Thanks.

2 Answers 2

1

The domain which is used to qualify unqualified hostnames can be set in your /etc/resolv.conf file. If host2 doesn't exist in the domain mentioned in your resolv.conf file, the name cannot be resolved and thus you get the error message.

2
  • In resolv.conf file i see 2 entries: nameserver X.X.X.2 nameserver X.X.X.3. host1 not configured here. How host1 being resolved ? any idea ?
    – taras
    Dec 5, 2010 at 8:23
  • You should set search in your resolv.conf to provide hints which domains are on your network and in which order they should be searched. See manpages.ubuntu.com/manpages/lucid/en/man5/resolv.conf.5.html for details. Also edit your question and provide the FQDN of both hosts for further error analysis. Please don't obfuscate but use the real hostnames.
    – joschi
    Dec 10, 2010 at 11:40
1

Usually, any host tries to resolve the name using the hosts file. If that fails, it will try to query the configured DNS server to resolve the name.

There is a configuration file named /etc/nsswitch.conf which determines the order of name resolution process.

If you find a line like:

hosts:          files dns

This means to query the hosts file first, and then the DNS server. The DNS servers can be configured in /etc/resolv.conf.

You can use the following command to query the DNS server for name resolution:

$ dig host1.example.com

nslookup can do similar job.

9
  • In /etc/resolv.conf i see 2 IP, so it means host2 should be configured in those DNS servers side ?
    – taras
    Dec 5, 2010 at 8:14
  • The IP addresses found in /etc/resolv.conf are the DNS servers that should be queried to resolve the names. Usually, DNS servers use FQDN like host.example.com not just host2.
    – Khaled
    Dec 5, 2010 at 8:53
  • ping host1 shows host.example.com. but ping host2 shows unknown host. Does it mean, host1 been configured in DNS(stated in /etc/resolv.conf) and host2 not ?
    – taras
    Dec 5, 2010 at 8:59
  • If you did not find host1 in /etc/hosts, so it should be defined in the DNS server. Did you check the /etc/nsswitch.conf file?
    – Khaled
    Dec 5, 2010 at 9:13
  • etc/nsswitch.conf contents added.
    – taras
    Dec 5, 2010 at 9:22

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .