LINUXOR.SK ... open source notes ...

2007 - Debian 4 - OpenVPN Howto

category: howtoz/archive · date: 2008-04-18 · source: old.linuxor.sk/VPN/BH_Debian4.0_OpenVPN.txt

The Slovak original of this document: 2007 - Debian 4 - OpenVPN Howto (slovensky).

Installing a VPN (OpenVPN)

asciiart
-----------------
 Install OpenVPN
-----------------

        # apt-get install liblzo1
        # apt-get install openvpn
        # apt-get install openssl

--------------------------------------
 Creating the Certification Authority
--------------------------------------

        # cp -R /usr/share/doc/openvpn/examples/easy-rsa /etc/
        # cd /etc/easy-rsa

        # chmod 744 ./vars
        # gunzip openssl.cnf.gz
        # . ./vars
        # ./clean-all

        # ./build-ca
        ------------
        Country Name (2 letter code) [KG]:SK
        State or Province Name (full name) [NA]:Slovakia
        Locality Name (eg, city) [BISHKEK]:Mesto
        Organization Name (eg, company) [OpenVPN-TEST]:Firma
        Organizational Unit Name (eg, section) []:IT
        Common Name (eg, your name or your server's hostname) []:CA
        Email Address [me@myhost.mydomain]:mail@firma.sk

-----------------------------------------
 Creating the certificate for the server
-----------------------------------------

        # ./build-key-server gw.firma.sk
        ------------------------------------------
        Country Name (2 letter code) [KG]:SK
        State or Province Name (full name) [NA]:Slovakia
        Locality Name (eg, city) [BISHKEK]:Mesto
        Organization Name (eg, company) [OpenVPN-TEST]:Firma
        Organizational Unit Name (eg, section) []:IT
        Common Name (eg, your name or your server's hostname) []:gw.firma.sk
        Email Address [me@myhost.mydomain]:mail@firma.sk

-----------------------------------------
 Creating the certificate for the client
-----------------------------------------

        # ./build-key klient1
        ---------------------
        Country Name (2 letter code) [KG]:SK
        State or Province Name (full name) [NA]:Slovakia
        Locality Name (eg, city) [BISHKEK]:Mesto
        Organization Name (eg, company) [OpenVPN-TEST]:Firma
        Organizational Unit Name (eg, section) []:IT
        Common Name (eg, your name or your server's hostname) []:klient1
        Email Address [me@myhost.mydomain]:mail@firma.sk

        # ./build-key klient2
        ---------------------
        Country Name (2 letter code) [KG]:SK
        State or Province Name (full name) [NA]:Slovakia
        Locality Name (eg, city) [BISHKEK]:Domica
        Organization Name (eg, company) [OpenVPN-TEST]:DomicaKomplex
        Organizational Unit Name (eg, section) []:IT
        Common Name (eg, your name or your server's hostname) []:klient2
        Email Address [me@myhost.mydomain]:mail@firma.sk

----------------------------------------
 Creating the Diffie Hellman parameters
----------------------------------------

        # ./build-dh

-----------------------------------------
 Creating the group and the user openvpn
-----------------------------------------

        # groupadd openvpn
        # useradd -d /dev/null -g openvpn -s /bin/false openvpn

--------------------------------
 OpenVPN configuration - server
--------------------------------

        # nano /etc/openvpn/server.conf
        -------------------------------
        proto tcp                               # protocol
        dev tun                                 # device
        ca ca.crt                               # CA certificate
        cert gw.firma.sk.crt                    # server certificate
        key gw.firma.sk.key                     # server key
        dh dh1024.pem                           # DH parameters
        server 10.10.10.0 255.255.255.0         # server=10.10.10.1, clients=10.10.10.0/24
        client-config-dir ccd
        push "route 192.168.1.0 255.255.255.0"  # tell the client the route into the network
        keepalive 10 120
        comp-lzo                                # lzo compression
        user openvpn                            # the user the openvpn process runs as
        group openvpn                           # the group the openvpn process runs as
        persist-key                             # to avoid accessing resources on restart that may no longer be accessible (e.g. chroot or a privilege downgrade), we use a persistent key
        persist-tun                             # ditto for the device
        status openvpn-status.log               # log the status messages to openvpn-status.log
        log-append openvpn.log                  # log the main messages to openvpn.log
        verb 3                                  # it won't be that chatty (1..10)
        chroot /etc/openvpn/                    # chroot the openvpn process into the directory /etc/openvpn
        -------------------------------END->/etc/openvpn/server.conf

        Set things up so that every client is always assigned the same IP address
        -------------------------------------------------------------------------

        # mkdir /etc/openvpn/ccd
        # nano /etc/openvpn/ccd/klient1
        -------------------------------
        ifconfig-push 10.10.10.5 10.10.10.6
        -------------------------------END->/etc/openvpn/ccd/klient1

        # nano /etc/openvpn/ccd/klient2
        -------------------------------
        ifconfig-push 10.10.10.7 10.10.10.8
        -------------------------------END->/etc/openvpn/ccd/klient2

--------------------------------
 OpenVPN configuration - client
--------------------------------

        # client.ovpn
        -------------------
        client                          # mode
        dev tun                         # device
        proto tcp                       # protocol
        remote 10.62.2.44 1194          # remote side
        resolv-retry infinite
        ns-cert-type server             # verify the server by its certificate ( against MITM )
        nobind                          # clients usually don't need to bind a specific port
        persist-key                     # to avoid accessing resources on restart that may no longer be accessible (e.g. chroot or a privilege downgrade), we use a persistent key
        persist-tun                     # ditto for the device
        route 192.168.1.0 255.255.255.0 # route into the internal network
        ca ca.crt                       # CA certificate
        cert klient1.crt                # client certificate
        key klient1.key                 # client key
        comp-lzo                        # lzo compression is used
        verb 1                          # almost the minimum of logs (1..10)
        -------------------END->client.ovpn

Current practice (checked 2026-10)

noteThe article above is kept as it was written in 2007. This section lists what has changed since and what to do instead today.

The certificate steps with easy-rsa 3:

bash
$ # ./easyrsa init-pki
$ # ./easyrsa build-ca
$ # ./easyrsa gen-req gw.firma.sk nopass
$ # ./easyrsa sign-req server gw.firma.sk
$ # ./easyrsa gen-req klient1 nopass
$ # ./easyrsa sign-req client klient1

Sources:

← howtoz/archive↓ bundle(EN | SK)