How to configure nslookup/dig to resolve hostnames mentioned in /etc/hosts? DNS masquerade

Moderator: cah

Post Reply
cah
General of the Army / Fleet Admiral / General of the Air Force
General of the Army / Fleet Admiral / General of the Air Force
Posts: 1342
Joined: Sun Aug 17, 2008 5:05 am

How to configure nslookup/dig to resolve hostnames mentioned in /etc/hosts? DNS masquerade

Post by cah »

nslookup and dig cannot resolve IP address from /etc/hosts since it was not design that way. There is a workaround that can help resolve entries in /etc/hosts.

You may need an account with Red Hat to access the following link:

https://access.redhat.com/site/solutions/46767

Steps:
  1. Install DNSMASQ

    Code: Select all

    # yum install dnsmasq -y
    
  2. Edit /etc/resolve.conf to add the following line lookup the localhost

    Code: Select all

    nameserver 127.0.0.1
    
  3. Add the following lines in /etc/dnsmasq.conf

    Code: Select all

    domain-needed
    bogus-priv
    filterwin2k
    resolv-file=/etc/resolv.external
    expand-hosts
    domain=example.com
    log-queries
    log-facility=/var/log/dnsmasq
    conf-dir=/etc/dnsmasq.d
    
  4. Make a file for to specify external DNS server

    Code: Select all

    cp /etc/resolv.conf /etc/resolv.external
    
  5. Put the entry of your entries not in DNS into /etc/hosts

    Code: Select all

    1.1.1.1    test.xyz.com
    
  6. Start DNSMASQ Service

    Code: Select all

    # service dnsmasq start
    
  7. check the results

    Code: Select all

    # nslookup test.xyz.com
    Server:          127.0.0.1
    Address:     127.0.0.1#53
    
    Name:     test.xyz.com
    Address: 1.1.1.1
    
NOTICE: Whenevera new entry is added to /etc/hosts, the dnsmasq service needs to be restarted to take effect.

Code: Select all

# service dnsmasq restart
Shutting down dnsmasq:                                     [  OK  ]
Starting dnsmasq:                                          [  OK  ]
CAH, The Great
Post Reply