{"id":4733,"date":"2017-09-29T13:13:57","date_gmt":"2017-09-29T05:13:57","guid":{"rendered":"https:\/\/www.icocean.com\/blog\/?p=4733"},"modified":"2017-09-29T13:14:31","modified_gmt":"2017-09-29T05:14:31","slug":"automatic-vpn-routes-configuration-for-pptp-in-windows-78","status":"publish","type":"post","link":"https:\/\/www.icocean.com\/blog\/?p=4733","title":{"rendered":"Automatic VPN routes configuration for PPTP in Windows 7\/8"},"content":{"rendered":"<p>Published on 2013-06-30<br \/>\nPrerequisites for this article<br \/>\nTo read this article you should understand the following concepts:<br \/>\n&#8211; VPN<br \/>\n&#8211; PPTP<br \/>\n&#8211; routing<br \/>\n&#8211; network and netmask<br \/>\n&#8211; DNS server IP<br \/>\n&#8211; configuring PPTP VPN on Windows 7\/8<\/p>\n<p><strong>The Problem<\/strong><br \/>\nSuppose we have a PC with Windows 8 (or Windows 7) and we have administrator privileges on it. Now we decided to connect to our workplace with PPTP (server is already configured on remote site and it&#8217;s configuration is not covered by this article).<\/p>\n<p>Once we have configured our VPN connection we can see that there are only 2 options to configure IP networks going to VPN tunnel:<\/p>\n<p>1) Use VPN as a default gateway (all packets go to VPN)<br \/>\n2) Use VPN with only one route to the network, based on peer&#8217;s PPTP internal IP address (say if we connected to remote peer with 192.168.15.1 VPN address, we route all 192.168.15.0\/24 network there).<\/p>\n<p>What if we want to route more than one specific networks to VPN and everything else to our default internet gateway?<\/p>\n<p>A special software exists to perform this kind of tasks, that is called &#8216;Connection Manager&#8217; (CM). But this article is not about 3rd party CMs.<\/p>\n<p>All we want is configure custom routes, going to VPN, with native Windows 7\/8 tools, which will be automatically enabled once you connect to remote site (and they will be automatically removed, once you bring the VPN connection down, this is a default Windows behavior).<!--more--><\/p>\n<p><strong>Solution<\/strong><\/p>\n<p>I assume you already have a configured PPTP connection. In my example VPN connection name is &#8216;FarPost VPN&#8217;. Remember it, I will use it in many places. Replace it with the name of your VPN connection.<\/p>\n<p>Suppose we wish to route only the following networks to the VPN:<br \/>\n172.16.1.0\/24<br \/>\n192.168.100.0\/24<\/p>\n<p>Also we want to use DNS servers from the VPN (their addresses should be in one of the above routable networks). Our DNS servers will be 192.168.100.2 and 172.16.1.2.<\/p>\n<p>Step-by-Step:<br \/>\n&#8211; Run &#8216;cmd.exe&#8217; as Administrator.<br \/>\n  Press Windows-F, find Files -> &#8216;cmd.exe&#8217;, right click and select &#8216;Run as Administrator&#8217;<\/p>\n<p>&#8211; Create a directory for your scripts. I will name it &#8216;FarpostVPN&#8217; (run this command in cmd.exe):<\/p>\n<p>mkdir C:\\ProgramData\\Microsoft\\Network\\Connections\\Cm\\FarpostVPN<br \/>\ncd C:\\ProgramData\\Microsoft\\Network\\Connections\\Cm\\FarpostVPN<\/p>\n<p>Select all<\/p>\n<p>Open in new window<\/p>\n<p>&#8211; Create a custom &#8216;route add&#8217; script (also run from cmd.exe):<\/p>\n<p>notepad routes.netsh<\/p>\n<p>Select all<\/p>\n<p>Open in new window<br \/>\nand here is content of our &#8216;routes.netsh&#8217; (don&#8217;t forget to replace &#8216;FarPost VPN&#8217; with your real connection name):<\/p>\n<p>interface ipv4<br \/>\nadd route prefix=172.16.1.0\/24 interface=&#8221;FarPost VPN&#8221; store=active<br \/>\nadd route prefix=192.168.100.0\/24 interface=&#8221;FarPost VPN&#8221; store=active<br \/>\nexit<\/p>\n<p>Select all<\/p>\n<p>Open in new window<br \/>\nsave this script to C:\\ProgramData\\Microsoft\\Network\\Connections\\Cm\\FarpostVPN<\/p>\n<p>&#8211; Now connect to your VPN (this is a trick to locate correct windows Event), if you are not already connected<\/p>\n<p>&#8211; Run Windows event viewer (from cmd.exe run):<\/p>\n<p>eventvwr.exe<\/p>\n<p>Select all<\/p>\n<p>Open in new window<br \/>\nand locate the latest &#8216;Informational&#8217; event here: Windows Logs -> Applications and Services Logs -> Microsoft -> Windows -> Network Profile -> Operational (log name) -> 10000 (event ID).<br \/>\nIn my case the event looks like:<br \/>\nNetwork Connected<br \/>\n      Name: FarPost VPN<br \/>\n      Desc: FarPost VPN<br \/>\n      Type: Unmanaged<br \/>\n      State: Connected<br \/>\n      Category: Public<\/p>\n<p>&#8211; Right click on this event and select &#8216;Attach Task To this Event&#8217;<br \/>\nNow you know what to do, no?<br \/>\nAssign any name and add meaningful description (say &#8220;add routes to FarPost VPN&#8221;)<\/p>\n<p>&#8211; Press Next (you will be on &#8216;When The Event is Logged&#8217; dialog)<br \/>\n&#8211; Press Next again<br \/>\nSelect &#8216;Start a program&#8217; and press &#8216;Next&#8217;<br \/>\n&#8211; on &#8216;Start a program&#8217; dialog enter:<br \/>\nProgram\/script:<br \/>\nnetsh.exe<\/p>\n<p>Select all<\/p>\n<p>Open in new window<br \/>\nAdd arguments:  <\/p>\n<p>exec routes.netsh<\/p>\n<p>Select all<\/p>\n<p>Open in new window<br \/>\nStart in:<\/p>\n<p>C:\\ProgramData\\Microsoft\\Network\\Connections\\Cm\\FarpostVPN\\<\/p>\n<p>Select all<\/p>\n<p>Open in new window<br \/>\npress Next<br \/>\n&#8211; on &#8216;Finish&#8217; dialog check the &#8216;Open the properties dialog when I click Finish&#8217;<br \/>\npress Finish<\/p>\n<p>&#8211; on Task properties dialog change the following:<br \/>\nGeneral tab:<br \/>\n&#8211; check &#8216;Run with highest privileges&#8217;<br \/>\n&#8211; configure for: (select Windows 8 or Vista)<br \/>\nConditions tab:<br \/>\n&#8211; uncheck &#8216;Start the task only if computer runs on AC power&#8217;<br \/>\n&#8211; Start only if the following network connection is available: select your VPN connection<br \/>\npress OK, your task is ready<\/p>\n<p>&#8211; if you missed your task properties, in cmd.exe you can run:<\/p>\n<p>taskschd.msc<\/p>\n<p>Select all<\/p>\n<p>Open in new window<br \/>\nand locate your task here:<br \/>\nTask Scheduler Library -> Event Viewer Tasks<br \/>\nhere you can also &#8216;Enable All Tasks History&#8217; and see when and what codes your task executed in &#8216;History&#8217; tab<\/p>\n<p>&#8211; close &#8216;cmd.exe&#8217;<\/p>\n<p>&#8211; now configure custom DNS servers on your VPN connection<br \/>\nright click on your VPN connection<br \/>\nselect &#8216;Properties&#8217;<br \/>\n&#8216;Networking&#8217; tab -> select &#8216;Internet Protocol Version 4&#8217; -> Properties<br \/>\nselect &#8216;Use the following DNS server addresses&#8217;:<br \/>\nenter Preferred DNS and Alternative server IP (your internal VPN server address, in my example it is 192.168.100.2 and 172.16.1.2)<br \/>\npress &#8216;OK&#8217; and you are done<\/p>\n<p>&#8211; now every time you connect to your VPN server, routes should be added automatically<\/p>\n<p>Regards,<br \/>\nArtyom A. Konovalenko<\/p>\n<p>https:\/\/www.experts-exchange.com\/articles\/11931\/Automatic-VPN-routes-configuration-for-PPTP-in-Windows-7-8.html <\/p>\n","protected":false},"excerpt":{"rendered":"<p>Published on 2013-06-30 Prerequisites for this article  <a href='https:\/\/www.icocean.com\/blog\/?p=4733' class='excerpt-more'>[&#8230;]<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4],"tags":[4170,3073],"class_list":["post-4733","post","type-post","status-publish","format-standard","hentry","category-4","tag-route","tag-vpn","category-4-id","post-seq-1","post-parity-odd","meta-position-corners","fix"],"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/www.icocean.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/4733","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.icocean.com\/blog\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.icocean.com\/blog\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.icocean.com\/blog\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.icocean.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=4733"}],"version-history":[{"count":2,"href":"https:\/\/www.icocean.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/4733\/revisions"}],"predecessor-version":[{"id":4735,"href":"https:\/\/www.icocean.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/4733\/revisions\/4735"}],"wp:attachment":[{"href":"https:\/\/www.icocean.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=4733"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.icocean.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=4733"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.icocean.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=4733"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}