OpenSSH ile VPN Kurulumu

Acik kod dunyasinda vpn kullanimi icin oldukca cok secenek var[1]. Fakat en hizli, en kolay VPN kurulumu kanimca OpenSSH ile yapiliyor. OpenSSH 3.4 surumu ile birlikte gelen tunnelin destegi[2] ile tam bir VPN kurulumu gerceklestirilebiliyoruz.

Ornek;

Site1(1.2.3.0/24)–GW1–internet–GW2–Site2(5.6.7.1/24)
yukaridaki sistemde site1 ile site2 arasinda VPN yapmak istiyoruz.. Bunun icin gerekli ssh ve ip yapilandirmasi..

Site1;
#ssh -w0:0 5.6.7.1

bu adimdan sonra her iki tarafta tun0arabirimleri acilacak ve up hale gelecektir. Bundan sonraki islem bu arabirimlere uygun IP adresleri atamaktir..

Site1 icin IP tanimlamasi;

#ifconfig tun0 100.100.100.1 netmask 255.255.255.252

Site2 icin IP tanimlamasi;

#ifconfig tun0 100.100.100.2 netmask 255.255.255.252

ayarlari kalici hale getirmek icin kullanlian Linux/UNIX dagitima gore gerekli islemler yapilmali.. Bu ayarlari tamamladiktan
sonra tunelin iki ucu birbirini gorur vaziyettedir. Bunu bir uctan digerine ping atarak sınayabiliriz. (sistemdeki Firewall vs nin tun0 icin engelleme yapmadigini varsayiyoruz..)

Bundan sonra yapilacak ayarlar VPN’i ne amacla kullanacaginiza bagli olarak degisir. yine yukaridaki cizime gore devam edecek olursak. Site1’in site2’ye ulasmasi icin;

Site1 gatewayinde

#route add -net 5.6.7.0/24 dev tun0

komutunu vermeliyiz. Boylece ssh kurulu gateway’e gelen paketler dogru araibirimden yonlendirilerek karsi sisteme ulasacaktir. Ayni sekilde site2’ye ulasan paketlerin geri donebilmesi icin Site2 gatewayinde

#route add -net 1.2.3.0/24 dev tun0

komutu verilmeli ve son olarak IP forwarding aktif edilmeli.
sysctl net.inet.ip.forwarding=1 (*BSD sistemler icin), linux icin
echo 1 > /proc/sys/net/ipv4/ip_forward komutu da ise yarar.

ya da ihtiyaca gore NAT yapilabilir…

Not:noktadan noktaya VPN kurulumu icin sshd-config dosyasinda PermitTunnel secenegi yes olmali.[3]

[1] Acik kod VPN Cozumleri – http://www.enderunix.org/slides/Internet%20Konferanslari/acikkodvpn.pdf
[2] -w tunnel:tunnel
Requests a tun(4) device on the client (first tunnel arg) and
server (second tunnel arg). The devices may be specified by nu-
merical ID or the keyword “any”, which uses the next available
tunnel device. See also the Tunnel directive in ssh_config(5).

[3] man sshd_config
PermitTunnel
Specifies whether tun(4) device forwarding is allowed. The argu-
ment must be “yes”, “point-to-point”, “ethernet”, or
“no”. The default is “no”.

This entry was posted in VPN. Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *

19 + six =