Apple software stops connecting to the Internet; Firefox continues fine
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:
- Safari, Mail, iTunes, and Software Update tell me I’m not online.
- Firefox works fine.
- I can “curl” a URL on the command line and get the HTML back.
- Network Diagnostics tells me that my Internet connection is working.
- I can ping www.google.com or any other hostname I can remember.
- 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.
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.
↑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.
↑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.
↑
- ELinks—Full-Featured Text WWW Browser
- If you’re looking for a text browser for ensuring page readability, ELinks is a great choice. The useful commands are available as a pull-down menu after you hit the ESC key.
- Firefox
- I personally like Safari a lot, but when I can’t use Safari, Firefox is my browser of choice. It’s a great web browser.
- How is DNS used by individual processes?
- “Essentially there are two DNS resolving mechanisms in Mac OS X. The standard UNIX approach (/etc/resolv.conf) which is used by dig and then the approach used by the rest of the system.”
I've been experiencing the same thing, for perhaps a month, also upon waking from sleep. For me, quitting Mail.app and restarting it seems to do the trick (simply closing Mail is not sufficient, I have to restart it). Your solution is scriptable, however, which is nice.
Jerry at 5:36 a.m. January 22nd, 2011
IqnSM
I’m pretty sure I tried quitting Mail before discovering it was a DNS issue; I know I tried quitting Safari. If/when it happens again (and judging from how often it’s been happening, it probably will), I’ll verify whether quitting Mail.app and then starting it up again will also restore DNS service for me.
capvideo at 7:17 a.m. January 22nd, 2011
tVAhq
No, quitting Mail.app and then reopening it was not enough for my DNS to start working again. I went through the diagnosis above and it was definitely this issue: IP addresses worked in Safari, hostnames did not. Firefox worked, as well as ping on the command line, and Network Diagnostics said my network appeared to be fine. And it happened just about 30 seconds to a minute after waking from sleep. Safari was working fine, and Mail got mail, and then while reading mail I noticed the triangles on the Inbox. And sure enough, Mail no longer thought it was online, and Safari couldn’t reload the page it had in its window.
The unload/load of mDNSResponder fixed the issue immediately.
capvideo at 2:55 p.m. February 11th, 2011
tVAhq
Thanks! This was driving me nuts. Much better than re-booting (which I was doing daily before your post)!
Todd in Albuquerque at 10:04 a.m. April 5th, 2012
9wNry
My computer is doing the same thing, when I shutdown and restart it fixes it, but only for an hour or so.. seems to be getting worse, meaning less time in between it saying I am not connected to the internet and having to restart. I don't understand what to do to fix the problem?
Melissa Sundt in Phoenix az 85086 at 9:57 a.m. May 14th, 2012
1XALQ
Melissa, in my case, it only happens every month or more, so your issue may be a different one. Make sure you test that the command line does still work even though your browser and email don’t. Go to your Applications folder, your Utilities folder, and open “Terminal”.
should return stuff that looks like this:
If it instead says that it can’t do it, then your problem is a different one.
If the ping does work, you don’t need to restart the Mac to fix the problem. Restart mDNSResponder by using the two “sudo launchctl” commands at the bottom of the post under “A Fix”.
It’s still annoying, but at least you can get it over with faster.
Jerry in San Diego at 10:17 a.m. May 14th, 2012
3eqBR
My 2012 MBA and iMac both have this problem. It connects back to the network (wifi or cat 5) fine after a sleep, but the apple applications remain "offline". That is, the applications themselves work fine, except any online aspect of each app. So mail can't connect and download new mail, iPhoto can't get anything from photo stream or send photos to others, Notes won't automatically sync from iCloud, iMessage won't work etc etc. In each case, the solution is to command-Q and then re-open the apps (no reboot required). Like you, I found that Safari experienced fewer problems than other apps and would go offline after a sleep far less often (though it still happened on occasion) and also found that you could 'force' it to work without a re-start of the app, as you also found, most of the time anyway. Apple Support have done various things such as replacing the O/S and also, in the case of my MBA, replacing various hardware components, but the problems persist on both the iMac and the MBA. I don't want to be bothered doing another O/S replacement, which is what Apple Support are trying to do now I've got the same problem on my new iMac, as I know it doesn't work, and I'm not interested in wasting the time nor the 4gb (!) download it involves. As you've not updated this, I wonder if you've had some luck with finding out what is going on and getting a lasting fix. It is not acceptable for apple software to have problems like this, which means quitting and restarting almost every iLife application every time your computer wakes from sleep, yet they don't seem to be doing much about it. For your info, both my computers have only ever run Mountain Lion so I have no comment re Lion not having the same problems.
On the Apple Merry go Round in Australia at 7:08 a.m. January 31st, 2013
G1mi8
It does still happen, but not as often. And I’m still on Snow Leopard, though 10.6.8 now rather than 10.6.6. I haven’t been keeping track, but I think it happens less than every two months now, maybe less than every three months.
For what it’s worth, I have Mountain Lion at work and it never exhibits this problem.
Note that I did not find that Safari experienced fewer problems than other apps. When it happens, it is universal in that all apps that are ever affected by it are always affected when it happens. All apps (such as Firefox) that are not affected by it are never affected by it. The difference appears to be whether the app uses mDNSResponder or not.
The easiest way to see if you are having the same problem as described here is to go to the Terminal and type something like “ping www.google.com” the next time it happens. Since ping doesn’t use mDNSResponder, it will work even though Mail and Safari do not work.
If ping also cannot connect, then you have a different problem; your network connection itself is most likely down.
Jerry Stratton in San Diego at 10:27 a.m. January 31st, 2013
3eqBR