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

30 Mart 2015 Pazartesi

Backup & Restore Linux sistemlerde

Selamlar;

Bu paylaşımda yaklaşık 3 haftadır görev aldığım bir projede kullanılmak üzere oluşturduğum yedekleme ve yedekten dönme (Backup & Restore) mekanizması hakkında bilgi vermek istiyorum.Anlatacağım (Backup & Restore) mekanizmasını oluşturmak ve konfigure etmek oldukça kolay,ayrıca yedeklenen içeriğe web erişimi olduğu için alınan yedeklerin içerik ve doğruluğunu o anda kontrol edilebilmesi de bu mekanizmanın artılarından bir tanesi.Lafı fazla uzatmadan kısaca topolojiyi çizerek anlatıma başlıyorum.


Yukarıdaki şemada görüldüğü gibi iki adet sunucumuz bulunmakta.Sunucularımız dan ilki Centos yüklü apache web sunucusu diğeri ise Debian kurulu olan openvpn,dhcp ve file server servislerin çalıştığı Debian sunucu,iki sunucu arasında "ssh public key authentication" kullanılmakta,yani birbirlerine bağlanırken parola sormuyorlar,"ssh user@hostnane " komutu sonrası password:? sorulmuyor.Güvenli bağlantı için bir anahtar dosya kullanıyor,sunucular birbirlerini bu anahtar vasıtasıyla tanıyor ve haberleşiyor."Ssh public key" nasıl oluşturulur konusuna geçiyorum.

A-) Ssh public key oluşturma

Aşağıdaki komutları sırasıyla terminal konsolda çalıştıralım.Burada dikkat etmemiz gereken nokta ssh-keygen komutu ile oluşan "~/.ssh/id_rsa.pub" dosyasının içeriğini  "authorized_keys" isimli yeni bir dosyaya kaydetmek gerekmekte."Authorized_keys" dosyası "ssh public key authentication" kilit dosyasıdır.Bu örnekte authorized_keys dosyasını "A" sunucusu yani Centos için oluşturuyorum.
  • ssh-keygen -t rsa
Komut sonrası "~/.ssh/" dizinde iki adet  id_rsa ve id_rsa.pub isminde dosya oluşmakta.Yukarıda da bahsettiğim gibi id_rsa.pub dosyasının içeriğini yeni oluşturmamız gereken "authorized_keys" dosyasına taşımalıyız.Bu işlem için aşağıdaki komutu kullanıyorum. 
  • cat id_rsa.pub > authorized_keys

Bu aşamadan sonra geriye bağlanılacak sunucunun "~/.ssh/"pathine az önce oluşturduğum "authorized_keys" dosyasının kopyalanması kaldı.Bu işlem için aşağıdaki komutu kullanmalıyız.
  • scp authorized_keys user@B-sunucusu:~/.ssh/.
Kopyalama işlemi sonrası "A" sunucusundan yani Centos'tan "B" sunucusuna Debian'a ssh ile bağlantı yaptığımızda parola girmemiz gerekmeyecek.Fakat "B" sunucusundan Debian'dan "A" sunucusuna Centos'a ssh yaptığımızda parola sorulmaya devam edecektir.Bunu önlemek için "B"sunucusunda da ssh-keygen komutu yapılmalıdır.Burada farklı yapılması gereken tek komut "cat id_rsa.pub >> authorized_keys" dir.Sırasıyla aşağıda komut dizilimini veriyorum.

"Ssh public key authentication" için "B" Sunucusunda yapılması gereken işlem


  • "ssh-keygen -t rsa" komutu bu sunucuda da çalıştırılmalıdır.
Komut sonrası "~/.ssh/" dizinde iki adet  id_rsa ve id_rsa.pub isminde dosya oluşmakta.

  • cat id_rsa.pub >> authorized_keys
  • scp authorized_keys user@A-sunucusu:~/.ssh/. 
Bu işlemler sonrası her iki sunucu arasında ssh public key authentication metodu ile bağlantı sağlanmış oldu.Yedekleme için gerekli olan ilk adımı tamamlamış bulunmaktayız.İkinci adım olarak "A" sunucusuna yani Centos'a apache web sunucusu kurmaya sıra geldi.Bu kurulum için aşağıdaki komutları sırasıyla terminal konsolda çalıştıralım.

