Mainos / Advertisement:

Openvpn

Kohteesta Taisto
Versio hetkellä 18. elokuuta 2015 kello 12.06 – tehnyt Minh (keskustelu | muokkaukset) (→‎Sertifikaatit)
Siirry navigaatioon Siirry hakuun
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

 aptitude 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

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

Tämän jälkeen generoidaan RSA tiedostot

 source ./vars
 ./clean-all
 ./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]

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

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

Vanha ohje

Esimerkkimme

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

  • 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

Asennetaan openvpn pakettihallinnasta.

 aptitude install openvpn 

Sertifikaattien asennus

Kopioi certificate luontiin tarvittavat tiedostot openvpn kansioon

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


Luo avaimet seuraavasti /etc/openvpn/easy-rsa/2.0 hakemistossa (jos et tiedä mitä vastata kysymyksiin avaimia luotaessa, katso OpenVPN HOWTO):

cd /etc/openvpn/easy-rsa/2.0 

Voit muokata seuraavassa tiedostossa certificaten määrityksiä

nano vars 
   . ./vars
   ./clean-all
   ./build-ca
   ./build-key-server server
   ./build-key client
   ./build-dh

Lisää clientejä luodaan komennolla

./build-key client2
./build-key jonne

Sijoita luomasi avaimet haluamaasi paikkaan. Omani ovat /etc/openvpn/dataa-hakemistossa.

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

Alla konfiguraatiotiedosto palvelimelle jos sen haluaa tästä ottaa.

LAN to LAN

nano /etc/openvpn/server.conf

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


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):

         iptables -A INPUT -i tun+ -j ACCEPT
         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:

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
service openvpn restart

nyt voi pingata esim. kotiservulta 10.10.7.10(koulun clientti).


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

Client side:

auth-user-pass

Server side:

plugin /usr/share/openvpn/plugin/lib/openvpn-auth-pam.so system-auth

http proxy

Http proxyn asettaminen openvpn

http-proxy 192.168.4.1 1080

Debian 6:sen openvpn:ssä on bugi jonka seurauksena openvpn kaatuu. Ongelman voi korjata laittamalla kyseisen option

 http-proxy-retry

Linkki bugiin:

http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=514718

Mainos / Advertisement: