There was time when using my Mac was bliss form a DNS perspective, I never had to worry about my routing tables getting corrupted. I could always rely on hosts getting resolved, life was good! And then a combination of things happened and well those good old days are gone
- The networking stack on OSX went downhill.
- I joined Splunk.
- I started using a VPN on my Mac (We use Juniper SSL VPN).
- I started having to deal with this now recurring nightmare of my DNS suddenly failing, generally after using the VPN.
If you use a VPN on a Mac, I am sure you’ve seen it. Suddenly you type “https://github.com” in your browser, and you get a 404. “Is Github down?” you ask your co-workers? “Nope, works perfectly fine for me”. “Is hipchat down?”. “Nope, I am chatting away.”
Meanwhile. your browser looks something like this:
So you reboot, and then you find out that Github was up all along, the problem was your routing tables got screwed somehow related to the VPN, either that or the DNS demons have taken over your machine!
After dealing with this constantly, you start to seriously lose your sanity! It will of course always happen at the most inopportune time, like when you are about to present to your execs or walk on stage!
But my friends, there is hope, I have a cure! This is a cure I learned from the wise ninjas at my office (Thank you Danielle and Itay!), it is a little bash alias, and it will save you AND your DNS. Drop it in your .bash_profile and open a new terminal.
alias fixvpn="sudo route -n flush && sudo networksetup -setv4off Wi-Fi && sudo networksetup -setdhcp Wi-Fi"
Next time the DNS demons come to get you, run this baby from the shell. It will excommunicate those demons and quick.
Wait a few seconds, and bring up that webpage again.
You DNS and Sanity are restored!