Configure your OpenVPN server on Linux (2024)

OpenVPN creates an encrypted tunnel between two points, preventing a third party from accessing your network traffic. By setting up your virtual private network (VPN) server, you become your own VPN provider. Many popular VPN services already use OpenVPN, so why tie your connection to a specific provider when you can have complete control?

The first article in this series set up a server for your VPN, and the second article demonstrated how to install and configure the OpenVPN server software. This third article shows how to start OpenVPN with authentication in place.

To set up an OpenVPN server, you must:

  • Create a configuration file.
  • Set the sysctl value net.ipv4.ip_forward = 1 to enable routing.
  • Set up appropriate ownership for all configuration and authentication files to run the OpenVPN server daemon under a non-root account.
  • Set OpenVPN to start with the appropriate configuration file.
  • Configure your firewall.

Configuration file

You must create a server config file in /etc/openvpn/server/. You can start from scratch if you want, and OpenVPN includes several sample configuration files to use as a starting point. Have a look in /usr/share/doc/openvpn/sample/sample-config-files/ to see them all.

If you want to build a config file by hand, start with either server.conf or roadwarrior-server.conf (as appropriate), and place your config file in /etc/openvpn/server. Both files are extensively commented, so read the comments and decide which makes the most sense for your situation.

You can save time and aggravation by using my prebuilt server and client configuration file templates and sysctl file to turn on network routing. This configuration also includes customization to log connects and disconnects. It keeps logs on the OpenVPN server in /etc/openvpn/server/logs.

If you use my templates, you'll need to edit them to use your IP addresses and hostnames.

To use my prebuilt config templates, scripts, and sysctl to turn on IP forwarding, download my script:

$ curl \https://www.dgregscott.com/ovpn/OVPNdownloads.sh > \OVPNdownloads.sh

Read the script to get an idea of what it does. Here's a quick overview of its actions:

  • Creates the appropriate directories on your OpenVPN server
  • Downloads server and client config file templates from my website
  • Downloads my custom scripts and places them into the correct directory with correct permissions
  • Downloads 99-ipforward.conf and places it into /etc/sysctl.d to turn on IP forwarding at the next boot
  • Sets up ownership for everything in /etc/openvpn

Once you're satisfied that you understand what the script does, make it executable and run it:

$ chmod +x OVPNdownloads.sh$ sudo ./OVPNdownloads.sh

Here are the files it copies (notice the file ownership):

$ ls -al -R /etc/openvpn/etc/openvpn:total 12drwxr-xr-x. 4 openvpn openvpn 34 Apr 6 20:35 .drwxr-xr-x. 139 root root 8192 Apr 6 20:35 ..drwxr-xr-x. 2 openvpn openvpn 33 Apr 6 20:35 clientdrwxr-xr-x. 4 openvpn openvpn 56 Apr 6 20:35 server/etc/openvpn/client:total 4drwxr-xr-x. 2 openvpn openvpn 33 Apr 6 20:35 .drwxr-xr-x. 4 openvpn openvpn 34 Apr 6 20:35 ..-rw-r--r--. 1 openvpn openvpn 1764 Apr 6 20:35 OVPNclient2020.ovpn/etc/openvpn/server:total 4drwxr-xr-x. 4 openvpn openvpn 56 Apr 6 20:35 .drwxr-xr-x. 4 openvpn openvpn 34 Apr 6 20:35 ..drwxr-xr-x. 2 openvpn openvpn 59 Apr 6 20:35 ccddrwxr-xr-x. 2 openvpn openvpn 6 Apr 6 20:35 logs-rw-r--r--. 1 openvpn openvpn 2588 Apr 6 20:35 OVPNserver2020.conf/etc/openvpn/server/ccd:total 8drwxr-xr-x. 2 openvpn openvpn 59 Apr 6 20:35 .drwxr-xr-x. 4 openvpn openvpn 56 Apr 6 20:35 ..-rwxr-xr-x. 1 openvpn openvpn 917 Apr 6 20:35 client-connect.sh-rwxr-xr-x. 1 openvpn openvpn 990 Apr 6 20:35 client-disconnect.sh/etc/openvpn/server/logs:total 0drwxr-xr-x. 2 openvpn openvpn 6 Apr 6 20:35 .drwxr-xr-x. 4 openvpn openvpn 56 Apr 6 20:35 ..

Here's the 99-ipforward.conf file:

# Turn on IP forwarding. OpenVPN servers need to do routingnet.ipv4.ip_forward = 1

Edit OVPNserver2020.conf and OVPNclient2020.ovpn to include your IP addresses. Also, edit OVPNserver2020.conf to include your server certificate names from earlier. Later, you will rename and edit a copy of OVPNclient2020.ovpn for use with your client computers. The blocks that start with ***? show you where to edit.

File ownership

