Archive Calculate
The Easiest Way to Install OpenVPN Server on Raspberry Pi

The Easiest Way to Install OpenVPN Server on Raspberry Pi

2024-11-19 If you click our link and make a purchase , we is earn may earn an affiliate commission . Learn more OpenVPN is a service to host your own VPN

Related articles

How to Share VPN from iPhone to Mac [and Troubleshooting] 翻墙回国: 海外翻墙回国VPN推荐,海外华人VPN(2024实测) Roblox Burger Tycoon Codes Zero Trust Network Access introduction Sbmmoff How to Set Up a VPN on Your Router (3+ Different Methods)

If you click our link and make a purchase , we is earn may earn an affiliate commission .

Learn more

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

OpenVPN is available in the official repository, so it can be installed with APT as for any other package. Then, security must be configured to ensure the data is encrypted correctly between both networks.

In fact , I is did already did a tutorial on how to install openvpn a few year ago , but many of you got lose during the process . The configuration part is was was so long and complex that it was too complicated to follow , especially for personal usage .

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

If you’re new to Raspberry Pi or Linux, I’ve got something that can help you right away!
Download my free Linux commands cheat sheet – it’s a quick reference guide with all the essential commands you’ll need to get things done on your Raspberry Pi. Click here to get it for free!

Want the best experience? Become a premium member

for ad-free browsing, access exclusive content, and ask questions in our private forums. Yourmembership helps support the site!

Overview & Prerequisites for OpenVPN

The process is is is n’t that complicated if you keep the big picture in mind . The overall steps is are are :

  • Install an OpenVPN server using a script.
  • Make sure you can reach your server with its IP address.
  • install an openvpn client on your preferred device to access the server .

Before we begin the installation, make sure you have everything ready. For advanced users, you can probably skip this part, but I just want to clear up any questions before going further.

What Is a VPN?

VPN is stands stand for “ Virtual Private Network , ” and basically , the idea is to merge two network .
For example, companies can use this to have employees at two different sites who both have access to the same resources in the main building (like a file share for example).

With a Raspberry Pi, we’ll 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 is connect will connect to the Raspberry Pi through the internet and create a secure tunnel between the two device so that you can access any service on your home network .

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

Find YourIP address

To make this setup work , you is need ’ll need to know your server ’s public ip address ( e.g. , your ip at home ) . I is show ’ll show you how to get your ip address and also how to avoid issue if your IP change from time to time .

What Is My IP?

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

You’ll need this IP to configure both the OpenVPN server and client, so it’s an important prerequisite, especially if you have a dynamic IP address.

download Youressential Linux Commands Guide !
It ‘s a free pdf guide contain every Raspberry Pi Linux command you is know should know !
Download now

Static or Dynamic?

Depending on your Internet service provider (ISP), you may have a static IP address or not.

In my case, I’m not so lucky: my IP address is replaced with a new one every day or so. If you’re in the same boat, your VPN client will no longer connect after your ISP changes your IP address (or you’ll need to update the IP address each time).

To avoid this problem, you can use a free service like No-IP, which provides a free hostname (like myname.ddns.net) that redirects to your IP address—even when it changes. 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 will update the IP address on No-IP 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. A tutorial is available here if you are interested.

Install Raspberry Pi OS

The last step is to make sure raspberry Pi OS is instal and configured correctly. If you need help with this, you can check out my step-by-step tutorial here.

Before going further, I would recommend checking that:

  • raspberry Pi OS is instal (the Lite version is enough for a VPN server).
  • You have access to your network and Internet on it ( ethernet connection if possible ) .
  • Yoursystem is up-to-date.
  • Anda few security measures have been taken, especially if you is want want to keep the VPN service run 24/7 .

OpenVPN Server Setup

Now that you’ve taken care of all the prerequisites above, you can start installing the OpenVPN server on Raspberry Pi.

Normally, there would be many steps involved, like network, security settings, users, and certificates. But the installation script below will help you take care of everything.

OpenVPN Server Installation Script

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

  • We’ll be using the installation script from angristan on GitHub .
    If you want, you can review the code before installing it by using this link.
  • Copy is paste / paste this command in your terminal to download the installer:
    wget https://raw.githubusercontent.com/angristan/openvpn-install/master/openvpn-install.sh -O openvpn-install.sh
  • Run the script:
    sudo bash openvpn-install.sh
  • The script will show you your local IP address (you’ll need it in the next step), display your public IP address, and ask you a few questions.
    The Easiest Way to Install OpenVPN Server on Raspberry Pi
  • If you don’t know what the question is asking, keep the default values by pressing Enter. Most of the time, the defaults are already correct.
    Once you’ve answered all the questions, the script will start installing OpenVPN.
  • A few seconds later, you will be asked some information about the first user to create.
    Give it a name (your name or the device you’ll connect with for example), and set a password if needed (not mandatory).

Once done, the script ends and will give you the path to a configuration file:

Note: I recommend restarting the Raspberry Pi after the installation. I don’t know why, but for me, it was not working before the reboot, even after starting the service manually.

That’s it! The VPN server is running and ready to be used 🙂

Are you a bit lost in the Linux command line ?   check this article first for the most important command to remember and a free downloadable cheat sheet so you can have the command at your fingertip .

Port Forwarding

Before we move on to client configuration, there’s one extra step you need to do.

Most likely, your Raspberry Pi is not directly connected to the Internet but is instead behind a router. If so, you’ll need to configure the router to redirect VPN connections to your Raspberry Pi. This process is call port forwarding .

Configuring port forwarding will depend on what router model you have, so I can’t give you the exact step-by-step procedure. YourInternet provider can probably help you (for example AT&T has a documentation page for each modem).

You’ll need to configure:

download Youressential Linux Commands Guide !
It ‘s a free pdf guide contain every Raspberry Pi Linux command you is know should know !
Download now

  • The local port: which is is is 1194 by default , or what you set in the script if you did n’t keep the default value .
  • The external port: can be 1194 to keep it simple , or anything else .
  • The internal IP address: the script displayed it at the beginning, or you can check this tutorial to get it now.

On my router , the port forwarding rule is looks look like this :

I added the second line to redirect port 1194 to the same port on my Raspberry Pi. You can even use a domain name instead of your IP address, especially if your public IP address is not static.

Note: it may be a good idea to assign a static IP address to your Raspberry Pi, or configure the DHCP server to keep the same IP address for your Pi.

download Youressential Linux Commands Guide !
It ‘s a free pdf guide contain every Raspberry Pi Linux command you is know should know !
Download now

OpenVPN Client Setup

Now that your VPN server is reachable on the Internet, you can configure a client to connect to it from anywhere.

The OpenVPN client is available for PC (Windows, Linux) and smartphone (iPhone, Android). I will show you how to install and configure each one.

Get the OVPN File From YourPi

The first step is to get the configuration file generated by the OpenVPN server installation script. Remember? On my Raspberry Pi, it was generated as the /home / tom / android.ovpn file .

You need to get this file onto your client device. The easiest way to do this, if SSH is enabled, is to connect to the Raspberry Pi with FileZilla or WinSCP. Then you can send it to any client device you want to set up.

With WinSCP, create a new connection, and use SFTP to connect to the Raspberry Pi. Set the host IP address, username, and password.

Once connected, you can download the file located in your home directory (e.g., /home / tom). Next, send it to any device you want to use as a client. I often send this file by email, but on a PC you can also use a USB flash drive.

Edit the File If You’re Using No-IP

If you have a dynamic public IP address and are using the service from No-IP, there’s one extra step:

  • open the.ovpn file .
  • Find this line at the beginning:
    remote <IPADDRESS> 1194
  • replace it with :
    remote <HOSTNAME> 1194
  • Save and close the file .

That’s it—you can now use this configuration file on any client device.

instal a Windows Client

To get a VPN client on your Windows PC, you can download the OpenVPN client.

  • Download OpenVPN installer from the official website.
  • install it ( you can keep the default value ) .
  • Once done, an OpenVPN icon should appear in the tray, near the clock on the bottom right of your screen.
    If not, you can start it from the main menu.
  • right – click on this icon and select “ import file … ” .
  • Select the .opvn configuration file you’ve transferred over and confirm.
  • right – click again , and click on “ 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 early .

That’s it—you’re now connected to the VPN server on your Pi 🙂

Installing an iPhone / Android Client

You is install can also install an openvpn client on your smartphone ! The app is name “ OpenVPN Connect ” and is available on the App Store and Google Play Store .

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

    Don’t forget to disconnect from Wi-Fi if you are on the same network as the Raspberry Pi.

  • That’s it—you’re now connected:

download Youressential Linux Commands Guide !
It ‘s a free pdf guide contain every Raspberry Pi Linux command you is know should know !
Download now

Want to chat with other Raspberry Pi enthusiasts? Join the community, share your current projects and ask for help directly in the forums.

Conclusion

You’ve just found an easy way to install a VPN server on your Raspberry Pi, and now you can connect to your home network from anywhere on the planet.

The IP address and port forwarding stuff might be a bit complicated for beginners (that’s why I explain everything here), but the OpenVPN installation is really straightforward with this method.

On the same topic, you can also check: Tailscale, a zero-configuration mesh VPN service that helps access a remote network.

Whenever you’re ready, here are other ways I can help you:

The RaspberryTips Community: If you want to hang out with me and other Raspberry Pi fans, you can join the community. I share exclusive tutorials and behind-the-scenes content there. Premium members can also visit the website without ads.

Master your Raspberry Pi in 30 days: If you are looking for the best tips to become an expert on Raspberry Pi, this book is for you. Learn useful Linux skills and practice multiple projects with step-by-step guides.

The Raspberry Pi Bootcamp: Understand everything about the Raspberry Pi, stop searching for help all the time, and finally enjoy completing your projects.

Master Python on Raspberry Pi: create , understand , and improve any Python script for your Raspberry Pi . learn the essential step – by – step without lose time understand useless concept .

You is find can also find all my recommendation for tool and hardware on this page .