Mainos / Advertisement:

Ero sivun ”Openvpn” versioiden välillä

Kohteesta Taisto
Siirry navigaatioon Siirry hakuun
 
(35 välissä olevaa versiota samalta käyttäjältä ei näytetä)
Rivi 1: Rivi 1:
 
<languages/>
 
<languages/>
 
<translate>
 
<translate>
<!--T:1-->
+
 
 +
<!--T:39-->
 
OpenVPN on avoimella lähdekoodilla toimiva VPN. Tämä on yksi maailman turvallisimmista VPN protokollista. OpenVPN eroaa muista VPN protokollista, että vaatii erillisen asiakasohjelman muodostaakseen yhteyden palvelimeen.  
 
OpenVPN on avoimella lähdekoodilla toimiva VPN. Tämä on yksi maailman turvallisimmista VPN protokollista. OpenVPN eroaa muista VPN protokollista, että vaatii erillisen asiakasohjelman muodostaakseen yhteyden palvelimeen.  
  
 +
== Asennus == <!--T:40-->
  
== Asennus ==
+
<!--T:41-->
 +
Asenna OpenVPN paketti pakettihallinnasta palvelin ja asiakaslaitteille. Windowssille löytyy erillinen paketti [https://openvpn.net/index.php/open-source/downloads.html täältä].
  
   aptitude install openvpn
+
   <!--T:42-->
 +
sudo apt install openvpn
  
== Konfigurointi ==
+
== Konfigurointi == <!--T:43-->
  
=== Sertifikaatit ===
+
=== Sertifikaatit === <!--T:44-->
  
 +
<!--T:45-->
 
Asennuksen jälkeen sinun tulee kopioida oletushakemistosta tiedostoja jotta palvelin voi lukea niitä
 
Asennuksen jälkeen sinun tulee kopioida oletushakemistosta tiedostoja jotta palvelin voi lukea niitä
  
   cp -r /usr/share/doc/openvpn/examples/easy-rsa /etc/openvpn
+
   <!--T:46-->
 +
cp -r /usr/share/doc/openvpn/examples/easy-rsa /etc/openvpn
  
 +
Jessie tai uudemmissa:
 +
 +
cp -r /usr/share/easy-rsa /etc/openvpn/easy-rsa
 +
 +
<!--T:47-->
 
Tämän  jälkeen siirrytään generoimaan RSA avaimet VPN palvelua varten.  
 
Tämän  jälkeen siirrytään generoimaan RSA avaimet VPN palvelua varten.  
  
   cd /etc/openvpn/easy-rsa/2.0/
+
   <!--T:48-->
 +
cd /etc/openvpn/easy-rsa/2.0/
  
 +
<!--T:49-->
 
Muokkaa tämän jälkeen vars tiedostoa
 
Muokkaa tämän jälkeen vars tiedostoa
  
   nano /etc/openvpn/easy-rsa/2.0/vars
+
   <!--T:50-->
 +
nano /etc/openvpn/easy-rsa/2.0/vars
  
 +
<!--T:51-->
 
vars - tiedostossa muuta export KEY_SIZE 1024 -> 2048
 
vars - tiedostossa muuta export KEY_SIZE 1024 -> 2048
  
 +
<!--T:52-->
 
<pre>
 
<pre>
 
# Increase this to 2048 if you
 
# Increase this to 2048 if you
Rivi 36: Rivi 52:
 
</pre>
 
</pre>
  
 +
<!--T:53-->
 
Voit halutessasi kirjoittaa valmiiksi konfiguroinnit tähän tiedostoon.
 
Voit halutessasi kirjoittaa valmiiksi konfiguroinnit tähän tiedostoon.
  
 +
<!--T:54-->
 
Tallenna ja sulje tiedosto sekä käynnistä openvpn palvelu uudelleen
 
Tallenna ja sulje tiedosto sekä käynnistä openvpn palvelu uudelleen
  
   service openvpn restart
+
   <!--T:55-->
 +
service openvpn restart
 +
 
 +
<!--T:56-->
 +
Määritetään konfigurointitiedosto ./vars ja tyhjennetään vanhat avaimet
 +
 
 +
  <!--T:57-->
 +
source ./vars
  
Tämän jälkeen generoidaan RSA tiedostot
+
  <!--T:58-->
 +
./clean-all
  
  source ./vars
+
==== Root sertifikaatti ==== <!--T:59-->
  
  ./clean-all
+
<!--T:60-->
 +
Luodaan root sertifikaatti
  
   ./build-ca
+
   <!--T:61-->
 +
./build-ca
  
 +
<!--T:62-->
 
Tämän jälkeen vastaa ohjattuun velhoon:
 
Tämän jälkeen vastaa ohjattuun velhoon:
  
 +
<!--T:63-->
 
<pre>
 
<pre>
 
Generating a 2048 bit RSA private key
 
Generating a 2048 bit RSA private key
Rivi 75: Rivi 105:
 
</pre>
 
</pre>
  
 +
==== Palvelin sertifikaatti ==== <!--T:64-->
 +
 +
<!--T:65-->
 
Sertifikaatin genroimisen jälkeen luodaan privaattiavain palvelimelle. Muuta vpn.taisto.org vastaamaan palvelimesi nimeä.  
 
Sertifikaatin genroimisen jälkeen luodaan privaattiavain palvelimelle. Muuta vpn.taisto.org vastaamaan palvelimesi nimeä.  
  
   ../build-key-server vpn.taisto.org
+
   <!--T:66-->
 +
./build-key-server vpn.taisto.org
  
 +
<!--T:67-->
 
Tämän jälkeen vastaa jälleen seuraa velhoa
 
Tämän jälkeen vastaa jälleen seuraa velhoa
  
 +
<!--T:68-->
 
<pre>
 
<pre>
 
Generating a 2048 bit RSA private key
 
Generating a 2048 bit RSA private key
Rivi 103: Rivi 139:
  
  
 +
<!--T:69-->
 
Please enter the following 'extra' attributes
 
Please enter the following 'extra' attributes
 
to be sent with your certificate request
 
to be sent with your certificate request
Rivi 123: Rivi 160:
  
  
 +
<!--T:70-->
 
1 out of 1 certificate requests certified, commit? [y/n]y
 
1 out of 1 certificate requests certified, commit? [y/n]y
 
Write out database with 1 new entries
 
Write out database with 1 new entries
Rivi 128: Rivi 166:
 
</pre>
 
</pre>
  
 +
<!--T:71-->
 
Generoi Diffie Helman key exhange parametri. Tässä menee hetki.
 
Generoi Diffie Helman key exhange parametri. Tässä menee hetki.
  
   ./build-dh
+
   <!--T:72-->
 +
./build-dh
 +
 
 +
 
 +
==== Asiakas sertifikaatti ==== <!--T:73-->
  
 +
<!--T:74-->
 
Nyt luodaan OpenVPN asiakkaille sertifikaatti. Jokaisella asiakkaalla tulee olla oma sertifikaatti. Muuta client vastaamaan asiakkaan isäntänimeä.
 
Nyt luodaan OpenVPN asiakkaille sertifikaatti. Jokaisella asiakkaalla tulee olla oma sertifikaatti. Muuta client vastaamaan asiakkaan isäntänimeä.
  
   ./build-key client
+
   <!--T:75-->
 +
./build-key client
  
 +
<!--T:76-->
 
<pre>
 
<pre>
 
Generating a 2048 bit RSA private key
 
Generating a 2048 bit RSA private key
Rivi 158: Rivi 204:
  
  
 +
<!--T:77-->
 
Please enter the following 'extra' attributes
 
Please enter the following 'extra' attributes
 
to be sent with your certificate request
 
to be sent with your certificate request
Rivi 178: Rivi 225:
  
  
 +
<!--T:78-->
 
1 out of 1 certificate requests certified, commit? [y/n]y
 
1 out of 1 certificate requests certified, commit? [y/n]y
 
Write out database with 1 new entries
 
Write out database with 1 new entries
Rivi 183: Rivi 231:
 
</pre>
 
</pre>
  
 +
<!--T:79-->
 
Kopioi Root, palvelin sekä DH param sertifikaatti tiedostot OpenVPN root hakemistoon:
 
Kopioi Root, palvelin sekä DH param sertifikaatti tiedostot OpenVPN root hakemistoon:
  
 +
<!--T:80-->
 
<pre>
 
<pre>
 
cp /etc/openvpn/easy-rsa/2.0/keys/ca.crt /etc/openvpn
 
cp /etc/openvpn/easy-rsa/2.0/keys/ca.crt /etc/openvpn
Rivi 193: Rivi 243:
 
</pre>
 
</pre>
  
= Vanha ohje =
+
==== Kumoa sertifikaatti ==== <!--T:81-->
 +
 
 +
<!--T:82-->
 +
Seuraavilla komennoilla voit kumota käyttäoikeuden palvelimeen. Muuta client1 nimeä asiakasnimeksi minkä oikeuden haluat peruuttaa.
 +
 
 +
  <!--T:83-->
 +
. /etc/openvpn/easy-rsa/2.0/vars
 +
  . /etc/openvpn/easy-rsa/2.0/revoke-full client1
 +
 
 +
=== Palvelimen konfigurointi === <!--T:84-->
 +
 
 +
<!--T:85-->
 +
Pura ZIP tiedosto
 +
 
 +
  <!--T:86-->
 +
gunzip -d /usr/share/doc/openvpn/examples/sample-config-files/server.conf.gz
 +
 
 +
<!--T:87-->
 +
Kopioi esimerkki palvelin konfigurointi tiedosto /etc/openvpn hakemistoon
 +
 
 +
  <!--T:88-->
 +
cp /usr/share/doc/openvpn/examples/sample-config-files/server.conf /etc/openvpn
 +
 
 +
<!--T:89-->
 +
Sinun tulee vielä muokata server.conf tiedostossa muutama kohta ennen kuin voidaan ottaa OpenVPN palvelin käyttöön:
 +
 
 +
  <!--T:90-->
 +
nano /etc/openvpn/server.conf
 +
 
 +
<!--T:91-->
 +
* Oikeat avain tiedostot ja niiden polku
 +
<pre>
 +
# SSL/TLS root certificate (ca), certificate
 +
# (cert), and private key (key).  Each client
 +
# and the server must have their own cert and
 +
# key file.  The server and all clients will
 +
# use the same ca file.
 +
#
 +
# See the "easy-rsa" directory for a series
 +
# of scripts for generating RSA certificates
 +
# and private keys.  Remember to use
 +
# a unique Common Name for the server
 +
# and each of the client certificates.
 +
#
 +
# Any X509 key management system can be used.
 +
# OpenVPN can also use a PKCS #12 formatted key file
 +
# (see "pkcs12" directive in man page).
 +
ca ca.crt
 +
cert server.crt
 +
key server.key  # This file should be kept secret
 +
 
 +
<!--T:92-->
 +
# Diffie hellman parameters.
 +
# Generate your own with:
 +
#  openssl dhparam -out dh1024.pem 1024
 +
# Substitute 2048 for 1024 if you are using
 +
# 2048 bit keys.
 +
dh dh2028.pem
 +
</pre>
 +
 
 +
<!--T:93-->
 +
Lopuksi käynnistä VPN palvelu uudelleen
 +
 
 +
  <!--T:94-->
 +
service openvpn restart
 +
 
 +
==== Esimerkki palvelin konfiguraatio ====
 +
 
 +
<pre>
 +
proto tcp
 +
port 1194
 +
dev tun
 +
server 10.0.8.0 255.255.255.0
 +
topology subnet
 +
#ifconfig-pool-persist ipp.txt
 +
push "route 10.84.0.0 255.255.255.0"
 +
push "redirect-gateway def1"
 +
push "dhcp-option DNS 8.8.8.8"
 +
push "dhcp-option DNS 8.8.4.4"
 +
;client-to-client
 +
;duplicate-cn
 +
keepalive 10 120
 +
cipher BF-CBC        # Blowfish (default)
 +
;cipher AES-128-CBC  # AES
 +
;cipher DES-EDE3-CBC  # Triple-DES
 +
max-clients 100
 +
;user nobody
 +
;group nobody
 +
persist-key
 +
persist-tun
 +
status /var/log/openvpn-status.log
 +
log /var/log/openvpn.log
 +
log-append /var/log/openvpn.log
 +
verb 3
 +
</pre>
 +
 
 +
 
 +
=== Reititykset palvelimella ===
  
===== Esimerkkimme ===== <!--T:2-->
+
Salli IPv4 forward:
  
<!--T:3-->
+
  echo 1 > /proc/sys/net/ipv4/ip_forward
Esimerkissämme luomma yhteyden konffijh:n kotipalvelimelta gugglan koneelle. konffijh:lla on kotona hp palvelin missä on virtuaalidebian ja koululla on samanlainen hp kone missä on myös virtuaalidebian. Kotona on openvpnserveri ja koululla taas clientti
 
  
<!--T:4-->
+
Lisää NAT sääntö iptables
* Jh:n verkko kotona: 192.168.112.0/24
 
* kotigw: 192.168.112.254 (mikrotikki )
 
* openvpnservu: 192.168.112.3
 
* openvpnclientti: 192.168.7.7
 
* jh:n säätöverkko koulussa: 192.168.7.0/24
 
* portti: 1723
 
* Virtuaaliverkko: 10.10.7.0/24
 
  
== Palvelimen asennus ja konfigurointi  == <!--T:5-->
+
  iptables -t nat -A POSTROUTING -s 10.8.0.0/24 -o eth0 -j MASQUERADE
  
<!--T:6-->
+
Voit myös sillata bridge-utilsin avulla yhteyden.
Asennetaan openvpn pakettihallinnasta.
 
  
  <!--T:7-->
+
=== IPv6 ===
[[aptitude]] install openvpn
 
  
=== Sertifikaattien asennus === <!--T:8-->
+
Ota käyttöön OpenVPN IPv6 UDP tunneli
Kopioi certificate luontiin tarvittavat tiedostot openvpn kansioon
 
  
   <!--T:9-->
+
   proto udp6
cp -R /usr/share/doc/openvpn/examples/easy-rsa /etc/openvpn
 
  
 +
Tai TCP
  
<!--T:10-->
+
  proto tcp6
Luo avaimet seuraavasti /etc/openvpn/easy-rsa/2.0 hakemistossa (jos et tiedä mitä vastata kysymyksiin avaimia luotaessa, katso
 
OpenVPN HOWTO):
 
  
<!--T:11-->
+
Lisää palvelimen konfiguraatioon.  
cd /etc/openvpn/easy-rsa/2.0
 
  
<!--T:12-->
+
<pre>
Voit muokata seuraavassa tiedostossa certificaten määrityksiä
+
tun-ipv6
nano vars
+
push tun-ipv6
 +
</pre>
  
    <!--T:13-->
+
Lisää IPv6 osoite (oma /64 esimerkiksi). Ensimmäinen osoite käyttää palvelin ja muut jaetaan.
. ./vars
 
    ./clean-all
 
    ./build-ca
 
    ./build-key-server server
 
    ./build-key client
 
    ./build-dh
 
  
<!--T:14-->
+
  server-ipv6 2001::2003::/64
Lisää clientejä luodaan komennolla
 
./build-key client2
 
./build-key jonne
 
  
<!--T:15-->
+
Lisää reititys
Sijoita luomasi avaimet haluamaasi paikkaan. Omani ovat /etc/openvpn/dataa-hakemistossa.
 
  
<!--T:16-->
+
  push "route-ipv6 2000::/3"
Serverin conffitiedoston voi joko tehdä itse tai kopioida /usr/share/doc/openvpn/examples/sample-config-files/server.conf.gz. Siitä tarvii vain muokata serttien nimet ja halutessaan verkko-osoitteet. Tiedosto tarvii toki purkaa komennolla gunzip.
 
  
=== HOST to LAN === <!--T:17-->
 
  
 +
=== Asiakkaan konfigurointi === <!--T:95-->
  
<!--T:18-->
+
Asenna OpenVPN asiakaskoneelle
Alla konfiguraatiotiedosto palvelimelle jos sen haluaa tästä ottaa.
 
  
=== LAN to LAN === <!--T:19-->
+
  aptitude install openvpn
nano /etc/openvpn/server.conf
+
 
 +
<!--T:96-->
 +
Kopioi OpenVPN palvelimelta client.conf tiedosto omaan kotihakemistoon ja siirrä omalle asiakaslaitteelle
 +
 
 +
  <!--T:97-->
 +
cp /usr/share/doc/openvpn/examples/sample-config-files/client.conf ~/
 +
 
 +
<!--T:98-->
 +
Kopioi lisäksi ca (ca.crt) ja client sertifikaatit (client.crt) sekä privaattiavain (client.key) asiakaslaitteelle.
 +
 
 +
<!--T:99-->
 +
Avaa client.conf tiedosto
 +
 
 +
<!--T:100-->
 +
nano ~/client.conf
 +
 
 +
<!--T:101-->
 +
Muokkaa tämä tiedosto seuraavanlaiseksi:
 +
 
 +
<!--T:102-->
 +
* Määritä OpenVPN palvelimen osoite sekä portti, oletus 1194
 +
<pre>
 +
# The hostname/IP and port of the server.
 +
# You can have multiple remote entries
 +
# to load balance between the servers.
 +
remote my-server-1 1194
 +
;remote my-server-2 1194
 +
</pre>
 +
 
 +
<!--T:103-->
 +
* Määritä sertifikaattien polku
 +
<pre>
 +
# SSL/TLS parms.
 +
# See the server config file for more
 +
# description.  It's best to use
 +
# a separate .crt/.key file pair
 +
# for each client.  A single ca
 +
# file can be used for all clients.
 +
ca ca.crt
 +
cert client.crt
 +
key client.key
 +
</pre>
 +
 
 +
Käynnistä OpenVPN
 +
 
 +
  openvpn --config client.ovpn
 +
 
 +
==== Käynnistä OpenVPN profiilit palvelun käynnistyttyä ====
 +
 
 +
Avaa seuraava tiedosto
 +
 
 +
  nano /etc/default/openvpn
 +
 
 +
Poista risuaita riviltä
 +
 
 +
  AUTOSTART="all"
 +
 
 +
Tallenna tiedosto
 +
 
 +
Muuta *.ovpn tiedostot *.conf tiedostoiksi. Vain .conf tiedostot ladataan uudeelleen käynnistäessä OpenVPN prosessia
 +
 
 +
==== GUI ====
 +
 
 +
  aptitude install openvpn network-manager-openvpn
 +
 
 +
  service network-manager-restart
 +
 
 +
=== Radius todennus ===
 +
 
 +
Asenna seuraavat paketit
 +
 
 +
  apt-get install libgcrypt11 libgcrypt11-dev gcc make build-essential g++
 +
 
 +
Lataa Radius plugin
 +
 
 +
  wget http://www.nongnu.org/radiusplugin/radiusplugin_v2.1a_beta1.tar.gz
 +
 
 +
Pura tar tiedosto
 +
 
 +
  tar xvfz radiusplugin_v2.1a_beta1.tar.gz
 +
 
 +
Siirry hakemistoon
 +
 
 +
  cd radiusplugin_v2.1a_beta1/
  
<!--T:20-->
+
Käännä se
dev tun
 
port 1723
 
proto tcp
 
ca /etc/openvpn/ca.crt ## Muuta vastamaan omia certejä
 
cert /etc/openvpn/server.crt ##
 
key /etc/openvpn/server.key ##
 
dh /etc/openvpn/dh1024.pem ##
 
server 10.123.123.0 255.255.255.0 ## Muuta vastamaan omaa
 
ifconfig-pool-persist ipp.txt
 
comp-lzo
 
persist-key
 
persist-tun
 
status /var/log/openvpn-status.log
 
verb 3
 
client-to-client
 
client-config-dir ccd
 
route 192.168.0.0 255.255.255.0
 
  
 +
  make
  
<!--T:21-->
+
Kopioi OpenVPN kansioon seuraavat tiedostot
8. Avaa UDP-portti 1723 palomuurissasi ja lisää myös tarvittavat säännöt tun-adaptereille esim. seuraavasti (tämä tapa voi erota käyttämästäsi tavasta, joten sovella tarvittaessa):
 
  
          <!--T:22-->
+
  cp radiusplugin.so /etc/openvpn/
iptables -A INPUT -i tun+ -j ACCEPT
+
  cp radiusplugin.cnf /etc/openvpn/
          iptables -A FORWARD -i tun+ -j ACCEPT
 
          iptables -A FORWARD -o tun+ -j ACCEPT
 
9. Tämän jälkeen tarvitset vielä OpenVPN:n (Windows GUI) ja konfiguraatiotiedoston clientille:
 
  
<!--T:23-->
+
Konfiguroi Radiuspalvelimen asetukset
client
 
dev tun
 
port 1723
 
proto tcp
 
remote joh.dy.fi 1723
 
nobind
 
ca /etc/openvpn/keys/ca.crt
 
cert /etc/openvpn/keys/client2.crt
 
key /etc/openvpn/keys/client2.key
 
comp-lzo
 
persist-key
 
persist-tun
 
verb 3
 
route 192.168.0.0 255.255.255.0
 
keepalive 10 60
 
  
<!--T:24-->
+
<pre>
service openvpn restart
+
server
 +
{
 +
        # The UDP port for radius accounting.
 +
        acctport=1813
 +
        # The UDP port for radius authentication.
 +
        authport=1812
 +
        # The name or ip address of the radius server.
 +
        name=YOUR RADIUS SERVER IP
 +
        # How many times should the plugin send the if there is no response?
 +
        retry=1
 +
        # How long should the plugin wait for a response?
 +
        wait=1
 +
        # The shared secret.
 +
        sharedsecret=YOUR RADIUS SERVER SECRET
 +
}
 +
</pre>
  
<!--T:25-->
+
Lisää tämä server.conf tiedostoon
nyt voi pingata esim. kotiservulta 10.10.7.10(koulun clientti).
 
  
 +
  plugin /etc/openvpn/radiusplugin.so /etc/openvpn/radiusplugin.cnf
  
<!--T:26-->
+
Käynnistä OpenVPN uudelleen
Näin sinulla on toimiva OpenVPN-konfiguraatio ja voit tunneloida yhteyksiäsi turvallisesti ja helposti. Heitä kommenttia jos joku asia jäi epäselväksi tai ohjeissa on sinun mielestäsi jotain, minkä voisin tehdä paremmin.
 
  
===pam auth=== <!--T:27-->
+
  service openvpn restart
  
<!--T:28-->
 
Client side:
 
  
<!--T:29-->
+
== Testaus ==
auth-user-pass
 
  
<!--T:30-->
+
1. Käynnistä palvelin jos ei ole jo käynnistetty
Server side:
 
  
<!--T:31-->
+
2. Käynnistä asiakas jos ei ole jo käynnistetty
plugin /usr/share/openvpn/plugin/lib/openvpn-auth-pam.so system-auth
 
  
=== http proxy === <!--T:32-->
+
3. aja ifconfig komento OpenVPN asiakkaalla. Sielä tulisi näkyä tun0 tai vastaava interface. Lisäksi näkyy osoite sielä.
  
<!--T:33-->
+
<pre>
Http proxyn asettaminen openvpn
+
tun0      Link encap:UNSPEC  HWaddr 00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00 
 +
          inet addr:10.8.0.6  P-t-P:10.8.0.5  Mask:255.255.255.255
 +
          UP POINTOPOINT RUNNING NOARP MULTICAST  MTU:1500  Metric:1
 +
          RX packets:0 errors:0 dropped:0 overruns:0 frame:0
 +
          TX packets:14 errors:0 dropped:0 overruns:0 carrier:0
 +
          collisions:0 txqueuelen:100
 +
          RX bytes:0 (0.0 B)  TX bytes:896 (896.0 B)
 +
</pre>
  
<!--T:34-->
+
4. Pingaa palvelimeen oikeaan IP-osoiteeseen.  
http-proxy 192.168.4.1 1080
 
  
<!--T:35-->
+
5. pingaa palvelinkoneelta asiakaskoneelle.
Debian 6:sen openvpn:ssä on bugi jonka seurauksena openvpn kaatuu. Ongelman voi korjata laittamalla kyseisen option
 
  
  <!--T:36-->
+
6 Tarkita toimiiko DNS nslookup komennolla.
http-proxy-retry
 
  
<!--T:37-->
+
== Lähteet ==
Linkki bugiin:
 
  
<!--T:38-->
+
https://wiki.debian.org/openvpn%20for%20server%20and%20client
http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=514718
 
  
 +
https://www.digitalocean.com/community/tutorials/how-to-setup-and-configure-an-openvpn-server-on-debian-6
 
</translate>
 
</translate>

Nykyinen versio 25. toukokuuta 2017 kello 07.05

Muut kielet:
English • ‎suomi

OpenVPN on avoimella lähdekoodilla toimiva VPN. Tämä on yksi maailman turvallisimmista VPN protokollista. OpenVPN eroaa muista VPN protokollista, että vaatii erillisen asiakasohjelman muodostaakseen yhteyden palvelimeen.

Asennus

Asenna OpenVPN paketti pakettihallinnasta palvelin ja asiakaslaitteille. Windowssille löytyy erillinen paketti täältä.

 sudo apt install openvpn

Konfigurointi

Sertifikaatit

Asennuksen jälkeen sinun tulee kopioida oletushakemistosta tiedostoja jotta palvelin voi lukea niitä

 cp -r /usr/share/doc/openvpn/examples/easy-rsa /etc/openvpn

Jessie tai uudemmissa:

cp -r /usr/share/easy-rsa /etc/openvpn/easy-rsa

Tämän jälkeen siirrytään generoimaan RSA avaimet VPN palvelua varten.

 cd /etc/openvpn/easy-rsa/2.0/

Muokkaa tämän jälkeen vars tiedostoa

 nano /etc/openvpn/easy-rsa/2.0/vars

vars - tiedostossa muuta export KEY_SIZE 1024 -> 2048

# Increase this to 2048 if you
# are paranoid.  This will slow
# down TLS negotiation performance
# as well as the one-time DH parms
# generation process.
export KEY_SIZE=2048

Voit halutessasi kirjoittaa valmiiksi konfiguroinnit tähän tiedostoon.

Tallenna ja sulje tiedosto sekä käynnistä openvpn palvelu uudelleen

 service openvpn restart

Määritetään konfigurointitiedosto ./vars ja tyhjennetään vanhat avaimet

 source ./vars
 ./clean-all

Root sertifikaatti

Luodaan root sertifikaatti

 ./build-ca

Tämän jälkeen vastaa ohjattuun velhoon:

Generating a 2048 bit RSA private key
..+++
..................................................+++
writing new private key to 'ca.key'
-----
You are about to be asked to enter information that will be incorporated
into your certificate request.
What you are about to enter is what is called a Distinguished Name or a DN.
There are quite a few fields but you can leave some blank
For some fields there will be a default value,
If you enter '.', the field will be left blank.
-----
Country Name (2 letter code) [US]:FI
State or Province Name (full name) [CA]:Lounais-Suomi
Locality Name (eg, city) [SanFrancisco]:Turku
Organization Name (eg, company) [Fort-Funston]:Taistowiki
Organizational Unit Name (eg, section) [changeme]:Labs
Common Name (eg, your name or your server's hostname) [changeme]:vpn.taisto.org
Name [changeme]:Taistowiki VPN
Email Address [[email protected]]:[email protected]

Palvelin sertifikaatti

Sertifikaatin genroimisen jälkeen luodaan privaattiavain palvelimelle. Muuta vpn.taisto.org vastaamaan palvelimesi nimeä.

 ./build-key-server vpn.taisto.org

Tämän jälkeen vastaa jälleen seuraa velhoa

Generating a 2048 bit RSA private key
.................................................+++
.............................................................+++
writing new private key to 'vpn.taisto.org.key'
-----
You are about to be asked to enter information that will be incorporated
into your certificate request.
What you are about to enter is what is called a Distinguished Name or a DN.
There are quite a few fields but you can leave some blank
For some fields there will be a default value,
If you enter '.', the field will be left blank.
-----
Country Name (2 letter code) [US]:FI
State or Province Name (full name) [CA]:Lounais-Suomi
Locality Name (eg, city) [SanFrancisco]:Turku
Organization Name (eg, company) [Fort-Funston]:Taistowiki
Organizational Unit Name (eg, section) [changeme]:Labs
Common Name (eg, your name or your server's hostname) [vpn.taisto.org]:
Name [changeme]:Taistowiki
Email Address [[email protected]]:[email protected]

Please enter the following 'extra' attributes
to be sent with your certificate request
A challenge password []:
An optional company name []:
Using configuration from /etc/openvpn/easy-rsa/2.0/openssl-1.0.0.cnf
Check that the request matches the signature
Signature ok
The Subject's Distinguished Name is as follows
countryName           :PRINTABLE:'FI'
stateOrProvinceName   :PRINTABLE:'Lounais-Suomi'
localityName          :PRINTABLE:'Turku'
organizationName      :PRINTABLE:'Taistowiki'
organizationalUnitName:PRINTABLE:'Labs'
commonName            :PRINTABLE:'vpn.taisto.org'
name                  :PRINTABLE:'Taistowiki'
emailAddress          :IA5STRING:'[email protected]'
Certificate is to be certified until Aug 15 12:00:08 2025 GMT (3650 days)
Sign the certificate? [y/n]:y


1 out of 1 certificate requests certified, commit? [y/n]y
Write out database with 1 new entries
Data Base Updated

Generoi Diffie Helman key exhange parametri. Tässä menee hetki.

 ./build-dh


Asiakas sertifikaatti

Nyt luodaan OpenVPN asiakkaille sertifikaatti. Jokaisella asiakkaalla tulee olla oma sertifikaatti. Muuta client vastaamaan asiakkaan isäntänimeä.

 ./build-key client
Generating a 2048 bit RSA private key
...................................................................................+++
............+++
writing new private key to 'client.key'
-----
You are about to be asked to enter information that will be incorporated
into your certificate request.
What you are about to enter is what is called a Distinguished Name or a DN.
There are quite a few fields but you can leave some blank
For some fields there will be a default value,
If you enter '.', the field will be left blank.
-----
Country Name (2 letter code) [US]:FI
State or Province Name (full name) [CA]:Lounais-Suomi
Locality Name (eg, city) [SanFrancisco]:Turku
Organization Name (eg, company) [Fort-Funston]:Taistowiki
Organizational Unit Name (eg, section) [changeme]:Labs client
Common Name (eg, your name or your server's hostname) [client]:
Name [changeme]:Taistowiki
Email Address [[email protected]]:[email protected]

Please enter the following 'extra' attributes
to be sent with your certificate request
A challenge password []:
An optional company name []:
Using configuration from /etc/openvpn/easy-rsa/2.0/openssl-1.0.0.cnf
Check that the request matches the signature
Signature ok
The Subject's Distinguished Name is as follows
countryName           :PRINTABLE:'FI'
stateOrProvinceName   :T61STRING:'\0xFFFFFFC3Lounais-Suomi'
localityName          :PRINTABLE:'Turku'
organizationName      :PRINTABLE:'Taistowiki'
organizationalUnitName:PRINTABLE:'Labs client'
commonName            :PRINTABLE:'client'
name                  :PRINTABLE:'Taistowiki'
emailAddress          :IA5STRING:'[email protected]'
Certificate is to be certified until Aug 15 12:05:36 2025 GMT (3650 days)
Sign the certificate? [y/n]:y


1 out of 1 certificate requests certified, commit? [y/n]y
Write out database with 1 new entries
Data Base Updated

Kopioi Root, palvelin sekä DH param sertifikaatti tiedostot OpenVPN root hakemistoon:

cp /etc/openvpn/easy-rsa/2.0/keys/ca.crt /etc/openvpn
cp /etc/openvpn/easy-rsa/2.0/keys/ca.key /etc/openvpn
cp /etc/openvpn/easy-rsa/2.0/keys/dh2048.pem /etc/openvpn
cp /etc/openvpn/easy-rsa/2.0/keys/server.crt /etc/openvpn
cp /etc/openvpn/easy-rsa/2.0/keys/server.key /etc/openvpn

Kumoa sertifikaatti

Seuraavilla komennoilla voit kumota käyttäoikeuden palvelimeen. Muuta client1 nimeä asiakasnimeksi minkä oikeuden haluat peruuttaa.

 . /etc/openvpn/easy-rsa/2.0/vars
 . /etc/openvpn/easy-rsa/2.0/revoke-full client1

Palvelimen konfigurointi

Pura ZIP tiedosto

 gunzip -d /usr/share/doc/openvpn/examples/sample-config-files/server.conf.gz

Kopioi esimerkki palvelin konfigurointi tiedosto /etc/openvpn hakemistoon

 cp /usr/share/doc/openvpn/examples/sample-config-files/server.conf /etc/openvpn

Sinun tulee vielä muokata server.conf tiedostossa muutama kohta ennen kuin voidaan ottaa OpenVPN palvelin käyttöön:

 nano /etc/openvpn/server.conf
  • Oikeat avain tiedostot ja niiden polku
# SSL/TLS root certificate (ca), certificate
# (cert), and private key (key).  Each client
# and the server must have their own cert and
# key file.  The server and all clients will
# use the same ca file.
#
# See the "easy-rsa" directory for a series
# of scripts for generating RSA certificates
# and private keys.  Remember to use
# a unique Common Name for the server
# and each of the client certificates.
#
# Any X509 key management system can be used.
# OpenVPN can also use a PKCS #12 formatted key file
# (see "pkcs12" directive in man page).
ca ca.crt
cert server.crt
key server.key  # This file should be kept secret

# Diffie hellman parameters.
# Generate your own with:
#   openssl dhparam -out dh1024.pem 1024
# Substitute 2048 for 1024 if you are using
# 2048 bit keys.
dh dh2028.pem

Lopuksi käynnistä VPN palvelu uudelleen

 service openvpn restart

Esimerkki palvelin konfiguraatio

proto tcp
port 1194
dev tun
server 10.0.8.0 255.255.255.0
topology subnet
#ifconfig-pool-persist ipp.txt
push "route 10.84.0.0 255.255.255.0"
push "redirect-gateway def1"
push "dhcp-option DNS 8.8.8.8"
push "dhcp-option DNS 8.8.4.4"
;client-to-client
;duplicate-cn
keepalive 10 120
cipher BF-CBC        # Blowfish (default)
;cipher AES-128-CBC   # AES
;cipher DES-EDE3-CBC  # Triple-DES
max-clients 100
;user nobody
;group nobody
persist-key
persist-tun
status /var/log/openvpn-status.log
log /var/log/openvpn.log
log-append /var/log/openvpn.log
verb 3


Reititykset palvelimella

Salli IPv4 forward:

 echo 1 > /proc/sys/net/ipv4/ip_forward

Lisää NAT sääntö iptables

 iptables -t nat -A POSTROUTING -s 10.8.0.0/24 -o eth0 -j MASQUERADE

Voit myös sillata bridge-utilsin avulla yhteyden.

IPv6

Ota käyttöön OpenVPN IPv6 UDP tunneli

 proto udp6

Tai TCP

 proto tcp6

Lisää palvelimen konfiguraatioon.

tun-ipv6
push tun-ipv6

Lisää IPv6 osoite (oma /64 esimerkiksi). Ensimmäinen osoite käyttää palvelin ja muut jaetaan.

 server-ipv6 2001::2003::/64

Lisää reititys

 push "route-ipv6 2000::/3"


Asiakkaan konfigurointi

Asenna OpenVPN asiakaskoneelle

 aptitude install openvpn

Kopioi OpenVPN palvelimelta client.conf tiedosto omaan kotihakemistoon ja siirrä omalle asiakaslaitteelle

 cp /usr/share/doc/openvpn/examples/sample-config-files/client.conf ~/

Kopioi lisäksi ca (ca.crt) ja client sertifikaatit (client.crt) sekä privaattiavain (client.key) asiakaslaitteelle.

Avaa client.conf tiedosto

nano ~/client.conf

Muokkaa tämä tiedosto seuraavanlaiseksi:

  • Määritä OpenVPN palvelimen osoite sekä portti, oletus 1194
# The hostname/IP and port of the server.
# You can have multiple remote entries
# to load balance between the servers.
remote my-server-1 1194
;remote my-server-2 1194
  • Määritä sertifikaattien polku
# SSL/TLS parms.
# See the server config file for more
# description.  It's best to use
# a separate .crt/.key file pair
# for each client.  A single ca
# file can be used for all clients.
ca ca.crt
cert client.crt
key client.key

Käynnistä OpenVPN

 openvpn --config client.ovpn

Käynnistä OpenVPN profiilit palvelun käynnistyttyä

Avaa seuraava tiedosto

 nano /etc/default/openvpn

Poista risuaita riviltä

 AUTOSTART="all"

Tallenna tiedosto

Muuta *.ovpn tiedostot *.conf tiedostoiksi. Vain .conf tiedostot ladataan uudeelleen käynnistäessä OpenVPN prosessia

GUI

 aptitude install openvpn network-manager-openvpn
 service network-manager-restart

Radius todennus

Asenna seuraavat paketit

 apt-get install libgcrypt11 libgcrypt11-dev gcc make build-essential g++

Lataa Radius plugin

 wget http://www.nongnu.org/radiusplugin/radiusplugin_v2.1a_beta1.tar.gz

Pura tar tiedosto

 tar xvfz radiusplugin_v2.1a_beta1.tar.gz

Siirry hakemistoon

 cd radiusplugin_v2.1a_beta1/

Käännä se

 make

Kopioi OpenVPN kansioon seuraavat tiedostot

 cp radiusplugin.so /etc/openvpn/
 cp radiusplugin.cnf /etc/openvpn/

Konfiguroi Radiuspalvelimen asetukset

server
{
        # The UDP port for radius accounting.
        acctport=1813
        # The UDP port for radius authentication.
        authport=1812
        # The name or ip address of the radius server.
        name=YOUR RADIUS SERVER IP
        # How many times should the plugin send the if there is no response?
        retry=1
        # How long should the plugin wait for a response?
        wait=1
        # The shared secret.
        sharedsecret=YOUR RADIUS SERVER SECRET
}

Lisää tämä server.conf tiedostoon

 plugin /etc/openvpn/radiusplugin.so /etc/openvpn/radiusplugin.cnf

Käynnistä OpenVPN uudelleen

 service openvpn restart


Testaus

1. Käynnistä palvelin jos ei ole jo käynnistetty

2. Käynnistä asiakas jos ei ole jo käynnistetty

3. aja ifconfig komento OpenVPN asiakkaalla. Sielä tulisi näkyä tun0 tai vastaava interface. Lisäksi näkyy osoite sielä.

tun0      Link encap:UNSPEC  HWaddr 00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00  
          inet addr:10.8.0.6  P-t-P:10.8.0.5  Mask:255.255.255.255
          UP POINTOPOINT RUNNING NOARP MULTICAST  MTU:1500  Metric:1
          RX packets:0 errors:0 dropped:0 overruns:0 frame:0
          TX packets:14 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:100 
          RX bytes:0 (0.0 B)  TX bytes:896 (896.0 B)

4. Pingaa palvelimeen oikeaan IP-osoiteeseen.

5. pingaa palvelinkoneelta asiakaskoneelle.

6 Tarkita toimiiko DNS nslookup komennolla.

Lähteet

https://wiki.debian.org/openvpn%20for%20server%20and%20client

https://www.digitalocean.com/community/tutorials/how-to-setup-and-configure-an-openvpn-server-on-debian-6

Mainos / Advertisement: