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.
Best Answer
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), butping
will use the information in/etc/hosts
instead. This is also true for any CLI command likecurl
orwget
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:will direct
ping myserver.mydomain.com
to try to reach192.168.16.3
, butping myserver
will query DNS with whatever default domain is configured in/etc/resolv.conf
.For more information on
/etc/hosts
, seeman hosts
and this Wikipedia article on/etc/hosts
. For more information on/etc/resolv.conf
, see this Wikipedia article onresolv.conf
.