How to set up VPN server on Raspberry Pi [Complete Guide]

Vlad Constantinescu
by Vlad Constantinescu
VPN Expert & Privacy Advocate
Vlad might have a degree in Animal Husbandry and Livestock Management, but he's currently rocking anything software related, ranging from testing programs to writing in-depth reviews about them. He spent 3-4 years as a... Read more
Affiliate Disclosure
  • Raspberry Pi devices can be used for a lot of purposes, but one of the most popular ones is hosting private VPN servers.
  • Although it's not exactly easy to configure a VPN server on your RPi device, it's not rocket science, either.
  • Check out our VPN section for more news, guides, and reviews on VPNs.
  • Visit the How-To Hub to discover more VPN guides for common and uncommon issues.
How to set up VPN on Raspberry Pi

Raspberry Pi is a marvel of technological advancement, as it proves that strength isn’t all about size. The Raspberry Pi is actually a single-board computer.

Much like your phone, it can fit in your pocket (although it might look a bit bulgy) and, if you have the peripherals, can help you interface with it anywhere.

However, thanks to its size-based convenience, many choose to use these devices for very specific roles.

Some turn them into vintage arcades using emulators, while others use them as email servers, tiny media centers, or even VPN servers.

How to set up a VPN with Raspberry Pi?


  • Raspberry Pi (we used an RPi 2 model B)
  • A microSD card (for storage purposes)
  • An operating system (we used Rasperry Pi OS, formerly Raspbian)
  • Ethernet cable (using Wi-Fi is a bit more complicated)
  • USB cable (to power up the RPi)
  • A power source (we plugged our RPi into our router)
  • Peripherals (keyboard + mouse)
  • An HDMI cable
  • Display (monitor, TV)
  • An SSH client (we used Solar Putty)

Note that you won’t need all of these components to install the VPN on the Raspberry Pi. If you connect the device to a working Internet source, you can access it via SSH.

However, note that this method can have some drawbacks, as it involves having to reconnect to the RPi once you change network settings. We’ll get to that in just a bit.

Assuming that you have all the required components ready, let’s proceed with setting up the VPN on your RPi.

Connecting to your Raspberry Pi

  1. Plug the Ethernet cable into your router and Raspberry PiEthernet cable Raspberry Pi
  2. Connect your RPi to a power source (we used our router)Power source Raspberry Pi
  3. Install an SSH client on your computer
  4. Access your router’s gateway in your browser
  5. Locate and save the RPi’s local IP address
  6. Run the SSH client on your PC
  7. Create a new SSH session within the client
  8. Type the IP address you noted down earlier (or use raspberry/raspberry.local as the address)
  9. Use pi as username and raspberry as password
  10. Launch the session

Make sure everything is up-to-date

Before you proceed, you must understand that Raspberry Pi OS is more sensitive to change than, for instance, Windows.

Therefore, it won’t offer to fix any compatibility issues automatically.

Instead, you have to make sure that the environment is fit before installing anything, including VPN software on your Raspberry Pi.

Fortunately, doing so isn’t difficult with proper guidance.

Follow these steps:

  1. With the session active, type sudo apt-get update in the SSH terminalUpdate SSH Raspberry Pi
  2. Wait for the update process to finish
  3. Type sudo apt-get upgrade in the same terminal as beforeUpgrade SSH Raspberry Pi
  4. If prompted, type Y for confirmation and hit Enter on your keyboard
  5. Wait for the upgrade process to complete

Performing these two operations is of utmost importance, as running a VPN server implies a certain degree of security.

Keeping everything up-to-date on your Raspberry Pi device is a surefire method to avoid compatibility issues and exploitable vulnerabilities.

Note that these procedures can take quite a while, especially the upgrading part one. So, in the meantime…

Get a static IP address

Having a static IP address is quite important in this case. It will allow you to access your personal Raspberry Pi VPN server from virtually anywhere in the world without worrying that its IP will change at some point.

If you already have a static IP address, you should be fine.

Some ISPs offer this type of service by default, although many prefer the dynamic approach to solve (or better yet delay) the IP address pool exhaustion.

However, if you have a dynamic (that changes periodically) IP address, you can use DHCP or a free dynamic DNS service.

