2

I am having an issue connecting to my website. When I ping sample.com the server, I IP address I get is 192.168.0.12, but when I do an NSlookup, I get the correct IP. When I switch user account or go to the recovery mode, the name of site is resolved correctly and I can get to it.

Note that I am trying to access my website from the outside world, not from the local network.

I tried:

dscacheutil -q host -a name sample.com

and I got:

name: sample.com
ip_address: 192.168.0.12

To solve the issue I tried deleting the preferences from the library and resetting the NVRAM:

sudo dscacheutil -flushcache

sudo killall -INFO mDNSResponder

launchctl unload -w /System/Library/LaunchDaemons/com.apple.mDNSResponder.plist

But the name is still resolving wrong. I am running macOS High Sierra 10.13.2.

  • Do you have an entry for sample.com in /etc/hosts? – jaume Aug 17 '18 at 10:57
  • It worked, thank you for saving the day! Can you post it as an answer so I can mark it as accepted? – Riad C Aug 17 '18 at 14:59
  • I'm glad I could help, I added my comment as an answer. – jaume Aug 17 '18 at 15:48
1

Check if you have an entry for sample.com in /etc/hosts.

Entries in /etc/hosts take precedence over DNS. In your case, DNS is properly configured (nslookup returns the correct IP), but ping will use the information in /etc/hosts instead. This is also true for any CLI command like curl or wget and most apps (some apps don't appear to honor /etc/hosts.)

Note that the host name specified in the command must match an entry in /etc/hosts exactly, for example:

192.168.16.3   myserver.mydomain.com

will direct ping myserver.mydomain.com to try to reach 192.168.16.3, but ping myserver will query DNS with whatever default domain is configured in /etc/resolv.conf.

For more information on /etc/hosts, see man hosts and this Wikipedia article on /etc/hosts. For more information on /etc/resolv.conf, see this Wikipedia article on resolv.conf.

You must log in to answer this question.

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