MacOS – Cannot ping a single website when I am logged into the account

dnshigh sierramacosNetworkping

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), 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.