If you used the automated script from my website, file ownership is already in place. If not, you must ensure that your system has a user called openvpn that is a member of a group named openvpn. You must set the ownership of everything in /etc/openvpn to that user and group. It's safe to do this if you're unsure whether the user and group already exist because useradd will refuse to create a user with the same name as one that already exists:

$ sudo useradd openvpn$ sudo chown -R openvpn.openvpn /etc/openvpn

Firewall

If you decided not to disable the firewalld service in step 1, then your server's firewall service might not allow VPN traffic by default.Using the firewall-cmd command, you can enable the OpenVPN service, which opens the necessary ports and routes traffic as necessary:

$ sudo firewall-cmd --add-service openvpn --permanent$ sudo firewall-cmd --reload

No need to get lost in a maze of iptables!

Start your server

You can now start your OpenVPN server. So that it starts automatically after a reboot, use the enable subcommand of systemctl:

systemctl enable --now [email protected]

Final steps

The fourth and final article in this article will demonstrate how to set up clients to connect to your OpenVPN from afar.

This article is based on D. Greg Scott's blog and is reused with permission.

Configure your OpenVPN server on Linux (1)This work is licensed under a Creative Commons Attribution-Share Alike 4.0 International License.

Configure your OpenVPN server on Linux (2024)

FAQs

Configure your OpenVPN server on Linux? ›

OpenVPN config files are usually located in /etc/openvpn and usually named *. conf . server. conf is canonical; client config filenames are usually like <client name/>.

How to set up an OpenVPN server on Linux? ›

How to Install OpenVPN Server on Ubuntu
  1. Step 1: Update and Upgrade Ubuntu. ...
  2. Step 2: Install OpenVPN. ...
  3. Step 3: Generate Certificates and Keys. ...
  4. Step 4: Configure OpenVPN. ...
  5. Step 5: Start and Enable OpenVPN. ...
  6. Step 6: Configure Firewall. ...
  7. Step 7: Connect to OpenVPN Server. ...
  8. 41 thoughts on - How to Install OpenVPN Server on Ubuntu.

How to configure VPN on Linux server? ›

How to set up a VPN on Linux with Network Manager
  1. Download our OpenVPN configuration files.
  2. Update your system and the Network manager.
  3. Import OpenVPN configuration files in the VPN settings.
  4. Connect to the VPN server, which settings you've just imported.
Sep 27, 2022

Where is the OpenVPN server config file in Linux? ›

OpenVPN config files are usually located in /etc/openvpn and usually named *. conf . server. conf is canonical; client config filenames are usually like <client name/>.

How to create an OpenVPN server? ›

The purpose of this article is to provide the know-how needed to configure a working OpenVPN server on a Windows PC.
  1. Step 1: installing OpenVPN software. ...
  2. Step 2: preparing EasyRSA. ...
  3. Step 3: generating certificates and keys. ...
  4. Step 4: OpenVPN server configuration. ...
  5. Step 5: configuring clients. ...
  6. Step 6: launching the server.

How to configure a VPN server? ›

Steps for setting up a VPN
  1. Step 1: Line up key VPN components. ...
  2. Step 2: Prep devices. ...
  3. Step 3: Download and install VPN clients. ...
  4. Step 4: Find a setup tutorial. ...
  5. Step 5: Log in to the VPN. ...
  6. Step 6: Choose VPN protocols. ...
  7. Step 7: Troubleshoot. ...
  8. Step 8: Fine-tune the connection.

How do I start OpenVPN server with config? ›

Right click on an OpenVPN configuration file (.ovpn) and select Start OpenVPN on this configuration file. Once running, you can use the F4key to exit. Once running in a command prompt window, OpenVPN can be stopped by the F4 key.

Can I create my own VPN in Linux? ›

To set up a Linux VPN server, ensure you have a compatible machine. While you can set it up on a local system, we recommend using a VPS hosting service since it is more affordable and simpler to manage.

Can you create your own VPN server? ›

Setting Up Your Own VPN Server

Creating a VPN at home requires time, technical knowledge, and a bit of elbow grease, but the result is a highly personalized and controlled online experience. You can tailor every aspect of a custom VPN, from choosing the security protocols to setting up the network configurations.

How to config VPN in Ubuntu? ›

Setting up Ubuntu built-in VPN client
  1. Click on the network connection icon in the top right corner of your desktop. ...
  2. In the settings, choose the "Network" tab on the left, and click "+" button opposite of the "VPN" label to add a new VPN connection:
  3. Choose L2TP tunneling protocol:

How to connect to OpenVPN using Linux? ›

Download and install the OpenVPN package
  1. Open the terminal window. You can do that by pressing Ctrl+Alt+T keys or navigating to it in your apps menu.
  2. Enter the following command to install all the necessary packages: sudo apt-get install openvpn unzip. You may need to enter your computer password to confirm this process.
5 days ago

