Mainos / Advertisement:

Ero sivun ”Openvpn” versioiden välillä

Kohteesta Taisto
Siirry navigaatioon Siirry hakuun
 
(64 välissä olevaa versiota 3 käyttäjän tekeminä ei näytetä)
Rivi 1: Rivi 1:
OpenVPN on avoimella lähdekoodilla toimiva VPN. Tämä on yksi maailman turvallisimmista VPN protokollista. OpenVPN eroaa muista VPN protokolista, että vaatii erillisen asiakasohjelman muodostaakseen yhteyden palvelimeen.
+
<languages/>
 +
<translate>
  
===== Esimerkkimme =====
+
<!--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.
  
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
+
== Asennus == <!--T:40-->
  
* Jh:n verkko kotona: 192.168.112.0/24
+
<!--T:41-->
* kotigw: 192.168.112.254 (mikrotikki :) )
+
Asenna OpenVPN paketti pakettihallinnasta palvelin ja asiakaslaitteille. Windowssille löytyy erillinen paketti [https://openvpn.net/index.php/open-source/downloads.html täältä].
* openvpnservu: 192.168.112.3
 
* openvpnclientti: 192.168.7.7
 
* jh:n säätöverkko koulussa: 192.168.7.0/24
 
* portti: 1723 (koska turun tietohallinnon muuri joka estää...)
 
* Virtuaaliverkko: 10.10.7.0/24
 
  
== Serverin konffaus ==
+
  <!--T:42-->
 +
sudo apt install openvpn
  
Asennetaan openvpn, openssl ja bridge-utils palvelimeen.
+
== Konfigurointi == <!--T:43-->
  
  apt-get install openvpn openssl bridge-utils
+
=== Sertifikaatit === <!--T:44-->
  
Kopioi:
+
<!--T:45-->
 +
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:
  
Luo avaimet seuraavasti /etc/openvpn/easy-rsa/2.0 hakemistossa (jos et tiedä mitä vastata kysymyksiin avaimia luotaessa, katso
+
cp -r /usr/share/easy-rsa /etc/openvpn/easy-rsa
OpenVPN HOWTO):
 
  
    . ./vars
+
<!--T:47-->
    ./clean-all
+
Tämän  jälkeen siirrytään generoimaan RSA avaimet VPN palvelua varten.  
    ./build-ca
 
    ./build-key-server server
 
    ./build-key client
 
    ./build-dh
 
  
Sijoita luomasi avaimet haluamaasi paikkaan. Omani ovat /etc/openvpn/dataa-hakemistossa
+
  <!--T:48-->
Alla konfiguraatiotiedosto palvelimelle
+
cd /etc/openvpn/easy-rsa/2.0/
  
5.
+
<!--T:49-->
 +
Muokkaa tämän jälkeen vars tiedostoa
  
dev tun
+
  <!--T:50-->
port 1723
+
nano /etc/openvpn/easy-rsa/2.0/vars
proto tcp
 
ca /etc/openvpn/dataa/ca.crt
 
cert /etc/openvpn/dataa/server.crt
 
key /etc/openvpn/dataa/server.key
 
dh /etc/openvpn/dataa/dh1024.pem
 
server 10.10.7.0 255.255.255.0
 
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
 
route 192.168.176.0 255.255.255.0
 
route 192.168.180.0 255.255.255.0
 
route 10.1.1.0 255.255.255.0
 
route 10.5.25.0 255.255.255.0
 
route 10.5.26.0 255.255.255.0
 
route 10.5.27.0 255.255.255.0
 
route 10.20.0.0 255.255.0.0
 
route 10.245.0.0 255.255.0.0
 
route 192.168.88.0 255.255.255.0
 
  
 +
<!--T:51-->
 +
vars - tiedostossa muuta export KEY_SIZE 1024 -> 2048
  
6. Luo ethernet-silta lisäämällä /etc/network/interfaces -tiedostoon seuraavat rivit, missä eth0:n tilalla on sisäverkkosi verkkoadapteri ja ip-osoite tiedot vastaavat sisäverkkosi asetuksia:
+
<!--T:52-->
 +
<pre>
 +
# 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
 +
</pre>
  
          auto br0
+
<!--T:53-->
          iface br0 inet static
+
Voit halutessasi kirjoittaa valmiiksi konfiguroinnit tähän tiedostoon.
          address 192.168.2.1
 
          netmask 255.255.255.0
 
          broadcast 192.168.2.255
 
          network 192.168.2.0
 
          pre-up openvpn –mktun –dev tap0
 
          bridge_ports eth0 tap0
 
7. Käynnistä verkko uudestaan /etc/init.d/network restart komennolla 8. Avaa UDP-portti 1194 palomuurissasi ja lisää myös tarvittavat säännöt tap0- ja br0-adaptereille esim. seuraavasti (tämä tapa voi erota käyttämästäsi tavasta, joten sovella tarvittaessa):
 
  
          iptables -A INPUT -i tap0 -j ACCEPT
+
<!--T:54-->
          iptables -A INPUT -i br0 -j ACCEPT
+
Tallenna ja sulje tiedosto sekä käynnistä openvpn palvelu uudelleen
          iptables -A FORWARD -i br0 -j ACCEPT
 
9. Tämän jälkeen tarvitset vielä OpenVPN:n (Windows GUI) ja konfiguraatiotiedoston clientille:
 
  
client
+
  <!--T:55-->
dev tun
+
service openvpn restart
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.112.0 255.255.255.0
 
route 192.168.0.0 255.255.0.0
 
route 192.168.176.0 255.255.255.0
 
route 192.168.180.0 255.255.255.0
 
route 10.1.1.0 255.255.255.0
 
keepalive 10 60
 
  
service openvpn restart
+
<!--T:56-->
 +
Määritetään konfigurointitiedosto ./vars ja tyhjennetään vanhat avaimet
  
nyt voi pingata esim. kotiservulta 10.10.7.10(koulun clientti).
+
  <!--T:57-->
 +
source ./vars
  
 +
  <!--T:58-->
 +
./clean-all
  
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 :)
+
==== Root sertifikaatti ==== <!--T:59-->
  
 +