B-) Centos üzerine Apache server kurulumu
  • yum install httpd   "komutu ile apache kurulumu yapıyoruz"
  • chkconfig --levels 235 httpd on   "Apache servis otomatik başlıyor"
  • "/etc/httpd/conf/httpd.conf" dosyasında "NameVirtualHost *:80" başındaki "#"commenti kaldırıyoruz.
  • /etc/init.d/httpd restart  yada service httpd restart  "servisi yeniden başlatıyoruz,gelen uyarıyı"NameVirtualHost *:80 has no VirtualHosts" warning for now"dikkate almayın "
  • http://localhost adresinden apache web sunucusuna ulaşabilirsiniz.

C-) Apache server konfigürasyonu (Kullanıcı ve parola ekranı oluşturma)

  • Apache server'da ilk olarak  "/etc/httpd/conf/httpd.conf" dosyasında 350. satırda bulunan "AllowOverride All" ifadesini "AllowOverride None" olarak değiştirmeliyiz.Bu değişiklik ile oluşturduğumuz".htaccess" dosyalarını apache'nin okumasını sağlamış olduk.

"httpd.conf" dosyasıyla işimiz bittiğine göre ilk olarak ".htpasswd" ve arkasından ".htaccess" dosyalarını oluşturmaya sıra geldi.Bu dosyaları oluşturmak için iki yöntem bulunmakta.İlk yöntem web sunucu (A) Centos makinede aşağıdaki komutları sırasıyla çalıştırmak yada http://www.htaccesstools.com/ adresini kullanarak oluşturabiliriz. Web sayfasından dosyaları oluşturmak oldukça pratik ve kolay,sarı ile belirtiğim linkleri kullanarak htpasswd ve htaccess dosyası oluşturabilirsiniz.




NOT:Anlatımda komut satırı kullanılmıştır."/etc" atında "htpasswd" dizini bulunmuyorsa,mkdir /etc/htpasswd komutu ile dizini yarattıktan sonra aşağıdaki komutla apache parola dosyasını oluşturuyoruz.



  • htpasswd -c /etc/htpasswd/.htpasswd kullanıcı-adı
".htpasswd" dosyasının nerede oluştuğu önemli,çünkü ".htaccess" dosyasının içeriğinde ".htpasswd" dosyasının nerede olduğunu tanımlamamız gerekecek,bu açıdan dosyanın path bilgisi önem teşkil etmekte.Bu küçük ama önemli bir ayrıntı.Eğer web sayfası ile dosyaları oluşturmuşsak bu küçük ayrıntıya daha çok dikkat etmeliyiz.Örnek bir ".htpasswd" dosyasının içeriği aşağıdaki gibi görünmeli.



Dikkat ettiyseniz benim ".htpasswd" dosyamın bulunduğu dizin "/var/www/html/yedek" ".htaccess" dosyamdaki tanım ise bu pathe uygun olmalı.".htaccess" dosyası oluşturmak için "/var/www/html/yedek" pathinde aşağıdaki komutları sırasıyla çalıştırıyoruz.


  • mkdir /var/www/html/yedek "yedek dizin yoksa oluşturuyoruz"
  • cd /var/www/html/yedek "yedej dizine giriyoruz"
  • nano .htaccess "nano editörle aşağıdaki örnek içeriği kopyalayabilirsiniz"
  • chmod 644 .htaccess
Örnek ".htaccess" içeriği ;

AuthType Basic AuthName "Sunucu Yedek Erisim Alani" AuthGroupFile /dev/null AuthUserFile /var/www/html/yedek/.htpasswd Require valid-user

  

"htpasswd" dosyasını oluşturduğunuz path eğer anlatımın başında geçen "/etc/htpasswd/" dizini ise ;".htaccess" içeriğinde "AuthUserFile /etc/htpasswd/.htpasswd" dosyasının bulunduğu dizini değiştirmemiz gerecek.Bunun dışında ".htaccess" dosyası parola sorması gereken ekranda olmalı,bizim ekranımız" /var/www/html/yedek" olduğu için ".htaccess" dosyasını bu pathte oluşturduk.Son adım olarak apache servisi restart ederek "http://(A) Centos/yedek" adresinden konfigürasyonu kontrol etmek kaldı.
  • /etc/init.d/httpd restart
  • http://A-sunucusu-Centos/yedek



Yedekler için oluşturduğumuz alan bizden kullanıcı-adı ve parola sormakta,artık yedeklenen içeriğe güvenli bir şekilde ulaşacağız.Bizim dışımızda local ağdan bir başkası yedek içeriği görüntüleyemeyecek,tabi kullanıcı adı ve parolayı bilmiyorsa.Bu yüzden karmaşık bir parola oluşturmanızı öneririm.

D-) Backup&Restore script oluşturma


Bu aşamada size kendi hazırladığım yedeklerken bir yandan da restorunu oluşturan shell script'i paylaşacağım.


NOT:Shell scripti (B)-Debian sunucuda çalıştırmalıyız,scripte kullanılan path bilgilerini değiştirebilirsiniz.Scriptte değişiklik yapmadan kullanmak isterseniz (B)-Debian sunucuda " mkdir {/content,/content/yedek} yada mkdir /content && mkdir /content/yedek" komutu ile scriptte tanımlı olan dizinleri oluşturmalıyız.



#!/bin/bash
a=`date +%d%m%Y`
b=`date +"%H%M%S"`
c=`hostname`
d=`hostname -I | awk '{print $1}' |uniq`
cd /content/yedek
echo "$a$b$d$c" > /tmp/isim.txt
mkdir `cat /tmp/isim.txt`
#Yedeklenecek konfigurasyon dosyalari
cp /etc/dhcp/dhcpd.conf /content/yedek/`cat /tmp/isim.txt`
cp -r /etc/openvpn /content/yedek/`cat /tmp/isim.txt`
#Restore olusturma
cd /content/yedek/`cat /tmp/isim.txt`
cp /tmp/isim.txt .id
echo $c > .hn
cat << EOF > restore.sh
#!/bin/bash
cd /content/yedek/`cat .id`
tar -zxf `cat .id`.tar.gz
#Yedekten Onar
#DHCP
/etc/init.d/isc-dhcp-server stop
echo "DHCP servis onarildi"
cat dhcpd.conf > /etc/dhcp/dhcpd.conf
/etc/init.d/isc-dhcp-server start
#OPENVPN
/etc/init.d/openvpn stop
echo "OPENVPN servis onarildi"
cp -r openvpn /etc/.
/etc/init.d/openvpn start 
EOF
chmod ugo+x restore.sh
#Sikistirma
cd /content/yedek/`cat /tmp/isim.txt`
tar -zcvf `cat /tmp/isim.txt`.tar.gz * > /content/yedek/`cat /tmp/isim.txt`/Yedek_icerigi.log
rm -rf d* op*
#Merkezi Sunucuya gonderme
scp -r -o UserKnownHostsFile=/dev/null -o StrictHostKeychecking=no  /content/yedek/`cat /tmp/isim.txt` kullanıcı-adı@A-server-Centos:/var/www/html/yedek/.

Yukardaki shell script'te "tarih+saat+ip-adres-hostname" değişkenleri ile bir dizin oluşmakta,sonrasında yedeklenecek servislerin conf dosyası yada servisin ilgili path'nin bir yedeği "/content/yedek" içine yukarıda bahsettiğim tarih+saat+ip-adres-hostname" değişkeni ile oluşan dizine kaydedilmekte,sonrasında sıkıştırılıp scp ile (A) Centos web sunucusunun "/var/www/html/yedek" parola korulamalı alana kopyalanmakta.Bu shell script (B) Debian sunucuda çalıştırılmalı.Bu işlemi gerçekleştirmek için ilk olarak script dosyasını yedek1.sh ismiyle (B) Debian sunucunun /content pathine kaydedelim.chmod ugo+x /content/yedek1.sh komutu ile yürütülebilir dosya yapalım ve en son adım olarak aşağıdaki komut ile doğrudan yada ssh ile komut çalıştırma yöntemi ile bu backup&restore çalışması yapan yedek1.sh dosyasını çalıştıralım.İlk olarak doğrudan çalıştırma için standart ssh bağlantısı yapmamız yeterli;
  • ssh kullanıcı-adı@B-sunucusu-DEBİAN
  • cd /content
  • ./yedek1.sh