The DHCP method is a bit more complicated and depends on several factors such as router and ISP.

Thus, we suggest you pick a dynamic DNS service, but not before checking if your router has DDNS (dynamic DNS) support.

Installing PiVPN on Raspberry Pi

  1. In the SSH terminal, type curl -L | bashInstall PiVPN on RPi SSH
  2. Wait for the package configuration to unfold (automated)Installing packages PiVPN
  3. Confirm the turning of your Raspberry Pi into a VPN serverConfirm installation of PiVPN
  4. Acknowledge the DHCP settingsStatic IP address confirmation
  5. Choose Yes or No depending on your DHCP/manual static IP configuration situation
  6. Select a user (pi by default)
  7. Wait for the PiVPN installation to unfold for a while
  8. Select OpenVPN from the VPN menu by using the Space key on your keyboardChoose between WireGuard or OpenVPN
  9. Confirm by pressing Enter
  10. Choose No when prompted to customize settings (default settings are good enough)PiVPN settings customization
  11. Leave the default port open (1194)
  12. Choose the DNS provider of your VPN clients
  13. Select DNS if you don’t have a static IP addressStatic IP or DNS PiVPN
  14. Define the DNS name of the server if applicablePiVPN server's DNS name
  15. Make sure to enable unattended-upgrades
  16. Reboot the system, as recommended

That’s it, you’ve successfully installed PiVPN on your Raspberry Pi device. It’s not exactly rocket science but has a lot of steps, which can easily confuse novice users.

Create VPN profile

  1. Launch the SSH session once more
  2. In the terminal, type pivpn add
  3. Type a name for your client
  4. Define how many days until the certificate expires
  5. Type and confirm the password
How to add a PiVPN profile

After performing all the steps above, your VPN profile should be automatically created and you should now be able to use it without any issues.

Note that the profiles are saved on the RPi’s storage unit, so you’ll have to fetch them from there (you can use remote VNC or a card reader).

Note that you’ll also need to forward the port you used earlier. In our case, it was port 1194, so we forwarded this one.

Connect to your private RPi VPN

  1. Download OpenVPN Connect for Windows
  2. Install it on your PC
  3. Launch the OpenVPN Connect app
  4. Go to the File tabOpenVPN Connect file tab
  5. Browse to the OVPN file you got from your RPi
  6. Import it within the app
  7. Configure a profile name for itOpenVPN add profile name
  8. Click the Add button
  9. Flip the switch to activate the VPN connection
  10. Type the private key you used to create the profile
OpenVPN connected status

You should be now connected to the VPN server you personally configured on your RPi. The OpenVPN Connect client will show you some useful information such as your sent and received traffic, connection duration, and the time you received the last packet.

If for some reason you can’t connect to your VPN, check if you forwarded the port correctly (make sure to use the local IP address of your RPi instead of its external one).

Should you still be having difficulties, try the following:

  1. Reinstall PiVPN
  2. Make it use the public IP address (even if not static)
  3. Create the OVPN file
  4. Open the OVPN file in a text editor
  5. Replace the public IP with your DDNS manually

That’s it. The VPN connection should now work like a charm.


All things considered, it seems that the RPi is indeed a multi-talent tool that can also be used as your private, personal VPN server.

You can also connect to the VPN server with your phone. However, note that for every new client that connects to your server, you need to create a new VPN profile.

For better security, make sure that each profile has a different, strong password.

Your connection is not secure - websites you visit can find out your details:

  • Your IP
  • Your IP Address:

Companies can sell this information, alongside your location and internet provider name, and profit from it by serving targeted ads or monitoring your data usage.

Use a VPN to protect your privacy and secure your connection.

We recommend Private Internet Access, a VPN with a no-log policy, open source code, ad blocking and much more; now 79% off.

Frequently Asked Questions

  • If you’re decided to set up a personal VPN at home on Windows 10, check out our comprehensive guide and learn how to do it without efforts.

  • If you want to create a VPN connection in Windows 10 instead of using a VPN client, check out our detailed guide to learn how you can do that.

  • Yes, Windows 10 has a built-in VPN feature that you can use to connect to an existing VPN server. Our comprehensive guide will tell you all about it and how to use it.

This article covers:Topics: