Connect with us

Hi, what are you looking for?

Internet

The easiest way to install an OpenVPN server on a Raspberry Pi – RaspberryTips

The easiest way to install an OpenVPN server on a Raspberry Pi – RaspberryTips

πŸ‘¨β€πŸ’»

OpenVPN is a service to host your own VPN server, without using external servers.
A VPN is a secure connection between two networks, for example between your phone and your home.
In this tutorial, I will give you a step by step method to quickly install it on your Raspberry Pi.

OpenVPN is available in the official repository, so it can be installed with apt as with any other package.
Next, security must be configured to ensure that data is properly encrypted between both networks.

In fact, I actually did a tutorial on how to install OpenVPN a few years ago, but many of you got lost in the process.
The composition part is very long and complex, and it was very difficult to follow, especially for personal use.

That’s why I looked for an easier way to install and configure OpenVPN, and I found it!
I will share it with you now.

Basic requirements

Get my cheat sheet!
Get your FREE PDF with all the commands you need to know on your Raspberry Pi!

Right before the installation part, make sure everything is ready.
For advanced users, you can probably skip this part, I just want to answer all the questions before moving forward.

What is a VPN?

VPN stands for Virtual Private Network, and the basic idea is to merge two networks.
For example, companies can use this to assign employees in two different locations, but using the same resources from the main building (like sharing a file for example).

With a Raspberry Pi, we will generally use it to access a remote network from anywhere in the world.
For example, you can access your security camera or home automation web page from your smartphone while traveling.
The smartphone will connect to the Raspberry Pi over the Internet, and create a secure tunnel between the two devices, so you can access any service on your home network.

Raspberry Pi Bootcamp
Sale: 10% off today.
Take it to the second level.
I’m here to help you get started with your Raspberry Pi.
Learn all the skills you need in the right order.

OpenVPN is the software that will make this work on both sides.

Find your IP address

To create this, you need to know your home’s public IP address and configure it on the client side.
If you don’t know, I’ll show you how to get your IP address, as well as how to avoid issues if your IP changes from time to time.

What is my IP address?

Finding your current IP address is very easy, as there are many websites that will give you that address.
For example, go to WebInpact.com and note your IP address.

You’ll need this only at the end of the tutorial, when configuring the OpenVPN client, but it’s an important prerequisite, especially if you have a dynamic IP address.

Static or dynamic?

Depending on your internet provider, you may or may not have a static IP address.
In my case, I’m not very lucky, so every day or so my IP is replaced with a new one.
If you are in this situation, your VPN client will not work after the first change (or you will need to update the IP address every time).

To avoid this, You can use a free service called NoIP, which provides a free hostname (eg myname.ddns.net) that redirects to your IP address, even after the change. This way, you can configure your VPN client with myname.ddns.net instead of your IP address.

You just need to have something on your network, that updates the IP address on NoIP regularly.
I have this feature in my internet router, so I just need to put my credentials in the interface and it’s done.
But even if you don’t have it in your router, you can install a script on your Raspberry Pi (or any other device) to do the same thing. The Raspberry Pi tutorial is available here if you’re interested.

Install Raspberry Pi OS

The final step is to ensure that the Raspberry Pi OS is installed and configured correctly.
If you need help on this topic, you can review the step-by-step tutorial here.

Before moving forward, I recommend checking the following:

  • Raspberry Pi OS installed (Light version is enough for VPN server).
  • You have Access to your network and the Internet them (Ethernet connection if possible).
  • for you The system is up to date
  • And Some security steps have been takenEspecially if you want to keep it running 24/7 with the VPN service running.

OpenVPN Server Setup

Once ready, we can start installing the server on the Raspberry Pi.
There are many things involved like network, security settings, users and certificates. But the installation script will take care of everything.

OVPN text

Connect to your Raspberry Pi using SSH, and follow this procedure:

  • We’ll be using the install script from angristan on GitHub.
    You can check the code on this link before installing it if you want.
  • Copy and paste this command In your terminal to download it:
    wget https://raw.githubusercontent.com/angristan/openvpn-install/master/openvpn-install.sh -O openvpn-install.sh
  • then Run the script with:
    sudo bash openvpn-install.sh
  • The script will show you your local IP (you’ll need it in the next step) and your public IP and ask you a few questions.
  • Most of the time, you will Keep the default values, so just press “Enter” for each question if you don’t know.
    OpenVPN installation begins.
  • After a few seconds, you will be asked for some information about the first user who created it.
    Give it a name (yours or the device you’re going to connect to for example), and set a password if necessary (not mandatory).

Once done, the scripts finish and give you the path to the first config file:

Master your Raspberry Pi in 30 days
Sale: 10% off today.
Download the e-book.
Reveal the secrets of the Raspberry Pi in a 30-day challenge.
Learn useful Linux skills and practice multiple projects.

That’s it, VPN server is up and your first client is ready to use πŸ™‚

