Sunday, 22 January 2017

OpenVPN Server on Raspberry Pi

Introduction


In this tutorial I'll be showing you guys how to easily set up an OpenVPN Server on a Raspberry Pi using PiVPN which makes the set up of OpenVPN Server a lot easier and saves you a lot of time. Having an vpn server in your home allows you to connect to your home network from anywhere in the world, this can be very useful especially if you have a NAS(Network-attached storage) at home.


Requirements


  • A raspberry pi running raspbian(you don't have to use raspbian but it is the easiest way and that's what I am going to be showing here)
  • Ethernet connection for your Raspberry Pi.(you can use wifi but it is not recommended)
  • 30 to 60 minutes of your time.


Set-up


SSH into your raspberry pi


Windows

If you are using windows use putty to ssh into your raspberry pi, the default username is "pi" and password is "raspberry".


OS X/Linux

If you are using OS X or Linux open the terminal and type this, replace the ip address with the ip address of your raspberry pi for this example I'm using the ip of 192.168.1.80.




Running PiVPN


After successfully connecting to your Raspberry Pi run this command.



Press Enter until you reach this screen.




















Select eth0 as your interface, press space to select and press tab and enter.



Continue pressing enter until you reach this screen.



















Make sure to select yes to keep your server OpenVPN Server updated.





















Leave the port as 1194 unless you want to use another port.






















Select the 2048-bit encryption.
Continue with the default options and reboot the pi after completing the installation.


Adding Clients


Run the command below to add a new client to the server.



The new client file will be in /home/pi/opvns, you can use a program like WinSCP or filezilla to get the file from the pi, and that's all you need to do on the pi now you just need to set up your client to connect to the server.


Static IP


Since your Raspberry Pi is a server, it needs a static IP, this can be done by Reserving an IP for the mac address of the Raspberry Pi, this can be done by accessing your router's admin page.


Port-Forwarding


Before you can connect to your server from outside of your home network, you need to port-forward the specified port(the default port is 1194) for the OpenVPN server to your Raspberry Pi. For example if the ip of your Raspberry Pi is 192.168.1.80 then you need to forward port 1194 to 192.168.1.80 you can do this via your router's admin page.


Connecting to the OpenVPN Server


Windows

Download the OpenVPN client from here and import the .ovpn file that you retrieved from the pi. Then just connect to the server using the credentials you set up for that client.

OS X

Download Tunnelblick from here, double-click the .dmg file to install. Usage is similar to windows OpenVPN client.

Linux

Ubuntu/Debian based systems



CentOS


To connect to the server




Android

Install OpenVPN Connect from the play store, then import the .opvn file and connect to the server.

IOS

Install OpenVPN Connect from the app store and connect your phone to your computer, open itunes and click on iPhone > Apps. Scroll down to the file sharing section and click on OpenVPN Connect, then drag and drop the .ovpn file into the OpenVPN Connect Documents tab.

Alternatively you can upload the .ovpn file to a cloud service like dropbox and download the file from your browser and open with OpenVPN Connect.

No comments:

Post a Comment