Save your DNS and your SANITY when using VPN on a Mac
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:
- The networking stack on OSX went downhill.
- I joined Splunk.
- I started using a VPN on my Mac (We use Jupiter 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 my 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:
AAARGH!
So you reboot, and then you find out that Github was up all along, the problem was your routing tables on got screwed somehow related to the VPN. 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, I have a cure. This is a cure I learned from the ninjas at my office, it is a little bash alias, and it will save you AND your DNS. Drop it in your .bash_profile
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.
Wait a few seconds, and bring up that webpage again.
You DNS and Sanity are restored!