İkinici çalıştırma yöntemi olarak ssh ile komut çalıştırma yöntemini kullanabiliriz,bunun için aşağıdaki komutu kullanmamız yeterli olcaktır.
  • ssh kullanıcı-adı@B-server-DEBİAN "/content/./yedek1.sh"
Yedeğimizi aldığımıza göre "http://A-sunucusu-Centos/yedek" adresinden alınan yedeği kontrol etmeye sıra geldi.


Kullanıcı adı ve parolayı yazıp "Tamam" butonu ile yedek sayfasına oturum açıyorum.



30 mart 2015 tarihli olan dizine tıklayarak aldığımız yedeğin içeriğine ulaşıyoruz.


Fark ettiyseniz restore.sh ve Yedek_içeriği.log ile xxx.tar.gz dosyaları oluşmuş.restore.sh ile DEBİAN sunucuyu bu yedeğe döndürebiliriz.

restore.sh içeriği;

#!/bin/bash
cd /content/yedek/30032015173924192.168.0.9testbox09
tar -zxf 30032015173924192.168.0.9testbox09.tar.gz
#Yedekten Onar
#DHCP
/etc/init.d/isc-dhcp-server stop
echo "DHCP servis onarildi"
cat dhcpd.conf > /etc/dhcp/dhcpd.conf
/etc/init.d/isc-dhcp-server start
#OPENVPN
/etc/init.d/openvpn stop
echo "OPENVPN servis onarildi"
cp -r openvpn /etc/.
/etc/init.d/openvpn start 


Yedek_içeriği.log

dhcpd.conf
openvpn/
openvpn/easy-rsa/
openvpn/easy-rsa/build-ca
openvpn/easy-rsa/build-key-server
openvpn/easy-rsa/openssl-0.9.8.cnf
openvpn/easy-rsa/whichopensslcnf
openvpn/easy-rsa/build-req-pass
openvpn/easy-rsa/inherit-inter
openvpn/easy-rsa/revoke-full
openvpn/easy-rsa/build-req
openvpn/easy-rsa/pkitool
openvpn/easy-rsa/build-key-pass
openvpn/easy-rsa/istemcisertifika.tar
openvpn/easy-rsa/build-key
openvpn/easy-rsa/openssl-1.0.0.cnf
openvpn/easy-rsa/keys/
openvpn/easy-rsa/keys/client.csr
openvpn/easy-rsa/keys/server.csr
openvpn/easy-rsa/keys/a.txt
openvpn/easy-rsa/keys/client1.crt_yedek
openvpn/easy-rsa/keys/key.tar
openvpn/easy-rsa/keys/01.pem
openvpn/easy-rsa/keys/index.txt.old
openvpn/easy-rsa/keys/index.txt
openvpn/easy-rsa/keys/serial
openvpn/easy-rsa/keys/ca.key
openvpn/easy-rsa/keys/client1.key_yedek
openvpn/easy-rsa/keys/ca.crt
openvpn/easy-rsa/keys/index.txt.attr.old
openvpn/easy-rsa/keys/index.txt.attr
openvpn/easy-rsa/keys/server.crt
openvpn/easy-rsa/keys/serial.old
openvpn/easy-rsa/keys/dh2048.pem
openvpn/easy-rsa/keys/02.pem
openvpn/easy-rsa/keys/server.key
openvpn/easy-rsa/openssl-0.9.6.cnf
openvpn/easy-rsa/list-crl
openvpn/easy-rsa/build-dh
openvpn/easy-rsa/vars
openvpn/easy-rsa/clean-all
openvpn/easy-rsa/build-inter
openvpn/easy-rsa/build-key-pkcs12
openvpn/easy-rsa/sign-req
openvpn/update-resolv-conf
openvpn/ipp.txt
openvpn/ca.crt
openvpn/openvpn-status.log
openvpn/server.conf
openvpn/server.crt
openvpn/dh2048.pem
openvpn/server.key
restore.sh
Bu yedekleme yapısında yedeklenen içeriğin bir eşi (A)-Centos sunucunun "/var/www/html/yedek" dizininde aynı yedeğe ait diğer kopya ise (B)-Debian sunucusun "/content/yedek" dizininde saklanmakta.Alınan yedeğin birden fazla farklı ortamda bulunması bir felaket anında işimizi oldukça kolaylaştıracak bir ayrıntı.Kendinden restorlu backup şeysinin sonuna geldik :)



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



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