OpenVPN Community on Windows Azure by Zane J Chua

OpenVPN Community on Windows Azure

Looking for a guide to get the OpenVPN Community Version on Azure? Follow the guide below.

So first up, What do we need?

1. 30-Day Trial Azure Subscription [link]
2. A little bit of knowledge of Linux shell commands
3. PuTTY [link]
4. OpenVPN GUI [link]

Right. Now that we’ve gone through the pre-requisites, let’s move on to the fun part.

First up, we gotta head into Azure and create a virtual machine. Let’s quick create a machine as seen below.
A shared core and 768MB of RAM is more than enough for just an OpenVPN server as the overhead isn’t too large.
If you want to change the region to another region, go ahead but leave the rest as defaults.
Note down the password you use and the username.
Once you press the create button, give it a little bit for Azure to set-up everything and then proceed to the next step once you see it’s Status in Azure has been updated to “Running” with a green tick at the left.

Windows Azure

Now we have to configure some endpoints on the virtual machine itself as to make sure that your internet traffic is able to reach the virtual machine.

Go to the Endpoints Tab in your Virtual Machine once it’s been created and hit the add button at the bottom. Both buttons have been highlighted in the image below.

Windows Azure Virtual Machine Endpoints

Once you select add, you will be presented with a small pop-up wizard. Configure it according to the two images below

Endpoints Configuration Step 1

Endpoints Configuration Step 2

If it is done correctly, you should have an Endpoints tab looking like the one below.

Virtual Machine Endpoints Tab

If all is good, it’s time to move on to configuring the virtual machine you just set-up!

Now’s the time to fire up PuTTY that you downloaded just a moment ago.Launching PuTTY

Fill up the relevant details in this format:
username@dnsname
Example:
azureuser@spiffyrocks.cloudapp.net

Hit Open to start connecting to the virtual machine.

PuTTY Login Details

You will most likely get a warning like the one below but just hit yes.

PuTTY Security Alert

Next up you’ll have to key your password into the black box, don’t worry if you do not see your password being typed and just continue typing it and hit the Enter key when you’re done.

PuTTY Login

You should be logged into your Azure Virtual machine now and should see something similar to the image below.

PuTTY Logged In

Now, let’s proceed onto this by just typing commands into the box above. Each line means a new command.

