Toplam Sayfa Görüntüleme Sayısı

6 Mart 2015 Cuma

OpenVPN kurulumu (Debian yada Ubuntu dağıtımlara)

Selamlar;


Bu paylaşımda Openvpn kurulumundan bahsedeceğim.Openvpn hakkında kısa bir bilgi vererek anlatıma başlıyorum. Openvpn açık kaynak kodlu " virtual private network" özel sanal ağ anlamına gelen  (VPN) yazılımıdır.Noktadan noktaya yada köprü modu ile  çalışabilmektedir.Sunucu ve istemci tarafı bulunmaktadır.Kurulum anlatımında sunucu ve istemci taraflarına ayrıntılı olarak değineceğim.

NOT:Kurulumda apt-get yöntemi kullanılmıştır.Openvpn'nin lisanlı sürüm kurulumu yapılmamıştır.Kısaca web browser üzerinden yönetilen "https://IPAdresiniz:943/admin" ve tar.gz uzantılı kurulum anlatımı değildir.Kurulum ortamı Debian 7.3 Wheezy'dir.

Openvpn kurulum adımları;
  • sudo apt-get update
  • sudo apt-get install openvpn easy-rsa
Openvpn ve easy-rsa paket kurulumları tamamlandığına göre ikinci adıma geçiyorum.
  • sudo su
  • mkdir /etc/openvpn/easy-rsa/
  • cp -r /usr/share/easy-rsa/* /etc/openvpn/easy-rsa/

Root kullanıcı ile easy-rsa klasörü oluşturup,/usr/share/easy-rsa pathindeki içeriğin tamamını oluşturduğumuz /etc/openvpn/easy-rsa/ pathine kopyalıyoruz.Bu işlemide tamamladığımıza göre üçüncü adıma geçebiliriz.
  •  nano /etc/openvpn/easy-rsa/vars 
/etc/openvpn/easy-rsa/vars dosyasında bulunan aşağıda gösterdiğim alanları örnekteki gibi dolduruyoruz.

  • export KEY_COUNTRY="TR"
  • export KEY_PROVINCE="TURCA"
  • export KEY_CITY="ANKARA"
  • export KEY_ORG="Sucuk Sirketi"
  • export KEY_EMAIL=mehmetocal79@gmail.com
  • export KEY_CN=BenimVPN
  • export KEY_NAME=BenimVPN
  • export KEY_OU=BenimVPN
Alanları doldurduktan sonra aşağıdaki komutları terminal konsolda sırasıyla çalıştırarak sertifika belgesi oluşturacağız.
  • cd /etc/openvpn/easy-rsa/
  • source vars
  • ./clean-all
  • ./build-ca
NOT:"./build-ca" çalıştığında eğer aşağıdaki hata alınırsa;muhtemelen alınacaktır.

error on line 198 of /etc/openvpn/easy-rsa/openssl-1.0.0.cnf
140224783447712:error:0E065068:configuration file routines:STR_COPY:variable has no value:conf_def.c:618:line 198

Çözümü için ;
  •  nano /etc/openvpn/easy-rsa/vars 
Dosyasının en alt satırına ;
  • export KEY_ALTNAMES="something" tanımı eklenmelidir.

Hata düzeltmesinden sonra keys dizininde oluşan dosyalar silinmeli ve sertifika oluşturma işlemi tekrarlanmalıdır.Dördüncü adım;

  • ./build-dh komutunu çalıştırıyoruz.
SUNUCU (Server) SERTİFİKASI HAZIRLAMA
  • ./build-key-server server
"/etc/openvpn/easy-rsa/vars" dosyasına girdiğimiz "TR,TURCA,Sucuk Sirketi"gibi alanları "Enter"la geçiyoruz.“Sign the certificate? [y/n]” ve “1 out of certificate requests certified, commit? [y/n]” alanlarına ise "y" yazarak cevaplamamız gerekmekte. 


Server sertifikaları oluştuğuna göre,aşağıdaki komutlarla oluşan sertifikaları "/etc/openvpn/" patine taşımaya sıra geldi.Bu işlem için aşağıdaki komutları terminal konsolda çalıştırmalıyız.
  • cd keys/
  • cp server.crt server.key ca.crt dh2048.pem /etc/openvpn/
Crt,key,pem dosyalarını "/etc/openvpn/" pathine kopyaladıktan sonra istemci client sertifikası hazırlamamız gerekmekte.

İSTEMCİ (Client) SERTİFİKASI HAZIRLAMA
  • sudo su
  • cd /etc/openvpn/easy-rsa/
  • source vars
  • ./build-key client1
Yukardaki komutları terminal konsolda çalıştırdıktan sonra;aşağıda oluşan dosyaları istemci makineye taşımamız gerekmekte;İlk olarak dosyaları bir grup haline getirelim,bunun için tar komutu kullanılabilir "tar -cf istemcisertifika.tar  etc/openvpn/ca.crt  /etc/openvpn/easy-rsa/keys/client1.crt  /etc/openvpn/easy-rsa/keys/client1.key".istemcisertifika.tar dosyasını sftp yada scp ile istemci makineye gönderebiliriz.


  • etc/openvpn/ca.crt
  • /etc/openvpn/easy-rsa/keys/client1.crt
  • /etc/openvpn/easy-rsa/keys/client1.key
NOT:Taşıma işleminden sonra client1.crt ve client1.key dosyalarını sunucudan kaldırmamız gerekmekte.Silme işlemi yerine uzantısını değiştirmemizde yeterli olacaktır.Aşağıdaki komutlar dosyaların uzantılarını değiştirecektir.
  • mv /etc/openvpn/easy-rsa/keys/client1.crt  /etc/openvpn/easy-rsa/keys/client1.crt_yedek
  • mv /etc/openvpn/easy-rsa/keys/client1.key/etc/openvpn/easy-rsa/keys/client1.key_yedek
SUNUCU (Server) KONFİGÜRASYONU:

"/usr/share/doc/openvpn/examples/sample-config-files/" pathinde bulunan "server.conf.gz" dosyasını "/etc/openvpn/" pathine taşıyıp bu sıkıştırılmış dosyayı  "/etc/openvpn/" dizininde açmamız gerekmekte.Bu işlem için aşağıdaki komutları çalıştırmalıyız.
  • sudo cp /usr/share/doc/openvpn/examples/sample-config-files/server.conf.gz /etc/openvpn/
  • sudo gzip -d /etc/openvpn/server.conf.gz
Gzip dosyasını"server.conf.gz "/etc/openvpn/" dizininde açtığımızda "server.conf" dosyası oluştu."server.conf" dosyası Openvpn sunucumuzun konfigürasyon dosyası olduğu için dikkatli bir şekilde aşağıda listelediğim alanların örnekteki gibi doldurulması gerekmektedir.Bu konuda dikkatli olalım!!!!Yanlış bir işlem openvpn servisin hata almasına ve başlatılamamasına neden olacaktır.
  • sudo su
  • nano /etc/openvpn/server.conf 
ÖRNEK:"server.conf" dosyasında tanımlı olması gereken alanlar;
  • port 1194
  • proto udp
  • dev tun
  • ca /etc/openvpn/easy-rsa/keys/ca.crt
  • cert /etc/openvpn/easy-rsa/keys/server.crt
  • key /etc/openvpn/easy-rsa/keys/server.key  
  • dh /etc/openvpn/easy-rsa/keys/dh2048.pem
  • server 10.8.0.0 255.255.255.0
  • ifconfig-pool-persist ipp.txt
  • push "redirect-gateway def1"
  • push "dhcp-option DNS 84.200.69.80"
  • push "dhcp-option DNS 84.200.70.40"
  • keepalive 10 120
  • comp-lzo
  • user nobody
  • group nogroup
  • persist-key
  • persist-tun
  • status openvpn-status.log
  • verb 3

"server.conf" dosyasındaki alanları örnekteki gibi doldurduktan sonra openvpn servisi başlatmaya sıra geldi.Bu işlem için aşağıdaki komutu terminalde çalıştırmalıyız.
  • sudo service openvpn restart
OPENVPN SUNUCU FIREWALL (Ateş duvarı) ve ROUTİNG (Yönlendirme) KONFİGÜRASYONU

NOT:Openvpn sunucumuzda firewall çalışıyorsa;aşağıdaki komut ile firewall'da 1194 numaralı portu açmalıyız.
  • sudo ufw allow 1194
  • ufw status

Firewall'dan 1194 porta izin verdiğimize göre openvpn'nin "tun0" adaptörü ile fiziksel network adaptörü"eth0"'ın birbirleri ile haberleşmesini yani NAT'lamayı yapmamız  gerekmekte.Bu işlem için ilk olarak  "sysctl.conf" dosyasında "net.ipv4.ip_forward=1" tanımını kontrol etmeliyiz.
  • sudo nano /etc/sysctl.conf
  • "net.ipv4.ip_forward=1" olmalı
"sysctl.conf" dosyasında alanı kontrol ettikten sonra aşağıdaki komut ile "10.8.0.0/24 subnetinden" "tun0"dan gelen paketler fiziksel network cihazına "eth0"'a yönlenecektir.Yani "Postrouting" işlemi yapıyoruz.
  • sudo /sbin/iptables -t nat -A POSTROUTING -s 10.8.0.0/24 -o eth0 -j MASQUERADE
  • sudo /sbin/iptables -A FORWARD -i eth0 -o tun0 -m state --state RELATED,ESTABLISHED -j ACCEPT
  • sudo /sbin/iptables -A FORWARD -i tun0 -o eth0 -j ACCEPT
NOT:Openvpn servisi sunucu başladığında otomatik çalışması için aşağıdaki komutu kullanmalıyız.Run level 2345 on olarak yapılandırılır.
  • update-rc.d -f openvpn defaults
İSTEMCİ (Client) BAĞLANTI YAPILANDIRILMASI

İstemci makinede aşağıdaki komutlar çalıştırılarak openvpn client kurulumu yapılmalıdır.
  • sudo apt-get update
  • sudo apt-get install openvpn
Windows bir makineden bağlanılacak ise aşağıdaki web adresinden uygun olan istemci versiyonu indirilip kurulmalıdır.
Anlatıma linux istemci ile devam ediyorum,istemci makineye openvpn client kurulumu yapıldıktan sonra aşağıda belirttiğim dizinden "client.conf" dosyası "/etc/openvpn/" dizinine kopyalanır.Ayrıca sunucu üzerinde daha önce "tar"layıp oluşturduğumuz "istencisertifika.tar"dosyasında bulunan sertifikalarıda yine bu dizine "/etc/openvpn" çıkarmalıyız. Bu işlemleri yapabilmek için aşağıda verdiğim komutları terminalde çalıştırmalıyız.
  • cd /usr/share/doc/openvpn/examples/sample-config-files
  • sudo cp client.conf /etc/openvpn/.
"Client.conf"dosyasını "/etc/openvpn/" dizinine kopyaladıktan sonra client.conf dosyasında bulunan aşağıda belirtiğim alanların düzenlemesi gerekmekte,bu işlem için aşağıdaki örnek client.conf dosyasından faydalanabilirsiniz.
  • cd /etc/openvpn
  • sudo nano client.conf 

##############################################

# Sample client-side OpenVPN 2.0 config file #

# for connecting to multi-client server.     #

#                                            #

# This configuration can be used by multiple #

# clients, however each client should have   #

# its own cert and key files.                #

#                                            #

# On Windows, you might want to rename this  #

# file so it has a .ovpn extension           #

##############################################



# Specify that we are a client and that we

# will be pulling certain config file directives

# from the server.

client

# Use the same setting as you are using on
# the server.
# On most systems, the VPN will not function
# unless you partially or fully disable
# the firewall for the TUN/TAP interface.
;dev tap
dev tun

# Windows needs the TAP-Win32 adapter name
# from the Network Connections panel
# if you have more than one.  On XP SP2,
# you may need to disable the firewall
# for the TAP adapter.
;dev-node MyTap

# Are we connecting to a TCP or
# UDP server?  Use the same setting as
# on the server.
;proto tcp
proto udp

# The hostname/IP and port of the server.
# You can have multiple remote entries
# to load balance between the servers.
remote 192.168.0.9 1194
;remote my-server-2 1194

# Choose a random host from the remote
# list for load-balancing.  Otherwise
# try hosts in the order specified.
;remote-random

# Keep trying indefinitely to resolve the
# host name of the OpenVPN server.  Very useful
# on machines which are not permanently connected
# to the internet such as laptops.
resolv-retry infinite

# Most clients don't need to bind to
# a specific local port number.
nobind

# Downgrade privileges after initialization (non-Windows only)
;user nobody
;group nogroup

# Try to preserve some state across restarts.
persist-key
persist-tun

# If you are connecting through an
# HTTP proxy to reach the actual OpenVPN
# server, put the proxy server/IP and
# port number here.  See the man page
# if your proxy server requires
# authentication.
;http-proxy-retry # retry on connection failures
;http-proxy [proxy server] [proxy port #]

# Wireless networks often produce a lot
# of duplicate packets.  Set this flag
# to silence duplicate packet warnings.
;mute-replay-warnings

# 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 /etc/openvpn/ca.crt
cert /etc/openvpn/client1.crt
key /etc/openvpn/client1.key

# Verify server certificate by checking
# that the certicate has the nsCertType
# field set to "server".  This is an
# important precaution to protect against
# a potential attack discussed here:
#  http://openvpn.net/howto.html#mitm
#
# To use this feature, you will need to generate
# your server certificates with the nsCertType
# field set to "server".  The build-key-server
# script in the easy-rsa folder will do this.
ns-cert-type server

# If a tls-auth key is used on the server
# then every client must also have the key.
;tls-auth ta.key 1

# Select a cryptographic cipher.
# If the cipher option is used on the server
# then you must also specify it here.
;cipher x

# Enable compression on the VPN link.
# Don't enable this unless it is also
# enabled in the server config file.
comp-lzo yes

# Set log file verbosity.
verb 3

# Silence repeating messages
;mute 20

Client.conf dosyamızı oluşturduğumuza göre openvpn sunucumuza bağlanmaya sıra geldi.Aşağıdaki komutla vpn bağlantıyı gerçekleştiriyoruz.
  • sudo openvpn /etc/openvpn/client.conf


Windows openvpn istemci için örnek client.ovpn yapılandırması aşağıdaki örnekteki gibi olmalıdır.

##############################################
# Sample client-side OpenVPN 2.0 config file #
# for connecting to multi-client server.     #
#                                            #
# This configuration can be used by multiple #
# clients, however each client should have   #
# its own cert and key files.                #
#                                            #
# On Windows, you might want to rename this  #
# file so it has a .ovpn extension           #
##############################################

# Specify that we are a client and that we
# will be pulling certain config file directives
# from the server.
client

# Use the same setting as you are using on
# the server.
# On most systems, the VPN will not function
# unless you partially or fully disable
# the firewall for the TUN/TAP interface.
dev tap
;dev tun

# Windows needs the TAP-Win32 adapter name
# from the Network Connections panel
# if you have more than one.  On XP SP2,
# you may need to disable the firewall
# for the TAP adapter.
;dev-node MyTap

# Are we connecting to a TCP or
# UDP server?  Use the same setting as
# on the server.
;proto tcp
proto udp

# The hostname/IP and port of the server.
# You can have multiple remote entries
# to load balance between the servers.
remote 192.168.0.9
port 1194
;remote my-server-2 1194

# Choose a random host from the remote
# list for load-balancing.  Otherwise
# try hosts in the order specified.
;remote-random

# Keep trying indefinitely to resolve the
# host name of the OpenVPN server.  Very useful
# on machines which are not permanently connected
# to the internet such as laptops.
resolv-retry infinite

# Most clients don't need to bind to
# a specific local port number.
nobind

# Downgrade privileges after initialization (non-Windows only)
;user nobody
;group nogroup

# Try to preserve some state across restarts.
persist-key
persist-tun

# If you are connecting through an
# HTTP proxy to reach the actual OpenVPN
# server, put the proxy server/IP and
# port number here.  See the man page
# if your proxy server requires
# authentication.
;http-proxy-retry # retry on connection failures
;http-proxy [proxy server] [proxy port #]

# Wireless networks often produce a lot
# of duplicate packets.  Set this flag
# to silence duplicate packet warnings.
;mute-replay-warnings

# 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 C:\\VPN\\OpenVPN\\config\\ca.crt
cert C:\\VPN\\OpenVPN\\config\\client1.crt
key C:\\VPN\\OpenVPN\\config\\client1.key

# Verify server certificate by checking
# that the certicate has the nsCertType
# field set to "server".  This is an
# important precaution to protect against
# a potential attack discussed here:
#  http://openvpn.net/howto.html#mitm
#
# To use this feature, you will need to generate
# your server certificates with the nsCertType
# field set to "server".  The build-key-server
# script in the easy-rsa folder will do this.
ns-cert-type server

# If a tls-auth key is used on the server
# then every client must also have the key.
;tls-auth ta.key 1

# Select a cryptographic cipher.
# If the cipher option is used on the server
# then you must also specify it here.
;cipher x

# Enable compression on the VPN link.
# Don't enable this unless it is also
# enabled in the server config file.
comp-lzo yes

# Set log file verbosity.
verb 3

# Silence repeating messages
;mute 20

Windows openvpn client bağlantı görseli.

Bu paylaşımında sonuna geldik.Başka bir paylaşımda görüşmek üzere.
ford,fiat,opel,eset,norton,windows,hp,asus,samsung,lenova,ibm,apple.
Teşekkürler.
Mehmet ÖCAL 2015


Hiç yorum yok: