Q: I recently setup a DNS server on my Linux system. Now if I ping my IP is resolves to a hostname different from the one I put in DNS. If I use dig it resolves to the correct IP address in DNS. How is this possible and what is the problem?
A: Dig is a tool designed to query DNS servers. Ping is a tool to send ICMP ECHO_REQUEST to another machine, typically used to ensure the remote machine can communicate with the network. Although ping does resolve an IP address, it uses different mechanisms to do so.
Dig will use DNS only. Meaning it will use the name servers configured in /etc/resolv.conf just as the local DNS resolver would use, unless otherwise specified with the “server” argument.
Ping will use the mechanisms listed in the /etc/nsswitch.conf file to resolve hostnames in order they are given. This means it typically uses the hosts file (/etc/hosts) before querying DNS.
Here is an example excerpt of a default /etc/nsswitch.conf file:
#hosts: db files nisplus nis dns
hosts: files dns
The comment (line beginning with #) part of the excerpt shows the possible ways you can resolve hosts (db, files, nisplus, nis, or dns). The next line shows the currently configured ways to resolve hosts, in this case, files then DNS. This means ping (and other software) will use local files, like /etc/hosts, to find IP addresses for names before querying DNS. If it finds an answer using the first option, it will NOT progress to the next.
Although I can not definitely answer your question, I can tell you this is likely the problem. Check your /etc/hosts file and make sure you do not have any entries for things that are in DNS. DNS is much easier to manage on a network since all the changes can be made in one place rather than updating a hosts file on each client. I hope this helps.
Resources and Links
Leave a Reply Cancel reply
This site uses Akismet to reduce spam. Learn how your comment data is processed.
1 Comment
Join Our Newsletter
Categories
- Bash Scripting (17)
- Basic Commands (50)
- Featured (7)
- Just for Fun (5)
- Linux Quick Tips (98)
- Linux Tutorials (65)
- Miscellaneous (15)
- Network Tools (6)
- Reviews (2)
- Security (32)
Thanks a lot, it was useful.