{"id":1591,"date":"2013-04-02T14:04:10","date_gmt":"2013-04-02T14:04:10","guid":{"rendered":"http:\/\/blog.designed79.co.uk\/?p=1591"},"modified":"2013-04-02T14:09:55","modified_gmt":"2013-04-02T14:09:55","slug":"use-vpn-for-specific-sites-on-mac-os-x","status":"publish","type":"post","link":"https:\/\/blog.designed79.co.uk\/?p=1591","title":{"rendered":"Use VPN for specific sites, on Mac OS X"},"content":{"rendered":"<p>The problem is, routing through VPNs in Mac OS X is kind of an all-or-nothing deal: either it uses the VPN for everything or it uses it only for IP addresses in the VPN\u2019s subnet, with the lacodeer being the default behaviour in Mac OS X 10.6.<\/p>\n<p>I want finer control. Specifically, I want OS X to use the VPN for specific websites. It turns out this isn\u2019t too hard.<\/p>\n<p>Solution: To route specific websites (i.e. journal publishers) through my university VPN, I created \/etc\/ppp\/ip-up with the following contents:<\/p>\n<div class=\"codecolorer-container text default\" style=\"overflow:auto;white-space:nowrap;height:300px;\"><div class=\"text codecolorer\">&nbsp; &nbsp; #!\/bin\/bash<br \/>\n&nbsp; &nbsp; #<br \/>\n&nbsp; &nbsp; # Script which handles the routing issues as necessary for pppd.<br \/>\n&nbsp; &nbsp; # When the ppp link comes up, this script is called with the following<br \/>\n&nbsp; &nbsp; # parameters:<br \/>\n&nbsp; &nbsp; # &nbsp; &nbsp; &nbsp; $1 &nbsp; &nbsp; &nbsp;the interface name used by pppd (e.g. ppp3)<br \/>\n&nbsp; &nbsp; # &nbsp; &nbsp; &nbsp; $2 &nbsp; &nbsp; &nbsp;the codey device name<br \/>\n&nbsp; &nbsp; # &nbsp; &nbsp; &nbsp; $3 &nbsp; &nbsp; &nbsp;the codey device speed<br \/>\n&nbsp; &nbsp; # &nbsp; &nbsp; &nbsp; $4 &nbsp; &nbsp; &nbsp;the local IP address for the interface<br \/>\n&nbsp; &nbsp; # &nbsp; &nbsp; &nbsp; $5 &nbsp; &nbsp; &nbsp;the remote IP address<br \/>\n&nbsp; &nbsp; # &nbsp; &nbsp; &nbsp; $6 &nbsp; &nbsp; &nbsp;the parameter specified by the 'ipparam' option to pppd<br \/>\n&nbsp; &nbsp; #<br \/>\n&nbsp; &nbsp; <br \/>\n&nbsp; &nbsp; ## Routing setup for VPN<br \/>\n&nbsp; &nbsp; <br \/>\n&nbsp; &nbsp; # Array of IP addresses of the VPN server(s)<br \/>\n&nbsp; &nbsp; # I have it grab the list of round-robin'ed IP addresses based on the domain name<br \/>\n&nbsp; &nbsp; VPN_HOSTS=$(dig +short inside.mcgill.ca)<br \/>\n&nbsp; &nbsp; <br \/>\n&nbsp; &nbsp; # Array of hostns to route for<br \/>\n&nbsp; &nbsp; # These are the domain names and IP addresses that will be accessed through the VPN<br \/>\n&nbsp; &nbsp; VPN_ROUTE_FOR_HOSTS=(www.elsevier.com www.sciencedirect.com www.thelancet.com www.cmaj.ca scholar.google.com ncbi.nlm.nih.gov bmj.com)<br \/>\n&nbsp; &nbsp; <br \/>\n&nbsp; &nbsp;<br \/>\n&nbsp; &nbsp; &nbsp; &nbsp;<br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; # Add the routes<br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; for k in ${VPN_ROUTE_FOR_HOSTS[@]} ; do<br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; for l in $(dig +short $k) ; do<br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; \/sbin\/route add -host $l -interface $1<br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; done<br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; done<\/div><\/div>\n<p>Put your specific values into VPN_HOSTS and VPN_ROUTE_FOR_HOSTS. Don\u2019t forget to chmod a+x \/etc\/ppp\/ip-up. The routes will be added when you connect to the VPN and disappear when you disconnect from it.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>The problem is, routing through VPNs in Mac OS X is kind of an all-or-nothing deal: either it uses the VPN for [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-1591","post","type-post","status-publish","format-standard","hentry","category-info-on-tech"],"_links":{"self":[{"href":"https:\/\/blog.designed79.co.uk\/index.php?rest_route=\/wp\/v2\/posts\/1591","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.designed79.co.uk\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.designed79.co.uk\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.designed79.co.uk\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.designed79.co.uk\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1591"}],"version-history":[{"count":0,"href":"https:\/\/blog.designed79.co.uk\/index.php?rest_route=\/wp\/v2\/posts\/1591\/revisions"}],"wp:attachment":[{"href":"https:\/\/blog.designed79.co.uk\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1591"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.designed79.co.uk\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1591"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.designed79.co.uk\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1591"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}