Introduction This How-To will cover the process of installing OpenVPN Community Edition on a 64-bit Ubuntu 14.04 LTS server. All comma...
Introduction
This How-To will cover the process of installing OpenVPN Community Edition on a 64-bit Ubuntu 14.04 LTS server. All commands are entered from a terminal and root level permissions are assumed.
In this tutorial I will cover the installation and configuration of OpenVPN, the generation of the certificate authority and server-side certificates, as well as the generation of client certificates and the simplification and build of ovpn profiles using client keys and certificates.
When editing text files I use the vim text editor, but you may use whichever text editor you prefer to accomplish the task (vi, nano, emacs, etc...). When I refer to uncommenting a line in a file, it requires deleting either a ";" or "#" character from the beginning of said line.
Steps (19 total)
sudo apt-get update && sudo apt-get install openvpn easy-rsa
gunzip -c /usr/share/doc/openvpn/examples/sample-config-files/server.conf.gz > /etc/openvpn/server.conf
Change the line: dh dh1024.pem
to: dh dh2048.pem
to: dh dh2048.pem
Uncomment: push "redirect-gateway def1 bypass-dhcp"
Uncomment: push "dhcp-option DNS 208.67.222.222"
Uncomment: push "dhcp-option DNS 208.67.220.220"
Uncomment: user nobody
Uncomment: group nogroup
echo 1 > /proc/sys/net/ipv4/ip_forward
vim /etc/sysctl.conf
Uncomment: net.ipv4.ip_forward=1
ufw allow ssh
ufw allow 1194/udp
ufw allow 1194/udp
vim /etc/default/ufw
Change: DEFAULT_FORWARD_POLICY="DROP"
To: DEFAULT_FORWARD_POLICY="ACCEPT"
Change: DEFAULT_FORWARD_POLICY="DROP"
To: DEFAULT_FORWARD_POLICY="ACCEPT"
vim /etc/ufw/before.rules
Add the following directly below the "rules.before" section found at the top of the document:
Add the following directly below the "rules.before" section found at the top of the document:
# START OPENVPN RULES
# NAT table rules
*nat
:POSTROUTING ACCEPT [0:0]
# Allow traffic from OpenVPN client to eth0
-A POSTROUTING -s 10.8.0.0/8 -o eth0 -j MASQUERADE
COMMIT
# END OPENVPN RULES
# NAT table rules
*nat
:POSTROUTING ACCEPT [0:0]
# Allow traffic from OpenVPN client to eth0
-A POSTROUTING -s 10.8.0.0/8 -o eth0 -j MASQUERADE
COMMIT
# END OPENVPN RULES
ufw enable (Answer yes to the prompt)
ufw status (Verify configuration changes were passed)
cp -r /usr/share/easy-rsa /etc/openvpn
mkdir /etc/openvpn/easy-rsa/keys
vim /etc/openvpn/easy-rsa/vars
*Supply the appropriate information on the lines referencing COUNTRY, PROVINCE, CITY, ORG, EMAIL, and OU variables.
export KEY_COUNTRY="US"
export KEY_PROVINCE="NY"
export KEY_CITY="Big City"
export KEY_ORG="Company Name"
export KEY_EMAIL="frank@frijoles.com"
export KEY_OU="OrganizationalUnit"
export KEY_PROVINCE="NY"
export KEY_CITY="Big City"
export KEY_ORG="Company Name"
export KEY_EMAIL="frank@frijoles.com"
export KEY_OU="OrganizationalUnit"
*Set the key name to "server"
export KEY_NAME="server"
export KEY_NAME="server"
openssl dhparam -out /etc/openvpn/dh2048.pem 2048
cd /etc/openvpn/easy-rsa && . ./vars
./clean-all && ./build-ca
./build-key-server server
*Confirm all values previously entered in the "vars" file, and answer "y" to sign and commit.
cp /etc/openvpn/easy-rsa/keys/{server.crt,server.key,ca.crt} /etc/openvpn
service openvpn restart
cd /etc/openvpn/easy-rsa
./build-key client1
*verify values and answer "y" twice to sign and commit the certificate
cp /usr/share/doc/openvpn/examples/sample-config-files/client.conf /etc/openvpn/easy-rsa/keys/client.ovpn
vim /etc/openvpn/easy-rsa/keys/client.ovpn
Change: remote <server ip address> 1194
Uncomment: user nobody
Uncomment: group nogroup
Uncomment: group nogroup
Comment Out: #ca ca.crt
Comment Out: #cert client.crt
Comment Out: #key client.key
Comment Out: #cert client.crt
Comment Out: #key client.key
*At the bottom of the file add the following fields:
<ca>
(insert contents of ca.crt here)
</ca>
<cert>
(insert contents of client1.crt here)
</cert>
<key>
(insert contents of client1.key here)
</key>
<ca>
(insert contents of ca.crt here)
</ca>
<cert>
(insert contents of client1.crt here)
</cert>
<key>
(insert contents of client1.key here)
</key>
Securely transfer the newly created client.ovpn profile to a device you wish to connect to the VPN. Install the appropriate OpenVPN application on the device and import the OVPN profile.
Connect!
Build a script (or use the one linked... :-D ) to automate the process of client certificate/key creation and ovpn profile compilation. Please see the comments at the top of my script for further information.
Automate Client OVPN Profile Creation: http://community.spiceworks.com/scripts/show/3235-automate-openvpn-ovpn-profile-creation
Conclusion
That's it! You've got a basic VPN setup using OpenVPN. Assuming you have a static ip or dynamic dns configured, you should be able to securely connect to your local network.
This How-To is in many ways, a condensed version of the information provided in the Digital Ocean tutorial referenced below. If you want a more thorough explanation of many of the steps above please visit the referenced link.
No comments
Post a Comment