How to install OpenVPN Server on Debian 9

Debian Tutorial – This tutorial is going to show you how to install OpenVPN on Debian 9 Stretch. OpenVPN is a great solution that provide a secure connection over the internet. The VPN (Virtual Private Network) can protect you from the bad guy when you connected to public WiFi or else.

On this example, I have a droplet (virtual server) at DigitalOcean. You may also power up a small droplet like mine with $5 per month. Make a note the public IP address of the droplet. We will use the IP address of the droplet on this tutorial. For example, your public IP is : 139.59.105.22

Steps to install OpenVPN on Debian 9

Step 1. Get the Public IP address

In DigitalOcean dashboard, you can see current IP address of the droplet easily.

Step 2. Update and Upgrade Debian

Make sure your system is up to date.

Step 3. Install and configure UFW (Uncomplicated Firewall)

We need to install and configure the UFW on Debian 9. Its pretty easy.

Install UFW

Configure ufw to enable some important ports

Output

At this point ufw is up and running and access to port 80, 442 and 22 is enabled.

Step 4. Download install script

Step 5. Run the install script

You will be asked to enter your IP address, port etc. Please make sure you change the IP address with your Public IP address.
The installation process will take place. It took some times so be patient. At this point, our OpenVPN Server is ready. You can now check firewall rule
Output
How to start, stop and check status of the OpenVPN Server Service
Download the configuration file

Now we can download the ovpn configuration file. This file will be used to connect to the server. We can use scp command to do this

scp root@139.59.105.22:~/debian-openvpn.ovpn /home/dhani/Desktop

Change the details above with your own.

3 Comments

  1. Bonjour,

    Merci pour votre tuto.
    Je viens de faire l’installation d’openVPN sur mon serveur qui est sous Debian 9 sur lequel j’ai créer une seedbox et après avoir utilisé la commande “systemctl start openvpn@server” j’ai vérifier en utilisant la commande “systemctl status openvpn@server” et la voici ce qui est apparu :

    root@ns335252:~# systemctl start openvpn@server
    root@ns335252:~# systemctl status openvpn@server
    openvpn@server.service – OpenVPN connection to server
    Loaded: loaded (/lib/systemd/system/openvpn@.service; disabled; vendor preset
    Active: failed (Result: exit-code) since Sun 2017-12-03 00:34:39 CET; 29s ago
    Docs: man:openvpn(8)
    https://community.openvpn.net/openvpn/wiki/Openvpn23ManPage
    https://community.openvpn.net/openvpn/wiki/HOWTO
    Process: 24488 ExecStart=/usr/sbin/openvpn –daemon ovpn-server –status /run/
    Main PID: 24489 (code=exited, status=1/FAILURE)

    déc. 03 00:34:39 ns335252 ovpn-server[24489]: Could not determine IPv4/IPv6 prot
    déc. 03 00:34:39 ns335252 ovpn-server[24489]: Socket Buffers: R=[212992->212992]
    déc. 03 00:34:39 ns335252 ovpn-server[24489]: TCP/UDP: Socket bind failed on loc
    déc. 03 00:34:39 ns335252 ovpn-server[24489]: Exiting due to fatal error
    déc. 03 00:34:39 ns335252 ovpn-server[24489]: Closing TUN/TAP interface
    déc. 03 00:34:39 ns335252 ovpn-server[24489]: /sbin/ip addr del dev tun1 10.8.0.
    déc. 03 00:34:39 ns335252 systemd[1]: Started OpenVPN connection to server.
    déc. 03 00:34:39 ns335252 systemd[1]: openvpn@server.service: Main process exite
    déc. 03 00:34:39 ns335252 systemd[1]: openvpn@server.service: Unit entered faile
    déc. 03 00:34:39 ns335252 systemd[1]: openvpn@server.service: Failed with result
    lines 1-19/19 (END)
    openvpn@server.service – OpenVPN connection to server
    Loaded: loaded (/lib/systemd/system/openvpn@.service; disabled; vendor preset: enabled)
    Active: failed (Result: exit-code) since Sun 2017-12-03 00:34:39 CET; 29s ago
    Docs: man:openvpn(8)
    https://community.openvpn.net/openvpn/wiki/Openvpn23ManPage
    https://community.openvpn.net/openvpn/wiki/HOWTO
    Process: 24488 ExecStart=/usr/sbin/openvpn –daemon ovpn-server –status /run/openvpn/se
    Main PID: 24489 (code=exited, status=1/FAILURE)

    déc. 03 00:34:39 ns335252 ovpn-server[24489]: Could not determine IPv4/IPv6 protocol. Usin
    déc. 03 00:34:39 ns335252 ovpn-server[24489]: Socket Buffers: R=[212992->212992] S=[212992
    déc. 03 00:34:39 ns335252 ovpn-server[24489]: TCP/UDP: Socket bind failed on local address
    déc. 03 00:34:39 ns335252 ovpn-server[24489]: Exiting due to fatal error
    déc. 03 00:34:39 ns335252 ovpn-server[24489]: Closing TUN/TAP interface
    déc. 03 00:34:39 ns335252 ovpn-server[24489]: /sbin/ip addr del dev tun1 10.8.0.1/24
    déc. 03 00:34:39 ns335252 systemd[1]: Started OpenVPN connection to server.
    déc. 03 00:34:39 ns335252 systemd[1]: openvpn@server.service: Main process exited, code=ex
    déc. 03 00:34:39 ns335252 systemd[1]: openvpn@server.service: Unit entered failed state.
    déc. 03 00:34:39 ns335252 systemd[1]: openvpn@server.service: Failed with result ‘exit-cod
    ~
    ~
    Dons si j’ai bien compris celui ne fonctionne pas correctement.
    Pouvez-vous me venir en aide.
    Je vous en remercie par avance.
    (Je suis débutant sous Linux)
    Samuël

  2. J’ai fait une erreur lorsque j’ai posté ma question, j’aurais surement du masqué le nom de mon serveur a chaque fois

Leave a Reply

Your email address will not be published.


*