<!--T:60-->
 +
Luodaan root sertifikaatti
  
http://ilar.in/2008/08/01/vpn-tunneli-openvpn-sillattuna-udp-yli-ubuntu-debian/
+
  <!--T:61-->
 +
./build-ca
  
pam auth
+
<!--T:62-->
 +
Tämän jälkeen vastaa ohjattuun velhoon:
  
Client side:
+
<!--T:63-->
 +
<pre>
 +
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
 +
 +
</pre>
  
Prompt for username/password at startup time
+
==== Palvelin sertifikaatti ==== <!--T:64-->
auth-user-pass
 
  
Server side:
+
<!--T:65-->
 +
Sertifikaatin genroimisen jälkeen luodaan privaattiavain palvelimelle. Muuta vpn.taisto.org vastaamaan palvelimesi nimeä.
  
This enables username/password checks.
+
  <!--T:66-->
plugin /usr/share/openvpn/plugin/lib/openvpn-auth-pam.so system-auth
+
./build-key-server vpn.taisto.org
  
 +
<!--T:67-->
 +
Tämän jälkeen vastaa jälleen seuraa velhoa
  
[muokkaa]Linkkejä
+
<!--T:68-->
http://wiki.xdroop.com/space/Linux/OpenVPN/PAM+Authentication
+
<pre>
http://www.wikihow.com/Enable-Windows-XP-Routing
+
Generating a 2048 bit RSA private key
http://ilar.in/2008/08/01/vpn-tunneli-openvpn-sillattuna-udp-yli-ubuntu-debian/
+
.................................................+++
 +
.............................................................+++
 +
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
 +
  
== Http proxy ==
+
<!--T:69-->
 +
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
  
Http proxyn asettaminen openvpn
 
  
http-proxy 192.168.4.1 1080
+
<!--T:70-->
 +
1 out of 1 certificate requests certified, commit? [y/n]y
 +
Write out database with 1 new entries
 +
Data Base Updated
 +
</pre>
  
Debian 6:sen openvpn:ssä on bugi jonka seurauksena openvpn kaatuu. Ongelman voi korjata laittamalla kyseisen option
+
<!--T:71-->
 +
Generoi Diffie Helman key exhange parametri. Tässä menee hetki.
  
   http-proxy-retry
+
   <!--T:72-->
 +
./build-dh
  
  
Linkki bugiin:
+
==== Asiakas sertifikaatti ==== <!--T:73-->
  
http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=514718
+
<!--T:74-->
 +
Nyt luodaan OpenVPN asiakkaille sertifikaatti. Jokaisella asiakkaalla tulee olla oma sertifikaatti. Muuta client vastaamaan asiakkaan isäntänimeä.
  
desdi
+
  <!--T:75-->
 +
./build-key client
 +
 
 +
<!--T:76-->
 +
<pre>
 +
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
 +
 +
 
 +
<!--T:77-->
 +
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
 +
 
 +
 
 +
<!--T:78-->
 +
1 out of 1 certificate requests certified, commit? [y/n]y
 +
Write out database with 1 new entries
 +
Data Base Updated
 +
</pre>
 +
 
 +
<!--T:79-->
 +
Kopioi Root, palvelin sekä DH param sertifikaatti tiedostot OpenVPN root hakemistoon:
 +
 
 +
<!--T:80-->
 +
<pre>
 +
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
 +
</pre>
 +
 
 +
==== 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 ===
 +
 
 +
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.
 +
 
 +
<pre>
 +
tun-ipv6
 +
push tun-ipv6
 +
</pre>
 +
 
 +
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 === <!--T:95-->
 +
 
 +
Asenna OpenVPN asiakaskoneelle
 +
 
 +
  aptitude install openvpn
 +
 
 +
<!--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/
 +
 
 +
Käännä se
 +
 
 +
  make
 +
 
 +
Kopioi OpenVPN kansioon seuraavat tiedostot
 +
 
 +
  cp radiusplugin.so /etc/openvpn/
 +
  cp radiusplugin.cnf /etc/openvpn/
 +
 
 +
Konfiguroi Radiuspalvelimen asetukset
 +
 
 +
<pre>
 +
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>
 +
 
 +
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ä.
 +
 
 +
<pre>
 +
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>
 +
 
 +
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
 +
</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: