How to setup OpenVPN on CentOS 6, 7?

This tutorial explains how to setup Openvpn Access Server application on your CentOS 6 and 7 machine.

Prerequisites:
  • RHEL / CentOS Linux 6, 7 OS.
  • Enabled TUN / TAP kernel modules.
Summary:
  1. Update and prepare your CentOS system
  2. Install OpenVPN server
  3. Connect to the Admin panel
  4. Connect to the User Panel

1. Update and prepare your CentOS system

First, update your system and install the net-tools package, if it is not installed by default.

Command: yum update -y && yum install -y net-tools

Then, check if the TUN module is available on your system.

Command: cat /dev/net/tun

Expected output: cat: /dev/net/tun: File descriptor in bad state

If you receive no output, or the output message is different, it could mean that the TUN module is either not installed or not configured on your system. You can check the current state of the TUN module by running the following command. 

Command: lsmod | grep tun

Output:

tun 4242 -2 vhost_net
vznetstat 4242 -2 tun,ip_vznetstat,ip6_vznetstat

Finally, create the TUN device on your system.

Command: mkdir /dev/net && mknod /dev/net/tun c 10 200 && chmod 600 /dev/net/tun

NOTE: If you are using a VPS type server, you might need to contact your ISP and request to activate the TUN module manually for your server.

2. Install OpenVPN server

NOTE: You might want to check for newer versions of OpenVPN Access Server rpm packages.

  • Centos 6

Command: cd /tmp/ && wget http://swupdate.openvpn.org/as/openvpn-as-2.0.20-CentOS6.x86_64.rpm && rpm -i openvpn-as-2.0.20-CentOS6.x86_64.rpm

  • Centos 7

Command: cd /tmp/ && wget http://swupdate.openvpn.org/as/openvpn-as-2.0.10-CentOS7.x86_64.rpm && rpm -i openvpn-as-2.0.10-CentOS7.x86_64.rpm

You will see a similar output after the installation is complete.

Output:

The Access Server has been successfully installed in /usr/local/openvpn_as
Configuration log file has been written to /usr/local/openvpn_as/init.log
Please enter “passwd openvpn” to set the initial
administrative password, then login as “openvpn” to continue
configuration here: https://<Your_Server_IP>:943/admin
To reconfigure manually, use the /usr/local/openvpn_as/bin/ovpn-init tool.
Access Server web UIs are available here:
Admin UI: https://<Your_Server_IP>:943/admin
Client UI: https://<Your_Server_IP>:943/

Now, activate the administrator user “openvpn” by setting a new password.

Command: passwd openvpn

3. Connect to the Admin Panel

Enter the following URL in your web browser, connect to the Admin panel and start your vpn server.

https://<Your_Server_IP>:943/admin

4. Connect to the User Panel

First, create and activate a new user in your server command line, for example, “johnsmith”. This user will be your regular vpn user.

Command: useradd johnsmith

Command: passwd johnsmith

Now you can connect to your User panel (not the Admin panel) as a regular user. Use the following URL to connect to the User Panel. 

https://<Your_Server_IP>:943/

Once you are connected, you can download the pre-configured user config file for easy vpn access, get instructions on how to setup OpenVPN client on your computer (Linux, Windows, MacOS, Android) and how to connect to your OpenVPN server, using the newly installed OpenVPN client on your computer.

One Comment

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.