MacOS – Terminal/Safari Cannot Resolve Host But Chrome Can Connect

dnsmacosNetwork

I have MacBook Pro (Retina, 13-inch, Early 2015) with OS X 10.11.5.

Internet connection works only for Chrome. Safari and several terminal apps cannot connect to internet due to resolve host failure.

I read the following posts in stackexchange that describe similar connectivity issues: My native mac apps are not connecting to the internet, but Google Chrome does and works correctly. Why is this?

On the terminal:

  • ping google.com: ping: cannot resolve google.com: Unknown host
  • ping 8.8.8.8: 5 packets transmitted, 5 packets received, 0.0% packet loss
  • curl google.com: curl: (6) Couldn't resolve host 'google.com'
  • curl 8.8.8.8: curl: (7) Failed to connect to 8.8.8.8 port 80: Operation timed
  • ssh {servername} : ssh: Could not resolve hostname {servername}: nodename nor servname provided, or not known
  • nslookup google.com: This works correctly.
  • dig google.com: This works correctly.

I tried the followings a lot of times to no avail:

  1. Renewing/turning off&on/inputting manually DHCP.
  2. Restarting/resetting the router and the macbook.
  3. Turning WiFi on/off. This fixes the problem for a few minutes but then the connection drops again.
  4. Set all network configurations except wifi to "make service unavailable" in network preferences.
  5. Checked and copied all network settings from another macbook pro that's connected and online on my network.
  6. Ran network diagnostic and assistant tools
  7. Set Network > Wifi > Advanced > DNS > DNS servers to OpenDNS ip addresses: 208.67.222.222
  8. No Proxies is checked or set under Network > Wifi > Advanced > Proxies.
  9. Set TCP/IP > Configure IPv6 to "Link-local only" as suggested here: Constantly dropping internet on El Capitan?
  10. Logging in and connecting to internet with guest user account.

I tried running the following commands to reset DNS but they didn't run neither

$ sudo launchctl unload -w /System/Library/LaunchDaemons/com.apple.mDNSResponder.plist
/System/Library/LaunchDaemons/com.apple.mDNSResponder.plist: Could not find specified service

$ sudo launchctl load -w /System/Library/LaunchDaemons/com.apple.mDNSResponder.plist

I didn't try the followings:

  1. Resetting SMC
  2. Removed the /Library/Preferences/SystemConfiguration folder.
  3. Removed network password from keychain.

Other information that might be relevant:

  • OS X Firewall is off.

  • I tried the following commands on terminal:

    $ ifconfig en1
    en1: flags=963<UP,BROADCAST,SMART,RUNNING,PROMISC,SIMPLEX> mtu 1500
         options=60<TSO4,TSO6>
         ether 4a:00:03:bd:de:d0
         media: autoselect <full-duplex>
         status: inactive
    $ ifconfig awdl0
    awdl0: flags=8943<UP,BROADCAST,RUNNING,PROMISC,SIMPLEX,MULTICAST> mtu 1484
         ether 76:aa:18:a6:c9:49
         inet6 fe80::74aa:18ff:fea6:c949%awdl0 prefixlen 64 scopeid 0x8
         nd6 options=1<PERFORMNUD>
         media: autoselect
         status: active
    $ sudo ifconfig awdl0 down
    

I did the last command because it was suggested here: Constantly dropping internet on El Capitan?

  • My modem router has no black/whitelist for any MAC addresses.

  • skype app doesn't connect. It is stuck in "connecting" state.

flushing DNS cache didn't help neither:

$ sudo dscacheutil -flushcache
$ sudo killall -HUP mDNSResponder
No matching processes were found

Here are the DNS server settings:

$ cat /etc/resolv.conf
#
# Mac OS X Notice
#
# This file is not used by the host name and address resolution
# or the DNS query routing mechanisms used by most processes on
# this Mac OS X system.
#
# This file is automatically generated.
#
nameserver 192.168.43.1

Best Answer

Your launch daemon com.apple.mDNSResponder.reloaded is not loaded properly.

You can check this by entering sudo launchctl list | grep DNS.

The result should yield something like this:

-   0   com.apple.mDNSResponderHelper.reloaded
108 0   com.apple.mDNSResponder.reloaded

108 is the pid and should differ on your system.


Check your com.apple.mDNSResponder.plist for errors with:

cat /System/Library/LaunchDaemons/com.apple.mDNSResponder.plist

It should look like this:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
    <key>Label</key>
    <string>com.apple.mDNSResponder.reloaded</string>
    <key>OnDemand</key>
    <false/>
    <key>InitGroups</key>
    <false/>
    <key>UserName</key>
    <string>_mdnsresponder</string>
    <key>GroupName</key>
    <string>_mdnsresponder</string>
    <key>ProgramArguments</key>
    <array>
        <string>/usr/sbin/mDNSResponder</string>
    </array>
    <key>MachServices</key>
    <dict>
        <key>com.apple.mDNSResponder</key>
        <true/>
            <key>com.apple.mDNSResponder.dnsproxy</key>
            <true/>
    </dict>
    <key>Sockets</key>
    <dict>
        <key>Listeners</key>
        <dict>
            <key>SockFamily</key>
            <string>Unix</string>
            <key>SockPathName</key>
            <string>/var/run/mDNSResponder</string>
            <key>SockPathMode</key>
            <integer>438</integer>
        </dict>
    </dict>
    <key>POSIXSpawnType</key>
    <string>Interactive</string>
    <key>EnablePressuredExit</key>
    <false/>
</dict>
</plist>

Remove the lines <key>com.apple.mDNSResponder.reloaded</key> and the immediately following <false/> or <true/> from the file disabled.plist by editing it with

sudo nano /private/var/db/com.apple.xpc.launchd/disabled.plist

You may have to disable SIP to do so!

Remove the mDNSResponder daemon from the launchctl database with:

sudo launchctl remove com.apple.mDNSResponder.reloaded

Re-add it with

sudo launchctl load /System/Library/LaunchDaemons/com.apple.mDNSResponder.plist

Reboot.