I decided to create this guide while traveling from the U.S. to Germany. I could not find a single comprehensive reference that documents the process of properly provisioning an AWS EC2 OpenVPN instance, configuring OpenVPN, and using the VPN server from Windows (10.0.17763.379) and iOS (12.2).
This document is current as of March 31st, 2019 (UK trip). I doubt I will update it very often probably when I need to travel and want a VPN.
AWS EC2 Instance Creation and Configuration
The documentation from OpenVPN is pretty good for this section. As my documentation ages, no doubt the OpenVPN docs will be more accurate. There is also some good information from the listed EnvyAndroid site. I assume the reader has a basic understanding of AWS EC2.
- Log into the AWS Console and select the region in which you want to host the instance (e.g., EU London).
- Launch a new instance in the region of your choice. I recommend making it as local to your physical location as possible in order to have a fast connection. However, you may want to try and spoof your location (for things like NetFlix) the choice is up to you.
- Launch and instance and select Community AMIs .
- Select the current OpenVPN AMI. You can get the AMI ID from the Quick Start URL.
- https://docs.openvpn.net/how-to-tutorialsguides/virtual-platforms/amazon-ec2-appliance-ami-quick-start-guide/
- Select Amazon Web Services EC2 BYOL appliance quick start guide. If you do not provide a license key, the Access Server goes into a type of demonstration mode where all functions are available without time limit, but only 2 simultaneous VPN connections can be made at a time. To unlock more connections, you need to purchase and activate a license key on your Access Server installation.
- Alternatively, select Amazon Web Services EC2 tiered appliance quick start guide, and select a not-free solution to meet your needs.
- Accept the default size (t2.micro). This should be fine for personal VPN, and keeps things free.
- For configuration, nothing really needs to be changed from the defaults. I will just list the things I changed.
- Subnet: Select whatever you want. You may want to create multiple servers in different subnets for high-availability at some point.
- Protect against accidental termination: I like to enable this because I am often too aggressive in my clean-up routine
- User Data: You can configure OpenVPN via User Data as a test (under Advanced Details), if you so choose. You can also configure OpenVPN later your choice. Here is a example:
- public_hostname=test_vpn (we will change this later)
- admin_user=openvpn
- admin_pw=Passw0rd
- reroute_gw=1
- reroute_dns=1
- Select Add Storage.
- Storage: 8GB of magnetic storage is default. I went with 16GB and kept it magnetic.
- Tags: I like to add a name tag. In this example, Example OpenVPN Server .
- Security Group: Create an OpenVPN security group as documented in the Quick Start Guide. It needs to allow the following (feel free to change the Source as you see fit).
- TCP 22 Anywhere (0.0.0.0/0)
- TCP 443 Anywhere (0.0.0.0/0)
- TCP 943 Anywhere (0.0.0.0/0)
- UDP 1193 Anywhere (0.0.0.0/0)
- Review and Launch. I launch with a keypair. The instance will spin up relatively fast.
- Optional: Elastic IP is cool, but it is not free. The cost is low, but there is a cost (my 2 week trip cost me $1.57). Go to Elastic IP and allocate a new address. The Quick Start Guide is a good reference, but this is real simple. This step is technically not necessary, but is recommended. The elastic IP never changes you have it forever. You can associate it with any instance you want. Thus, you can terminate and create new instances as needed and always have the same IP for your VPN server.
- Click Allocate a new address .
- Click Allocate .
- Select the new elastic IP and click the Actions pull-down.
- Resource Type: Instance
- Instance: select the Instance ID of the instance you just created
- Private IP: select the IP of the instance (there is only one)
- Click Associate
- Via the AWS Console:
- Select your instance.
- Note the Public DNS name (listed above the Description, Status Check, etc., tabs). It will look something like:
ec2-x-x-x-x.eu-central-1.compute.amazonaws.com
- Right-click the instance, Networking, and select Change Source/Dest. Check. Click Yes, disable .
Connecting to OpenVPN Server
- Log in via SSH (remember to use the Elastic IP, if you created one), using the Quick Start Guide as a reference. Here is a summary:
- Via puttygen.exe (http://www.putty.org/), import your Amazon key (.pem) and export it to a private .ppk file (putty.exe needs the .ppk file). If you use a key passphrase, store it in a secure location (LastPass, etc.). If you don t use a passphrase, you will not be prompted for a password in 1b (I assume, I always use a passphrase).
- The default key type of RSA 2048 is probably fine, but make it whatever value you want.
- Click Save private key .
- Run putty.exe, configuring it as documented in the Quick Start Guide. The important parts to configure are Host Name (or IP), and to point to your .ppk file the SSH/Auth section. You will log in with the openvpnas (note the as at the end) account and your key passphrase as the password.
Initial OpenVPN Server Configuration
I have mixed results here. Sometimes I am prompted to configure OpenVPN, sometimes not I opt to reconfigure, regardless simple run sudo ovpn-init --ec2 if not prompted. Accept the defaults except for the first one (EULA agreement, type yes ). The Quick Start Guide explains all the various settings. I am unsure if the defaults are determined by the User Data field or are truly default (I use User Data), so just in case, here is a summary of my defaults to use as a reference:
- Please enter 'yes' to indicate your agreement [no]: yes
- Will this be the primary Access Server node?
(enter 'no' to configure as a backup or standby node)
> Press ENTER for default [yes]: yes
- Please specify the network interface and IP address to be used by the Admin Web UI:
(1) all interfaces: 0.0.0.0
(2) eth0: 172.31.44.139
Please enter the option number from the list above (1-2).
> Press Enter for default [2]: <Enter>
- Please specify the port number for the Admin Web UI.
> Press ENTER for default [943]: <Enter>
- Please specify the TCP port number for the OpenVPN Daemon
> Press ENTER for default [443]: <Enter>
- Should client traffic be routed by default through the VPN?
> Press ENTER for default [no]: yes
- Should client DNS traffic be routed by default through the VPN?
> Press ENTER for default [no]: yes
- Use local authentication via internal DB?
> Press ENTER for default [yes]: <Enter>
- Should private subnets be accessible to clients by default?
> Press ENTER for EC2 default [yes]: <Enter>
- To initially login to the Admin Web UI, you must use a username and password that successfully authenticates you with the host UNIX system (you can later modify the settings so that RADIUS or LDAP is used for authentication instead).
You can login to the Admin Web UI as "openvpn" or specify a different user account to use for this purpose.
Do you wish to login to the Admin UI as "openvpn"?
> Press ENTER for default [yes]: <Enter>
- > Please specify your OpenVPN-AS license key (or leave blank to specify later): <Enter>
- You can always re-configure OpenVPN by running the command:
sudo ovpn-init --ec2
- Change the timezone (optional set it to whatever you like):
sudo dpkg-reconfigure tzdata
- Disable the bootstrap account (optional). I did not bother.
- Update the system using the following commands:
sudo apt-get update && sudo apt-get upgrade
(answer Y to the various questions, if prompted)
- If desired, change the password of the openvpn account.
sudo passwd openvpn
- Reboot.
sudo reboot
OpenVPN Client Installation
- Download and install the OpenVPN client on your Windows system. Accept the defaults.
- Install the OpenVPN client for iOS from the Apple Store.
OpenVPN Admin UI and Web UI
You are almost done. There are just a few final tweaks to make to OpenVPN Access Server, and they can all be done via the web interfaces.
- Log in to the admin UI (https://<IP>/admin/ - note the https) using the name and password defined in the User Data or OpenVPN configuration. There are several things you will want to configure.
- Configuration / TLS Settings: Change the OpenVPN and Web Server settings to TLS 1.2 only.
- Configuration / Network Settings: Change the Hostname to the public DNS you noted from 3b of AWS EC2 Instance Creation and Configuration
- Configuration / Advanced VPN: Change the server and client configs to use AES 256:
cipher AES-256-CBC
- User Management / User Permissions: Create a new user with just the Allow Auto-login right. Once created, click Show and set the password. This is the account you will use to access OpenVPN from you Windows and iOS devices. This is documented on another EnvyAndroid site:
- Logout.
- From your Windows system, browse to the the web UI (https://<IP>/ - note the https).
- Log in with the user account and password used in 1d (above). Next to Go , select Login.
- Save the .ovpn file. You can select either the Yourself (user locked profile) or the Yourself (autologin profile) , depending on whether or not you want to use credentials.
- You now have two choices you can either copy the .ovpn file to %ProgramFiles%\OpenVPN\config\ , or you can bring up the OpenVPN GUI and import the .ovpn file (which merely puts it into %USERPROFILE%\OpenVPN\config\ by default [this can be changed]). The user profile location is fine if you have multiple people using your system and each wants their own VPN servers/accounts. However, if only you use the machine, or if people will share the OpenVPN servers/accounts, it is easier to just put the .ovpn files into the application directory.
- You can now connect using the OpenVPN client. If you selected an autologin profile, you will not get prompted for a user or password; if you selected a locked profile, you will get prompted for a user and password.
- On your iOS device, browse to the the web UI (https://<IP>/ - note the https) using Safari. Do not use FireFox because FireFox does not know how to associate the .ovpn file with OpenVPN.
- Log in with the user account and password used in 1d (above). Next to Go , select Login.
- Save the .ovpn file. You can select either the Yourself (user locked profile) or the Yourself (autologin profile) , depending on whether or not you want to use credentials.
- Select Open in OpenVPN .
- You can now connect using the OpenVPN client. If you selected an autologin profile, you will not get prompted for a user or password; if you selected a locked profile, you will get prompted for a user and password.
http://accc.uic.edu/answer/how-do-i-configure-and-use-openvpn-iphone-and-ipad
e. There are other ways of getting the .ovpn file to your iOS device, but many suck. The one above is by far the easiest. Another easy one is to drop the file onto your device via Explorer and iTunes (I have not tested this recently). You can also get the file to your iOS device via all manner of secure and insecure processes (email, SMS text, DropBox, whatever).
Things to Investigate:
- Investigate setting up a fault-tolerant cluster of OpenVPN servers in different AZ s, using a single Elastic IP to reach the cluster.
- Investigate the VPN-on-Demand stuff (see below).
Other References
- Amazon documentation on using PuTTY:
https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/putty.html?icmpid=docs_ec2_console
- EnvyAndroid primer:
- OpenVPN starter page:
https://openvpn.net/index.php/access-server/cloudmachines/513-access-server-amazon-vpc.html
- OpenVPN Connect iOS FAQ:
https://docs.openvpn.net/docs/openvpn-connect/openvpn-connect-ios-faq.html
- python scripts to get .ovpn file (I never needed these, but they seem cool):
https://gist.github.com/Justasic/908ef5f4fa162f15b3b8
https://vpsboard.com/threads/how-do-i-create-an-openvpn-file.2123/
- VPN-on-Demand info:
https://docs.openvpn.net/docs/access-server/openvpn-access-server-command-line-tools.html