Home > Others, Programming > Save your DNS and your SANITY when using VPN on a Mac

Save your DNS and your SANITY when using VPN on a Mac

Screen Shot 2015-10-01 at 7.08.31 AM

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.

Screen Shot 2015-10-01 at 7.09.48 AM

Wait a few seconds, and bring up that webpage again.

Screen Shot 2015-10-01 at 7.09.57 AM

You DNS and Sanity are restored!

Categories: Others, Programming Tags:
  1. No comments yet.
  1. No trackbacks yet.
You must be logged in to post a comment.