OpenVPN is a wonderful VPN system, but it’s not so simple to set up on Windows. When I first created this how-to, there wasn’t a real cohesive and precise instruction set on how to get an OpenVPN server working on Windows where Windows clients could have all traffic go through the VPN (the alternative is where only directed traffic goes through the VPN: Split tunneling). I prefer all my traffic going through a VPN when connected, less likely for information to leak out.
1. Throughout this guide I will use two words: over and over again: server and client1. Feel free to modify these, but be sure to modify them EVERYWHERE they are repeated. To help you out I bolded and italicized them everywhere you should change them (except in the config files, they need to be changed in those as well)
2. Everywhere you see quotation marks, it is to signify what you should type (which would be the stuff inside the quotation marks), DO NOT TYPE THE QUOATATION MARKS UNLESS OTHERWISE SPECIFIED!
3. I know this seems long, but it really isn’t, I just broke everything down into as basic of steps as I could and explain everything as thoroughly as I can. In the end, it pays off, you have a secure multi-client VPN offering that definitely beats PPTP in terms of security and robustness.
4. A relatively common practice with OpenVPN is to configure it to use TCP port 443, as this is the port normally associated with HTTPS, so even the most most draconian of firewalls won’t block it. I don’t cover this, instead cover OpenVPN using the default port of 1194 UDP. Changing it is simple, just edit the server and client configuration files to use proto tcp and port 443. Make sure to also change your forwarded port and firewall rules to match as well.
5. This guide uses the 192.168.137.0/24 block for the OpenVPN network. This is the default for Internet Connection Sharing (a needed utility to get Internet through OpenVPN on Windows) for Windows 7, which is why I chose it (it should also be the default for Windows Vista, though I cannot test this) On Windows XP, ICS uses 192.168.0.0/24 by default, which isn’t very useful for a VPN (as it’s a popular subnet and would lead to conflicts in various situations). If you wish to change the subnet for OpenVPN, you must change it in the config file for the server as well as for ICS. This can be done through a registry setting. In HKLMSystemCurrentControlSetservicesSharedAccessParameters you will need to change ScopeAddress and ScopeAddressBackup to the first IP address in the range you wish to use. I am not certain if Windows XP can change it or not, but it’s worth a shot. Here is a registry file of the 192.168.137.1 ICS configuration, change the network numbers and run it to change to a different subnet (or do it manually). You can also find it on PasteBin.
6. You will also need to know your public IP address or set up a Dynamic DNS service. This can be done by visiting http://www.whatismyip.com/ on your server. Better is to set up no-ip on your server and use their free dynamic dns service (as it’ll work even if your home IP changes). You will need to do this for PPTP VPN servers and SSH servers. I will mention this again when we get to the client configuration file.
- run wf.msc
- Click Inbound rules on the left panel, and on the right panel click “New Rule…”
- Select Port for the rule type and click next. Image of steps 2-3Â
- Select UDP and enter in port 1194 and click next
- Select Allow the connection and click next
- Select which networks to allow the rule, to be safe, allow for all and click next
- Name the rule “openvpn in” (without quotes) and click finish.
- Download OpenVPN onto the will-be OpenVPN server and run the installer (as administrator if you are using Windows Vista/7)
- . When you get to the “Install Location” part of the setup, I highly recommend installing it to C:OpenVPN rather than the default install path. Especially on Vista/7 as this will save you headaches. Proceed to finish the install
- Navigate to the installation folder (C:OpenVPN if you followed my advice), then enter the config folder (C:OpenVPNconfig).
- Here, create a file server.ovpn. It should look like this:Â http://pastebin.com/wU0MeHKLAbout the server.ovpn configuration file:You can modify the port number to any number you want, just remember what you set it to. Same for proto (short for protocol) you can change that to tcp, just remember you did so (udp will give you better performance, but may be blocked on some draconian networks)
Line 5 is one that may need changing. First, you need to keep “server” as server (it’s a configuration line dictating the VPN server IP range). Later on we’ll enable Internet Connection Sharing and you may need to change 192.168.137.0 to match any IP address being forced on you by Internet Connection Sharing (for me this was 192.168.137.0/24 but it may be different for you) I’ll remind you of this when we get to Server Configuration.
You need to specify the DNS servers, I chose OpenDNS as it makes it easy to test if the tunnel is being used without running something like Wireshark (which is nice), but any DNS server will do.
- Open up the command line (As administrator on Vista/7)
- type “cd C:OpenVPNeasy-rsa” (without quotes, everywhere you see quotes from now on, it’s to signify what you should type) and hit enter
- type “init-config” and hit enter
- navigate to C:OpenVPNeasy-rsa in explorer if you haven’t already. find the vars.bat file, right-click it and edit it
- Edits to make to vars.bat:Mandatory: change HOME path from “%programfiles%OpenVPNeasy-rsa” to “C:OpenVPNeasy-rsa” (if you don’t do this you will get an error complaining about unable to write random state)You also need to fill (found near the bottom of the file):
Technically, any value will do, including the default ones, but I suggest filling them in with your information
You also need to set KEY_NAME and KEY_OU . I usually set name to my name and OU to VPNers just because it’s simple.
——– DO NOT CHANGE KEY_CN, IT NEEDS TO BE CONFIGURED ON A PER-RUN BASIS ———-
- Save vars.bat and return to the command line (reopen it as administrator and navigate back to C:OpenVPNeasy-rsa if you closed it)
- type “vars” and hit enter
- type “clean-all” and hit enter (it’s normal for this to kick up an error, it just means the folder “keys” didn’t exist before it was ran)
- type “build-ca” and hit enter. This will start the creation process for the ca.crt file. You will be prompted for various things. The default values are fine until you get to COMMON NAME
- WHEN YOU GET TO Common Name enter in “server“
- “build-key-server server“
- Leave the password blank unless you want to read OpenVPN documentation. same for company name
- answer “y” to signing and committing to the certificates.
- type “build-dh” and hit enter
- copy ca.crt, server.crt, server.key, and dh1024.pem from the keys folder in easy-rsa to C:OpenVPNconfig
- Â type “build-key client1” and hit enter
- WHEN YOU GET TO Common Name enter in “client1“
- Leave the password blank unless you want to read OpenVPN documentation. same for company name
- answer “y” to signing and committing to the certificates.
- Install OpenVPN on the client computer EXACTLY the same as on the server (ok, it doesn’t really need to be exactly the same, I’m just too lazy to tell you what you do and don’t need)
- copy ca.crt, client1.crt, and client1.key from the server’s keys folder to the client computer’s OpenVPN config folder (C:OpenVPNconfig if you installed it like I said)
- in the config folder on the client, you will need to create a client1.ovpn file. It should look like this:Â http://pastebin.com/42ekkJtL
About the client configuration file:
You need to use the same protocol as you specified on the server configuration file.
On line 5, for remote, you need to specify the PUBLIC IP address of the server OR the DNS entry for it. Refer to Note #6 for this information. After the ip address or DNS listing, specify the port. This needs to be the same port as in the server configuration file.
Almost done! Just have some configuration left on the server to go.
- On the server open up services (run services.msc). Find OpenVPN, right-click it and go to properties. Set it to automatic and start it.
- Â Still on the server in services, find Routing and Remote Access (shorthand: RRAS). Set it to automatic and start it. NOTE: At least in a couple of my goes with this, enabling RRAS made my network indicator in the notifications tray signify I had no connection — I Still had a connection despite being told otherwise. It only happened on a few of my computers, so it may or may not happen to you (if it does, see if you can access any website. If you can there’s no problem)
- You will need to modify a registry entry, so open up regedit and go to HKEY_LOCAL_MACHINESYSTEMCurrentControlSetServicesTcpipParameters. In there change IPEnableRouter to 1 (defualt is 0).
IPEnableRouter.reg file download | PasteBin
- You may need to reboot before the registry change takes effect
- Still on the server, go Control Panel->Network and Sharing Center and click on “Change Adapter Settings“
- If you use my config it is necessary to change the TAP name (as the default name is random). Right-click the adapter that says TAP-Win32(or WIN-64) Adapter and select “Rename“. Rename it to “MyTap”.
- Right-click the newly-named MyTap and go to properties. Uncheck IPv6 if it’s available (Vista/7 + some XP computers with it configured).Now we go onto Internet Connection Sharing (ICS) configuration. You may wish to review Note #5 as it covers some details on how to use a different subnet, as well as the “Some Things Very Important To Note” section for possible issues. A reminder is my guide assumes you are using 192.168.137.0/24, which is not the case on Windows XP. Edit as appropriate.
- This part is not necessary if you have checked the registry entry for ICS and made sure it is correct for your needs, but is a useful way to double-check as you’ll get a warning popup. While still having the MyTap Properties open, Select IPv4 and click properties. Give it a static IP of 192.168.137.1 with a 255.255.255.0 subnet mask.
- Right-click your LAN adapter (the one you gave a static IP in step zero) and go to Properties. Go to the sharing tab (advanced on Windows XP) and check “Allow other computers to connect through this computer’s Internet Connection”
- If there is a drop-down list you can select from, select MyTap. If not, don’t worry: that just means you have no other adapters to share with other than MyTap. Image of Steps 9+10
- Uncheck the lower box titled “Allow other network users to control or disable the shared Internet Connection” if it is checked.
- Click OK. If you did optional step 8 for Server Configuration, you’ll get a popup that says something about how MyTap will be set to 192.168.137.1. If yours said a different IP address, you will need to modify server.ovpn to use that subnet (same first 3 sets of numbers, last one a zero) and restart the OpenVPN service, alternatively you can set the ICS network range in your registry. Run this registry file to use the guide’s 192.168.137.1 (Pastebin) or configure it manually using regedit and navigating to HKLMSystemCurrentControlSetservicesSharedAccessParameters and editing ScopeAddress and ScopeAddressBackup to use the desired IP address range (you specify the first IP address in the range). You can check to make sure that the IP address for MyTap is correct by running ipconfig /all in the command line and making sure it matches that in your server.ovpn config file.
Now you just need to port forward for OpenVPN so you can access it over the Internet.
- Still on the client, go Control Panel->Network and Sharing Center and click on “Change Adapter Settings“
- Â If you use my config it is necessary to change the TAP name (as the default name is random). Right-click the adapter that says TAP-Win32(or WIN-64) Adapter and select “Rename“. Rename it to “MyTap”.
- You can try out OpenVPN now on your LAN to make sure all is working. Just change your client1.ovpn to connect to your server’s LAN ip address (NOT the address you set for MyTAP on the server, but the static IP you set for the LAN adapter).
- Launch OpenVPN GUI (as Administrator on Vista/7). A tray Icon should appear for OpenVPN (a little red-monitored computer with a globe). Right-click it and select “Connect”
- A window like this will appear. After a few seconds to a minute, you should hopefully connect and be assigned an IP address. To verify traffic is going through the tunnel, assuming you used OpenDNS, you can test it simply using an OpenDNS check.
I know it’s been a lot of work, but it’s worth it. You now have a secure basic VPN setup More robust than Microsoft’s default PPTP offering as well as allowing multiple clients. You can improve the security by looking into ta.key, maxclients, client filtering, choosing the cipher, and password authentication. You’ll need to go elsewhere to learn how to do these, or I may cover them in a future post. Finally, there are a few things you should know
Some Things Very Important To Note
- If you have issues with resolving DNS, uncomment register-dns from the client file.
- On some networks with a short dhcp timeout, your client may have issues with getting a new address lease due to OpenVPN sending the request through the VPN. Disconnecting from OpenVPN and running “ipconfig /release” followed by “ipconfig /renew” in the command prompt will solve the issue (until it times out again).
- Internet Connection Sharing (ICS) is a tricky one, but I’ve gotten it mostly figured out through the SharedAccess registry options. You can read up on configuring ICS here. On Windows XP it uses 192.168.0.1 by default and I’ve yet to verify if that can be changed.
- Strictly speaking, the subnetting you are giving your OpenVPN server may not be absolutely correct. This doesn’t matter for a handful (3) clients, but it may stop you from having too many clients. This appears to either be related to the version of Windows used, related to the NIC used, or related to whether the NIC used is a wireless NIC and cannot be changed. You should get subnet mask of 255.255.255.0, but may get less (lowest I got was 255.255.255.252 — 3 clients + the server would max that out). When the OpenVPN client should pull the correct information when it connects, so as long as you don’t exceed the limit, it’s not an issue. Slightly related is the below:
- I don’t know if this was because my virtual machine is crashy, but I noticed that the MyTap adapter would randomly change to using APIPA (Automatic Private IP-Adressing) and therefore having the 169.254.0.0/16 block. It’s simple enough to fix. NOTE: This happens when RRAS runs into an issue and the DHCP server fails, to fix this issue, follow the below 3 steps:
First, disable sharing on the LAN adapter.
Second, reset the MyTap to use a static IPv4 address (IP and default gateway the same, in my case 192.168.137.1).
Third, re-enable sharing on the LAN adapter for MyTap.
- I suggest disabling sleep/hibernation on the server (I mean, if the server isn’t online when you need to connect, it’s kinda useless) anyway. And whenever you reboot for updates, just check to make sure the MyTap properly has the first IP address in the block your OpenVPN server gives.
- I’ve yet to find a way to get the OpenVPN network to be identified by anything less than a Public Network on Windows 7. It doesn’t make much of a big deal unless you want to access network shares on the OpenVPN server (which may not be possible since Windows may block sharing since it’s a public network). NOTE: This is due to OpenVPN’s network not having a default gateway. Some steps on potential workarounds can be found on the Internet.