Friday, March 23, 2018

Under standing /etc/resolv.conf

When your request from local machine has to go out and you need to find the IP address or domain name of a remote computer then you need some help from DNS.

In order to reach out to your preferred DNS Server one need to setup /etc/resolv.conf properly.

At minimum you can have at least values for two variables

search
nameserver


search: Is the list of the domains which the location machine can search to get the answer.
nameserver: Is the IP address of the DNS Server in those domain. There can be maximum of 3 nameservers and it is setup in (/usr/include/resolv.h)  with value
# define MAXNS                  3       /* max # name servers we'll track */

Let's test it. My setting is

My computer is on a domain and then on my computer I have virtualbox network setup of machines

My Domain:                   appowl247.com
My Virtualbox Domain: example.com
DNS on exmaple.com:   192.168.2.150
Two DNS on appowl274.com : xxx.xxx.x.xxx and yyy.yyy.yy.yy

Setting on my DNS for example.com

[root@dns ~]# cat /etc/resolv.conf
# Generated by NetworkManager
domain appowl247.com
search appowl247.com example.com
nameserver xxx.xxx.x.xxx
nameserver yyy.yyy.yy.yy
[root@dns ~]#

Test:
I will try to resolve the name for
wa01.example.com
google.com
hdhillon.appowl247.com



Scenario 1:

Let's create the /etc/resolv.conf file with appowl247.com and example.com

[root@wa01 ~]# cat /etc/resolv.conf
search example.com appowl247.com

nameserver 192.168.2.150

nameserver xxx.xxx.x.xxx
nameserver yyy.yyy.yy.yy

[root@wa01 ~]#


Below nslookup will work for example.com , appowl247.com and internet.

[root@wa01 ~]# nslookup wa01.example.com
Server:         192.168.2.150nslookup google.com

Address:        192.168.2.150#53

Name:   wa01.example.com
Address: 192.168.2.11

[root@wa01 ~]# nslookup google.com
nslookup hdhillon
Server:         xxx.xxx.x.xxx
Address:        xxx.xxx.x.xxx#53

Non-authoritative answer:
Name:   google.com
Address: 172.217.25.46

[root@wa01 ~]# nslookup hdhillon
Server:         xxx.xxx.x.xxx
Address:        xxx.xxx.x.xxx#53

Name:   hdhillon.appowl247.com
Address: 10.11.12.105

[root@wa01 ~]#


Scenario 2:

[root@wa01 ~]# cat /etc/resolv.conf
search example.com appowl247.com
nameserver 192.168.2.150

[root@wa01 ~]#

nslookup is not able to find the IP address of appowl247.com as well as internet

[root@wa01 ~]# nslookup wa01.example.com
Server:         192.168.2.150
Address:        192.168.2.150#53

Name:   wa01.example.com
Address: 192.168.2.11

[root@wa01 ~]# nslookup google.com
nslookup hdhillon
;; connection timed out; trying next origin
;; connection timed out; no servers could be reached

[root@wa01 ~]# nslookup hdhillon
;; connection timed out; trying next origin
;; connection timed out; no servers could be reached

[root@wa01 ~]#


Scenario 3:

[root@wa01 ~]# cat /etc/resolv.conf

search example.com 

nameserver 192.168.2.150

nameserver xxx.xxx.x.xxx
nameserver yyy.yyy.yy.yy

[root@wa01 ~]# 

nslookup is not able to find the IP address of my machine on appowl247.com

[root@wa01 ~]# nslookup wa01.example.com
Server:         192.168.2.150
Address:        192.168.2.150#53

Name:   wa01.example.com
Address: 192.168.2.11

[root@wa01 ~]# nslookup google.com
nslookup hdhillon
Server:         xxx.xxx.x.xxx
Address:        xxx.xxx.x.xxx#53

Non-authoritative answer:
Name:   google.com
Address: 172.217.25.46

[root@wa01 ~]# nslookup hdhillon
Server:         xxx.xxx.x.xxx
Address:        xxx.xxx.x.xxx#53

** server can't find hdhillon: NXDOMAIN

[root@wa01 ~]# 


Scenario 4:

[root@wa01 ~]# chattr +i /etc/resolv.conf
[root@wa01 ~]# cat /etc/resolv.conf
# Harvey additions
search example.com

nameserver 192.168.2.150

nameserver xxx.xxx.x.xxx
nameserver yyy.yyy.yy.yy

[root@wa01 ~]#

nslookup will not be able to locate the IP for machine on appowl247.com

[root@wa01 ~]# nslookup wa01.example.com
Server:         192.168.2.150
Address:        192.168.2.150#53

Name:   wa01.example.com
Address: 192.168.2.11

[root@wa01 ~]# nslookup google.com
nslookup hdhillon
Server:         xxx.xxx.x.xxx
Address:        xxx.xxx.x.xxx#53

Non-authoritative answer:
Name:   google.com
Address: 216.58.200.110

[root@wa01 ~]# nslookup hdhillon
Server:         xxx.xxx.x.xxx
Address:        xxx.xxx.x.xxx#53

** server can't find hdhillon: NXDOMAIN

[root@wa01 ~]#


Findings:

It is very important to consider adding all the domains you wish to search for to look at the DNS.

If domain name is missing under search then you will get an error like:
** server can't find <what ever>: NXDOMAIN


In case domain is present but the IP address of DNS is missing under nameserver then you will get
[root@wa01 ~]# nslookup google.com
;; connection timed out; trying next origin
;; connection timed out; no servers could be reached


In case domain is missing and but the IP address of DNS is present under nameserver then you will get
** server can't find <Something>: NXDOMAIN




No comments: