La Vita è Bella

2005-03-03

OpenVPN

Finally, configured OpenVPN well now.

My situation is: 2 computers A & B, A is at the lab and in a subnet, B is at the dormitory. I just want A to use B's connection.

Following OpenVPN's Static Key Mini-HOWTO, I used the following configurations:

Server:

remote server.ip dev tun0
ifconfig 10.8.0.1 10.8.0.2
secret /etc/openvpn/static.key
comp-lzo
keepalive 10 60
ping-timer-rem
persist-tun
persist-key

Client:

remote server.ip
dev tun0
ifconfig 10.8.0.2 10.8.0.1
secret /etc/openvpn/static.key
comp-lzo
keepalive 10 60
ping-timer-rem
persist-tun
persist-key

And then is the routing settings. At server, I must enable ip forwarding as the following script:

#!/bin/sh
modprobe iptable_nat
iptables -t nat -A POSTROUTING -s 10.8.0.0/16 -d ! 10.8.0.0/16 -j MASQUERADE
echo 1 > /proc/sys/net/ipv4/ip_forward

At client, Add the original route to the server network, and add 10.8.0.1 as the gateway to all other networks:

#!/bin/sh
route add -net server.ip netmask 255.255.255.0 gw 192.168.0.251
route del default route add default gw 10.8.0.1

And then I can use OpenVPN!

14:41:00 by fishy - Permanent Link

May the Force be with you. RAmen