Noticeable: I recommend restarting your Raspberry Pi after installation. I don’t know why, but for me, it wasn’t working before restarting, even after starting the service manually.

Shipping Port

Before configuring the client, there is an extra step that you have to take.
Most likely, your Raspberry Pi is not directly on the Internet, but behind a router. So You need to configure this router to forward VPN connections to your Raspberry Pi.

The configuration will depend on your router model, so I can’t give you the exact step-by-step procedure, but your internet provider will probably help you (eg AT&T has a documentation page for each modem).

You will need to configure:

  • external port: It could be 1194 to simplify it or something else.
  • internal IP address: The script offered it initially, or you can check out this tutorial to get it now.
  • domestic port: which is 1194 by default, or whatever you set in the script if you don’t keep the default value.

In my case, it looks like this:

So I added the second line, to forward port 1194 to the Raspberry Pi, the same port.
You can even use the domain name in place of your IP address, especially if your public IP address is not static.

NoticeableA good idea would be to use a static IP address on your Raspberry Pi, or configure a DHCP server to hold the IP address of your Raspberry Pi.

OpenVPN Client Setup

Get my cheat sheet!
Get your FREE PDF with all the commands you need to know on your Raspberry Pi!

Our VPN server is now online, so we can configure a client to connect to it from anywhere.
OpenVPN is available for computers (Windows, Linux) and smartphones (iPhone, Android). I’ll show you how to install and configure it.

Get the OVPN file

The first step, whatever your system, is to get the file created on the Raspberry Pi by the OpenVPN wizard.
remembers? For me, it was /home/pi/android.ovpn

Mastering Python on Raspberry Pi
Sale: 10% off today.
Get the e-book.
Do more with your Raspberry Pi, learn useful concepts and take shortcuts.
You lose half the fun of using a Raspberry Pi if you don’t know anything about Python.

You need to get it on the client where you want to install OpenVPN.
The easiest way to do this if SSH is enabled is Connect to your Raspberry Pi using FileZilla or WinSCP, and transfer the file on your computer.
Then you can send it to any device you want to configure.

In FileZilla, create a new site and use SFTP to connect to your Raspberry Pi.
Set the host IP address, username, and password.

Once connected, you can download the file in /home/pi, and send it to the device you want to use as a client (I often do this via email, but for a PC you can use a USB key as well).

Edit the file to use your No-IP hostname

If you have a dynamic public IP and you are using the service from No-IP, there is an extra step:

  • Open the .ovpn file
  • Look for this line at the beginning:
    far 1194
  • replace it with:
    far 1194
  • Save and close the file

That’s it, you can now use it on any device.

Installation on Windows

  • Download the OpenVPN installer from the official site
  • Install it (you can keep the default values)
  • Once that’s done, the OpenVPN icon should appear in the case, near the clock in the lower right of the screen.
    If not, you can start it from the main menu.
  • Right-click on this icon and select “Import file…”.
  • Select the file created on the Raspberry Pi and confirm.
  • Right-click again, and click Connect.
    It will only work if the device is not on your home network, but you can test it by sharing your phone connection for example.
  • Enter your password if you choose to set one in the configuration.

That’s it, you are now connected to your VPN server πŸ™‚

Install on iPhone / Android

You can also install OpenVPN on your phone!
The app is called β€œOpenVPN Connect” and it is available on the App Store and Google Play Store.

  • Install the application on your phone
  • Transfer the .ovpn file to your phone: The easiest way to do this is to email it and download it from your email app.
  • Open OpenVPN Connect
  • Go to Import Profile > File, and select the .ovpn file from the download folder
  • Click “Import” and “Add”
  • A new profile has been added, and you can connect by clicking on it

    Do not forget Disconnect from Wi-Fi If you are on the same network as your Raspberry Pi

  • That’s it, you are now connected:

conclusion

That’s it, you now know an easy way to install OpenVPN on your Raspberry Pi, and connect to your home network from anywhere on the planet.
The IP address and port forwarding stuff can be a little complicated for beginners (that’s why I explain everything here), but installing OpenVPN is really straightforward this way.


Don’t forget to share this post with friends !

Discover  Safe use of passwords over a VPN connection
Click to comment

Leave a Reply

Your email address will not be published.

Related

Internet

AnyConnect: Install a self-signed certificate as a trusted source πŸ‘¨β€πŸ’» kmgmt-2879-cbs-220-config-security-port objective The goal of this article is to walk you through creating and...

Internet

ITProPortal . Portal πŸ‘¨β€πŸ’» We live in a dynamic moment in terms of technology. Even criminals are becoming more technically savvy and are using...

Internet

Avira Free Antivirus Review for Mac / Windows and Android are the most common targets for malware programmers, but that doesn’t mean macOS is...

Internet

Avira Free Security Review You need antivirus protection on all of your devices, whether you’ve budgeted for it or not. If ready cash is...