sudo -i
apt-get install openvpn easy-rsa
mkdir /etc/openvpn/easy-rsa/
cp -r /usr/share/easy-rsa/* /etc/openvpn/easy-rsa/
cd /etc/openvpn/easy-rsa/
source vars
./clean-all
./build-ca
./build-key-server spiffyrocks
./build-dh
cd keys/
cp spiffyrocks.crt spiffyrocks.key ca.crt dh1024.pem /etc/openvpn/
nano /etc/sysctl.conf

*Note: You will have to enter the details accordingly to generate the certificates and answer ‘y’ during the installation of packages or the signing of certificates. When executing the command ./build-key-server, instead of using ‘spiffyrocks’ you can choose to use your own name, all you have to do is substitute accordingly.

*Note 2: If you are using the newest Long Term Support of Ubuntu which is 14.04, the ./build-dh command automatically generates a 2048 bit diffie-hellman. You would have to replace dh1024.pem with dh2048.pem instead. And in the below openvpn configuration file you would have to find dh1024.pem and replace it with dh2048.pem

Now you have to edit a line in this file.
Look for this section in the file by using your arrow key to scroll down the file

# Uncomment the next line to enable packet forwarding for IPv4
#net.ipv4.ip_forward=1

Change this section to:

# Uncomment the next line to enable packet forwarding for IPv4
net.ipv4.ip_forward=1

Then press Ctrl + O and Enter then press Ctrl + X

Now let’s set-up the OpenVPN Configuration files on the server.

cp /usr/share/doc/openvpn/examples/sample-config-files/server.conf.gz /etc/openvpn/
gzip -d /etc/openvpn/server.conf.gz
nano /etc/openvpn/server.conf

Here we are back in nano (nano is a Text Editor) again and let’s edit this configuration file now.
Make the relevant changes as listed below:

From:

# TCP or UDP server?
;proto tcp
proto udp

To:

# TCP or UDP server?
proto tcp
;proto udp

From:

ca ca.crt
cert server.crt
key server.key # This file should be kept secret

To:

ca ca.crt
cert spiffyrocks.crt
key spiffyrocks.key # This file should be kept secret

From:

# (The OpenVPN server machine may need to NAT
# or bridge the TUN/TAP interface to the internet
# in order for this to work properly).
;push “redirect-gateway def1 bypass-dhcp”

To:

# (The OpenVPN server machine may need to NAT
# or bridge the TUN/TAP interface to the internet
# in order for this to work properly).
push “redirect-gateway def1 bypass-dhcp”

From:

# The addresses below refer to the public
# DNS servers provided by opendns.com.
;push “dhcp-option DNS 208.67.222.222”
;push “dhcp-option DNS 208.67.220.220”

To:

# The addresses below refer to the public
# DNS servers provided by opendns.com.
push “dhcp-option DNS 208.67.222.222”
push “dhcp-option DNS 208.67.220.220”

Now once you have all of it done,
Press Ctrl + O and Enter then press Ctrl + X

We have to edit one more file on the virtual machine and then we should be pristine

nano /etc/rc.local

NOTE: PLEASE DO NOT COPY AND PASTE THE LINE CHANGE BELOW. TYPE IT OUT.

Change the file according to below.
From:

# By default this script does nothing.
exit 0

To:

# By default this script does nothing.
iptables -t nat -A POSTROUTING -s “10.8.0.0/24” -j MASQUERADE
exit 0

We now need to generate keys so that you’re able to connect to your VPN Server.
All we need to do is run the following commands in PuTTY.

cd /etc/openvpn/easy-rsa/
source vars
./build-key client1
cd keys/

Here comes the slightly tricky part. We need to get the generated certificates and keys out of the server.
To do this, we will just use PuTTY and copy the certificates into a file.
Run the following commands one by one to view the file and select the text with your mouse and it will be automatically copied.

nano ca.crt
nano client1.crt
nano client1.key

You don’t even have to right click to copy, It should look something like below when you have selected the text.
Once that’s done, open up a blank text file in NotePad, paste it inside and save it with the proper extension respectively(.crt, .key)
Selection of Content in PuTTY
We will be needing to start the OpenVPN service and also reboot the virtual machine to make some of the changes take effect. Run the following commands:

service openvpn start
reboot

I will be providing you with a simple client configuration file below which you will need to change the remote address which is currently ‘spiffyrocks.cloudapp.net’ and save it as client.ovpn on your computer.

client.ovpn

client
dev tun
proto tcp
remote spiffyrocks.cloudapp.net 1194
resolv-retry infinite
nobind
persist-key
persist-tun
ca ca.crt
cert client1.crt
key client1.key
ns-cert-type server
comp-lzo
verb 3

After doing this, you should have 4 files which are
ca.crt
client1.crt
client1.key
client.ovpn

*Note: I assume that you have installed the 64bit version of OpenVPN GUI. If you installed the 32bit version of OpenVPN GUI, you should copy the files into C:\Program Files (x86)\OpenVPN\config instead.

Copy these files into C:\Program Files\OpenVPN\config and it should look like the folder below.

OpenVPN Config Folder

Time to fire up OpenVPN GUI and test it out against our new Azure hosted OpenVPN Server!
Right Click and run the OpenVPN GUI as Administrator.
OpenVPN should appear as a tray icon at the bottom right, right click it and press connect!
You should get a similar window as below when it’s connecting

OpenVPN Connecting in Progress

And if you followed all the steps correctly, you should see your vpn connected like below! Woohoo!

OpenVPN Connected

Now just a quick test to see if your IP Changed. It worked! My IP Changed and now it seems like my internet is from the US when I’m actually a few thousand miles away. Pat yourself on the back, you’ve just earned yourself a medal.

who.is

 

Extras:

For students who just started Polytechnic and you realise that your school internet blocks certain sites you want to visit, you can also follow my guide. However, the only major change you need to make is that anywhere that i specify ‘1194’ you need to change it to ‘443’ and it should work.

Related Posts

3 Responses to “OpenVPN Community on Windows Azure”

  1. Avatar

    Kevin

    Hi , I followed the steps exactly and successfully connected to the VPN, but after I connected, I cannot get online any more. Do you know what’s the problem with it ?

    my IP address is 10.8.0.6, here is my logs:

    Thu Mar 27 17:04:17 2014 OpenVPN 2.3.2 x86_64-w64-mingw32 [SSL (OpenSSL)] [LZO] [PKCS11] [eurephia] [IPv6] built on Aug 22 2013
    Enter Management Password:
    Thu Mar 27 17:04:17 2014 MANAGEMENT: TCP Socket listening on [AF_INET]127.0.0.1:25340
    Thu Mar 27 17:04:17 2014 Need hold release from management interface, waiting…
    Thu Mar 27 17:04:18 2014 MANAGEMENT: Client connected from [AF_INET]127.0.0.1:25340
    Thu Mar 27 17:04:18 2014 MANAGEMENT: CMD ‘state on’
    Thu Mar 27 17:04:18 2014 MANAGEMENT: CMD ‘log all on’
    Thu Mar 27 17:04:18 2014 MANAGEMENT: CMD ‘hold off’
    Thu Mar 27 17:04:18 2014 MANAGEMENT: CMD ‘hold release’
    Thu Mar 27 17:04:18 2014 Socket Buffers: R=[65536->65536] S=[65536->65536]
    Thu Mar 27 17:04:18 2014 MANAGEMENT: >STATE:1395957858,RESOLVE,,,
    Thu Mar 27 17:04:18 2014 Attempting to establish TCP connection with [AF_INET]191.234.57.53:1194
    Thu Mar 27 17:04:18 2014 MANAGEMENT: >STATE:1395957858,TCP_CONNECT,,,
    Thu Mar 27 17:04:18 2014 TCP connection established with [AF_INET]191.234.57.53:1194
    Thu Mar 27 17:04:18 2014 TCPv4_CLIENT link local: [undef]
    Thu Mar 27 17:04:18 2014 TCPv4_CLIENT link remote: [AF_INET]191.234.57.53:1194
    Thu Mar 27 17:04:18 2014 MANAGEMENT: >STATE:1395957858,WAIT,,,
    Thu Mar 27 17:04:18 2014 MANAGEMENT: >STATE:1395957858,AUTH,,,
    Thu Mar 27 17:04:18 2014 TLS: Initial packet from [AF_INET]191.234.57.53:1194, sid=164dbcef 0070eeec
    Thu Mar 27 17:04:18 2014 VERIFY OK: depth=1, C=US, ST=IL, L=Chicago, O=Northwestern, OU=McCormick, CN=UBVPN, name=Kevin, emailAddress=hengshi2015@u.northwestern.edu
    Thu Mar 27 17:04:18 2014 VERIFY OK: nsCertType=SERVER
    Thu Mar 27 17:04:18 2014 VERIFY OK: depth=0, C=US, ST=IL, L=Evanston, O=Northwestern, OU=McCormick, CN=ubvpn, name=HengShi, emailAddress=hengshi2015@u.northwesten.edu
    Thu Mar 27 17:04:19 2014 Data Channel Encrypt: Cipher ‘BF-CBC’ initialized with 128 bit key
    Thu Mar 27 17:04:19 2014 Data Channel Encrypt: Using 160 bit message hash ‘SHA1’ for HMAC authentication
    Thu Mar 27 17:04:19 2014 Data Channel Decrypt: Cipher ‘BF-CBC’ initialized with 128 bit key
    Thu Mar 27 17:04:19 2014 Data Channel Decrypt: Using 160 bit message hash ‘SHA1’ for HMAC authentication
    Thu Mar 27 17:04:19 2014 Control Channel: TLSv1, cipher TLSv1/SSLv3 DHE-RSA-AES256-SHA, 1024 bit RSA
    Thu Mar 27 17:04:19 2014 [ubvpn] Peer Connection Initiated with [AF_INET]191.234.57.53:1194
    Thu Mar 27 17:04:20 2014 MANAGEMENT: >STATE:1395957860,GET_CONFIG,,,
    Thu Mar 27 17:04:21 2014 SENT CONTROL [ubvpn]: ‘PUSH_REQUEST’ (status=1)
    Thu Mar 27 17:04:21 2014 PUSH: Received control message: ‘PUSH_REPLY,redirect-gateway def1 bypass-dhcp,dhcp-option DNS 208.67.222.222,dhcp-option DNS 208.67.220.220,route 10.8.0.1,topology net30,ping 10,ping-restart 120,ifconfig 10.8.0.6 10.8.0.5’
    Thu Mar 27 17:04:21 2014 OPTIONS IMPORT: timers and/or timeouts modified
    Thu Mar 27 17:04:21 2014 OPTIONS IMPORT: –ifconfig/up options modified
    Thu Mar 27 17:04:21 2014 OPTIONS IMPORT: route options modified
    Thu Mar 27 17:04:21 2014 OPTIONS IMPORT: –ip-win32 and/or –dhcp-option options modified
    Thu Mar 27 17:04:21 2014 do_ifconfig, tt->ipv6=0, tt->did_ifconfig_ipv6_setup=0
    Thu Mar 27 17:04:21 2014 MANAGEMENT: >STATE:1395957861,ASSIGN_IP,,10.8.0.6,
    Thu Mar 27 17:04:21 2014 open_tun, tt->ipv6=0
    Thu Mar 27 17:04:21 2014 TAP-WIN32 device [Local Area Connection] opened: \\.\Global\{E4CDB45D-020A-4358-980F-C08D203A5D3D}.tap
    Thu Mar 27 17:04:21 2014 TAP-Windows Driver Version 9.9
    Thu Mar 27 17:04:21 2014 Notified TAP-Windows driver to set a DHCP IP/netmask of 10.8.0.6/255.255.255.252 on interface {E4CDB45D-020A-4358-980F-C08D203A5D3D} [DHCP-serv: 10.8.0.5, lease-time: 31536000]
    Thu Mar 27 17:04:21 2014 Successful ARP Flush on interface [23] {E4CDB45D-020A-4358-980F-C08D203A5D3D}
    Thu Mar 27 17:04:26 2014 TEST ROUTES: 2/2 succeeded len=1 ret=1 a=0 u/d=up
    Thu Mar 27 17:04:26 2014 C:\Windows\system32\route.exe ADD 191.234.57.53 MASK 255.255.255.255 10.101.230.1
    Thu Mar 27 17:04:26 2014 ROUTE: CreateIpForwardEntry succeeded with dwForwardMetric1=25 and dwForwardType=4
    Thu Mar 27 17:04:26 2014 Route addition via IPAPI succeeded [adaptive]
    Thu Mar 27 17:04:26 2014 C:\Windows\system32\route.exe ADD 165.124.49.132 MASK 255.255.255.255 10.101.230.1
    Thu Mar 27 17:04:26 2014 ROUTE: CreateIpForwardEntry succeeded with dwForwardMetric1=25 and dwForwardType=4
    Thu Mar 27 17:04:26 2014 Route addition via IPAPI succeeded [adaptive]
    Thu Mar 27 17:04:26 2014 C:\Windows\system32\route.exe ADD 0.0.0.0 MASK 128.0.0.0 10.8.0.5
    Thu Mar 27 17:04:26 2014 ROUTE: CreateIpForwardEntry succeeded with dwForwardMetric1=30 and dwForwardType=4
    Thu Mar 27 17:04:26 2014 Route addition via IPAPI succeeded [adaptive]
    Thu Mar 27 17:04:26 2014 C:\Windows\system32\route.exe ADD 128.0.0.0 MASK 128.0.0.0 10.8.0.5
    Thu Mar 27 17:04:26 2014 ROUTE: CreateIpForwardEntry succeeded with dwForwardMetric1=30 and dwForwardType=4
    Thu Mar 27 17:04:26 2014 Route addition via IPAPI succeeded [adaptive]
    Thu Mar 27 17:04:26 2014 MANAGEMENT: >STATE:1395957866,ADD_ROUTES,,,
    Thu Mar 27 17:04:26 2014 C:\Windows\system32\route.exe ADD 10.8.0.1 MASK 255.255.255.255 10.8.0.5
    Thu Mar 27 17:04:26 2014 ROUTE: CreateIpForwardEntry succeeded with dwForwardMetric1=30 and dwForwardType=4
    Thu Mar 27 17:04:26 2014 Route addition via IPAPI succeeded [adaptive]
    Thu Mar 27 17:04:26 2014 Initialization Sequence Completed
    Thu Mar 27 17:04:26 2014 MANAGEMENT: >STATE:1395957866,CONNECTED,SUCCESS,10.8.0.6,191.234.57.53
    Thu Mar 27 17:04:41 2014 C:\Windows\system32\route.exe DELETE 10.8.0.1 MASK 255.255.255.255 10.8.0.5
    Thu Mar 27 17:04:41 2014 Route deletion via IPAPI succeeded [adaptive]
    Thu Mar 27 17:04:41 2014 C:\Windows\system32\route.exe DELETE 191.234.57.53 MASK 255.255.255.255 10.101.230.1
    Thu Mar 27 17:04:41 2014 Route deletion via IPAPI succeeded [adaptive]
    Thu Mar 27 17:04:41 2014 C:\Windows\system32\route.exe DELETE 165.124.49.132 MASK 255.255.255.255 10.101.230.1
    Thu Mar 27 17:04:41 2014 Route deletion via IPAPI succeeded [adaptive]
    Thu Mar 27 17:04:41 2014 C:\Windows\system32\route.exe DELETE 0.0.0.0 MASK 128.0.0.0 10.8.0.5
    Thu Mar 27 17:04:41 2014 Route deletion via IPAPI succeeded [adaptive]
    Thu Mar 27 17:04:41 2014 C:\Windows\system32\route.exe DELETE 128.0.0.0 MASK 128.0.0.0 10.8.0.5
    Thu Mar 27 17:04:41 2014 Route deletion via IPAPI succeeded [adaptive]
    Thu Mar 27 17:04:41 2014 Closing TUN/TAP interface
    Thu Mar 27 17:04:41 2014 SIGTERM[hard,] received, process exiting
    Thu Mar 27 17:04:41 2014 MANAGEMENT: >STATE:1395957881,EXITING,SIGTERM,,

    Reply
  2. Avatar

    andres

    Excellent…works perfectly… I only belived that I would be able to connect with more speed through the VPN, even right now I have around 30Mb/s download out of VPN,and I only can get max 6Mb/s connected to the VPN Server …the server was created in Brazil, in the same state where I am right now, so I can’t understand what happens … :s

    Reply

Leave a Reply