Une méthode pour créer un VPN en utilisant PPP et SSH sous Linux. Testé sous Ubuntu 8.04 LTS, Ubuntu 8.10 et bien sûr Debian.
Sources:
http://www.faqs.org/docs/Linux-mini/ppp-ssh.html
http://www.revsys.com/writings/quicktips/nat.html
==> Setup a vpn user on the server
root@server:~# useradd -U vpn
edit /etc/passwd and change vpn default shell to /bin/bash
root@server:~# mkdir -p /home/vpn/.ssh
root@server:~# chown -R vpn.vpn /home/vpn
root@server:~# passwd vpn
==> Use a generated hard to remember password. You will use it only once.
Generate root RSA keys on the client
root@client:~# ssh-keygen
Copy the client root RSA public key to the server vpn user authorized keys
root@client:~# scp .ssh/id_rsa.pub vpn@server:./.ssh/authorized_keys
root@server:~# chmod 700 /home/vpn/.ssh
root@server:~# chmod 600 /home/vpn/.ssh/authorized_keys
Test the automatic login :
root@client:~# ssh -l vpn server
==> You should get the vpn user shell without password
Setup sudo on the server to allow vpn user run the pppd command
root@server:~# visudo
Add:
Cmnd_Alias VPN=/usr/sbin/pppdvpn ALL=NOPASSWD: VPN
Test sudo :
root@server:~# su – vpn
vpn@server:~$ sudo usr/sbin/pppd noauth
==> should see pppd garbage on your terminal
The vpn-pppssh ScriptUse this script in the client
Change those lines for your needs :
SERVER_HOSTNAME=eldivino.domain.com
SERVER_USERNAME=vpn
SERVER_IFIPADDR=192.168.3.2
CLIENT_IFIPADDR=192.168.3.1
Test the VPN link
root@client:~# ./vpn-pppssh start
Should see something like :
Using interface ppp0Connect: ppp0 <--> /dev/pts/1local IP address 192.168.3.1remote IP address 192.168.3.2
Test the VPN link :
root@client:~# ping 192.168.3.1 (ping client local IP)root@client:~# ping 192.168.3.2 (ping server IP)root@server:~# ping 192.168.3.1 (ping client IP)
Setup server routing :
root@server:~# echo 1 > /proc/sys/net/ipv4/ip_forward
root@server:~# iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE
root@server:~# iptables -A FORWARD -i eth0 -o ppp0 -m state –state RELATED,ESTABLISHED -j ACCEPT
root@server:~# iptables -A FORWARD -i ppp0 -o eth0 -j ACCEPT
Add default route on the client :
root@client:~# route add -net default gw 192.168.3.2
Test if every things work from the client :
root@client:~# ping www.google.ca