DEV Community

Cover image for How To Set Up a VPN Server on Linux for Free
Sudhir Bahadure
Sudhir Bahadure

Posted on

How To Set Up a VPN Server on Linux for Free

Introduction

Last week, I spent 3 hours trying to set up a VPN server on my Linux machine, only to realize I was making a simple mistake. This experience made me realize that many developers struggle with setting up a secure VPN server, and that's why I'm excited to share with you a step-by-step guide on how to set up a VPN server on Linux for free. By the end of this article, you will have a fully functional VPN server up and running, and you'll understand the importance of VPNs in 2026. To get started, you'll need:

  • A Linux machine with a valid IP address
  • A basic understanding of networking concepts
  • A text editor or terminal access

Table of Contents

Step 1 — Install OpenVPN

Installing OpenVPN is a crucial step in setting up a VPN server, as it provides the necessary tools to create and manage VPN connections. You can install OpenVPN using the following command:

sudo apt-get update
sudo apt-get install openvpn
Enter fullscreen mode Exit fullscreen mode

Expected output:

Reading package lists... Done
Building dependency tree
Reading state information... Done
openvpn is already the newest version (2.4.7-1ubuntu2).
0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.
Enter fullscreen mode Exit fullscreen mode

Step 2 — Configure OpenVPN

Configuring OpenVPN involves creating a configuration file that defines the VPN settings. You can create a new file using your favorite text editor:

sudo nano /etc/openvpn/server.conf
Enter fullscreen mode Exit fullscreen mode

Add the following configuration:

port 1194
proto udp
dev tun
ca ca.crt
cert server.crt
key server.key
dh dh2048.pem
Enter fullscreen mode Exit fullscreen mode

Expected output:

# OpenVPN configuration file
port 1194
proto udp
dev tun
ca ca.crt
cert server.crt
key server.key
dh dh2048.pem
Enter fullscreen mode Exit fullscreen mode

Step 3 — Generate Certificates

Generating certificates is an essential step in setting up a secure VPN connection. You can use the following command to generate the necessary certificates:

sudo openssl req -x509 -newkey rsa:2048 -nodes -keyout /etc/openvpn/server.key -out /etc/openvpn/server.crt -days 365
Enter fullscreen mode Exit fullscreen mode

Expected output:

Generating a 2048 bit RSA private key
........+++
........+++
writing new private key to '/etc/openvpn/server.key'
-----
Enter fullscreen mode Exit fullscreen mode

Step 4 — Set up the VPN Server

Setting up the VPN server involves starting the OpenVPN service and configuring the firewall rules. You can use the following command to start the OpenVPN service:

sudo systemctl start openvpn
Enter fullscreen mode Exit fullscreen mode

Expected output:

Started OpenVPN service.
Enter fullscreen mode Exit fullscreen mode

You'll also need to configure the firewall rules to allow incoming VPN connections:

sudo ufw allow openvpn
Enter fullscreen mode Exit fullscreen mode

Expected output:

Rule added
Enter fullscreen mode Exit fullscreen mode

Step 5 — Connect to the VPN Server

Connecting to the VPN server involves using an OpenVPN client to establish a connection to the VPN server. You can use the following command to connect to the VPN server:

sudo openvpn --config /etc/openvpn/client.conf
Enter fullscreen mode Exit fullscreen mode

Expected output:

Wed Mar 15 14:30:00 2026 OpenVPN 2.4.7 x86_64-pc-linux-gnu [SSL (OpenSSL)] [LZO] [EPOLL] [PKCS11] [MH/PKTINFO] [AEAD] built on Feb 20 2026
Wed Mar 15 14:30:00 2026 library versions: OpenSSL 1.1.1f  31 Mar 2020
Enter fullscreen mode Exit fullscreen mode

Real-World Usage

Now that you have a fully functional VPN server up and running, you can use it to secure your internet connection when using public Wi-Fi networks. For example, you can use the VPN server to encrypt your internet traffic when working remotely from a coffee shop.

Real-World Application

Setting up a VPN server is an essential step in securing your online presence, especially when working with sensitive data. By using a VPN server, you can ensure that your internet traffic is encrypted and protected from hackers. If you're looking for a reliable VPN solution, you can check out NordVPN (68% off + 3 months free) or Hostinger (up to 80% off hosting) for your hosting needs.

Conclusion

In this article, you learned how to set up a VPN server on Linux for free. Here are three key takeaways:

  1. Installing OpenVPN is a crucial step in setting up a VPN server.
  2. Configuring OpenVPN involves creating a configuration file that defines the VPN settings.
  3. Generating certificates is an essential step in setting up a secure VPN connection. What to build next? Check out our Linux & Security Deep Dives series for more tutorials on Linux and security.

💬 Your Turn

Have you automated your VPN setup before? What was your approach? Drop it in the comments — I read every one.

💡 Found this helpful?

If this tutorial saved you time or solved a problem, consider:

Support me on Ko-fi

Every coffee keeps me writing free tutorials like this one!


This article was written with AI assistance and reviewed for technical accuracy.
Part of the **Linux & Security Deep Dives* series — Follow for more free tutorials*

#aBotWroteThis

Top comments (0)