Mimsy Were the Borogoves

Hacks: Articles about programming in Python, Perl, Swift, BASIC, and whatever else I happen to feel like hacking at.

Apple software stops connecting to the Internet; Firefox continues fine

Jerry Stratton, January 21, 2011

I don’t know what changed, but in the last few days every once in a while I’ll appear to lose my Internet connection on Mac OS X. However, when I look into it I’ll discover that while Apple software—Safari, iTunes, Software Update, and Mail—think my computer is not connected to the net, non-Apple software such as Firefox connect just fine.

I’m currently using Snow Leopard, Mac OS X 10.6.6.

Safari tells me:

Safari can’t open the page “https://www.google.com/” because your computer isn’t connected to the Internet.

iTunes tells me:

iTunes could not connect to the iTunes Store.

Make sure your network connection is active and try again.

Mail just beeps at me and takes my accounts offline.

Firefox, iChat, and the command-line1 work fine. I’m editing this blog post right now in Firefox; I can use curl to view the HTML of any page, I can use elinks to view pages, and I can ssh to remote servers. Pinging and traceroute all seem to get through fine.

Network Diagnostics tells me “Your Internet connection appears to be working correctly.”

Rebooting makes the problem go away. Turning off Ethernet in Network Preferences and turning it on again does not make it go away, nor does changing the DNS servers or changing the IPv6 configuration setting2.

I decided to try and troubleshoot it tonight, and discovered that Safari, at least, can connect to the Internet. It just can’t resolve hostnames. If I ping or dig a hostname and paste that IP address into Safari, Safari will, in fact, connect to the Internet fine. If you have this problem, you can see this best by digging www.google.com and then pasting Google’s IP address into Safari’s URL bar.

Diagnosis

Here’s a summary of what this issue looks like to me:

  1. Safari, Mail, iTunes, and Software Update tell me I’m not online.
  2. Firefox works fine.
  3. I can “curl” a URL on the command line and get the HTML back.
  4. Network Diagnostics tells me that my Internet connection is working.
  5. I can ping www.google.com or any other hostname I can remember.
  6. If I copy an IP address from a ping, I can paste it into Safari and get the appropriate web page.3

I’m not sure, but the problem appears to occur a few minutes after waking from sleep. I can browse a few web pages, get a little mail, and then after a few minutes of reading, suddenly I notice that Mail is offline, and I can’t get any new web pages up.

A fix

Just clearing the DNS cache didn’t help me. Neither the command that should work (sudo dscacheutil -flushcache) or the command that had to be used in earlier versions of 10.6 (sudo killall -HUP mDNSResponder) had any effect. And the DNS cache appears to have entries:

  • bash-3.2$ dscacheutil -q host -a name www.google.com
  • name: www.l.google.com
  • alias: www.google.com
  • ip_address: 66.102.7.99
  • ip_address: 66.102.7.104

Restarting mDNSResponder fixed the issue, although I expect it’s a temporary fix:

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

And now I can use Safari, get e-mail, and use Software Update!

I found those commands, and their explanation, in How is DNS used by individual processes?.

Judging from what I’ve read, dscacheutil and mDNSResponder are using different systems, but they try to synchronize between each other; that might be why dscacheutil had entries that Safari couldn’t resolve. Beyond that, I don’t know. Maybe mDNSResponder is getting hung up. Most Apple software probably uses mDNSResponder, whereas being cross-platform software Firefox uses the same system curl, dig, and ping use. And it’s tools like ping and traceroute that, I think, Network Diagnostics uses to determine if there’s a good connection or not.

  1. Except, oddly, Alpine, which isn’t even working on a remote server. All I use it for is reading system mail in the standard Unix mail file. But when this problem strikes, Alpine takes about 65 seconds to start up, as opposed to being instantaneous like it normally is. I have no idea what it’s trying to do that requires a network connection, or why it fails when everything else non-Apple works fine.

  2. I tried these only because in a thread on Apple’s support forum, making a simple change to the Network settings was provided as a solution for what sounded a lot like my problem.

  3. Some hostnames, because they are virtual hosts, will not give me the same web page that I would get by typing their hostname in. But I will get a web page from that site’s hosting provider.

  1. <- Django SuspiciousOperation
  2. Custom ForeignKey managers ->