What is the default config of OpenVPN server? ›

By default, Access Server comes configured with OpenVPN daemons listening on UDP port 1194 and TCP port 443. Access Server's web services also use TCP 443 for the web interfaces.

Where is the OpenVPN config in Ubuntu? ›

You can enable/disable various OpenVPN services on one system, but you could also let Ubuntu do it for you. There is a config for AUTOSTART in /etc/default/openvpn . Allowed values are “all”, “none” or a space-separated list of names of the VPNs. If empty, “all” is assumed.

What is the command to start OpenVPN server? ›

To run OpenVPN, you can:
  1. Right click on an OpenVPN configuration file (. ovpn) and select Start OpenVPN on this configuration file. ...
  2. Run OpenVPN from a command prompt Window with a command such as "openvpn myconfig. ovpn". ...
  3. Run OpenVPN as a service by putting one or more .

Is OpenVPN access server free? ›

Getting started with two free simultaneous connections

Access Server is free to install and use for a maximum of two simultaneous VPN connections, so you can test everything without having to pay first.

How to setup OpenVPN access server on Ubuntu? ›

The steps are as follows:
  1. Step 1 – Update your system. ...
  2. Step 2 – Find and note down your IP address. ...
  3. Step 3 – Download and run openvpn-install.sh script. ...
  4. Step 4 – Connect an OpenVPN server using iOS/Android/Linux/Windows desktop client. ...
  5. Step 5 – Verify/test the connectivity.
Mar 3, 2024

Top Articles
Sir Richard Branson (Billionaire) Supports Bitcoin, Buy Subway Sandwiches With Bitcoin, Bitcoin Auction Website Threatens Ebay, China Is Dominating Bitcoin Market
Airbnb Knows Why. Does Uber?
Evil Dead Movies In Order & Timeline
Videos De Mexicanas Calientes
Mylaheychart Login
Computer Repair Tryon North Carolina
Jesse Mckinzie Auctioneer
Concacaf Wiki
Mylife Cvs Login
1TamilMV.prof: Exploring the latest in Tamil entertainment - Ninewall
Mndot Road Closures
Bubbles Hair Salon Woodbridge Va
All Obituaries | Ashley's J H Williams & Sons, Inc. | Selma AL funeral home and cremation
Guardians Of The Galaxy Vol 3 Full Movie 123Movies
Buy PoE 2 Chaos Orbs - Cheap Orbs For Sale | Epiccarry
Bnsf.com/Workforce Hub
Dr Adj Redist Cadv Prin Amex Charge
Equibase | International Results
Ukc Message Board
Weepinbell Gen 3 Learnset
Aps Day Spa Evesham
Tyler Sis University City
The Weather Channel Local Weather Forecast
Employee Health Upmc
6 Most Trusted Pheromone perfumes of 2024 for Winning Over Women
Access a Shared Resource | Computing for Arts + Sciences
Gopher Carts Pensacola Beach
Taylored Services Hardeeville Sc
Life Insurance Policies | New York Life
Fastpitch Softball Pitching Tips for Beginners Part 1 | STACK
Ofw Pinoy Channel Su
Teenbeautyfitness
Skroch Funeral Home
Wow Quest Encroaching Heat
Page 5662 – Christianity Today
Lyca Shop Near Me
How are you feeling? Vocabulary & expressions to answer this common question!
Tiny Pains When Giving Blood Nyt Crossword
Barber Gym Quantico Hours
Carroll White Remc Outage Map
'Guys, you're just gonna have to deal with it': Ja Rule on women dominating modern rap, the lyrics he's 'ashamed' of, Ashanti, and his long-awaited comeback
Gym Assistant Manager Salary
US-amerikanisches Fernsehen 2023 in Deutschland schauen
How I Passed the AZ-900 Microsoft Azure Fundamentals Exam
bot .com Project by super soph
Erica Mena Net Worth Forbes
March 2023 Wincalendar
28 Mm Zwart Spaanplaat Gemelamineerd (U999 ST9 Matte | RAL9005) Op Maat | Zagen Op Mm + ABS Kantenband
Vrca File Converter
Phumikhmer 2022
Latest Posts
Article information

Author: Twana Towne Ret

Last Updated:

Views: 5699

Rating: 4.3 / 5 (64 voted)

Reviews: 87% of readers found this page helpful

Author information

Name: Twana Towne Ret

Birthday: 1994-03-19

Address: Apt. 990 97439 Corwin Motorway, Port Eliseoburgh, NM 99144-2618

Phone: +5958753152963

Job: National Specialist

Hobby: Kayaking, Photography, Skydiving, Embroidery, Leather crafting, Orienteering, Cooking

Introduction: My name is Twana Towne Ret, I am a famous, talented, joyous, perfect, powerful, inquisitive, lovely person who loves writing and wants to share my knowledge and understanding with you.