OpenVPN: Connect your LANs over the Internet

Setup

by ross at 13:14:48 on December 31, 2012

Let's assume that we need to connect server's LAN (192.168.10.0/24) and client's LAN (192.168.20.0/24).

Server

/usr/local/etc/openvpn/openvpn_officelan.conf:

port 1194
dev tun0 # use unique tunN for every config
ifconfig 172.16.0.1 172.16.0.2 # our-ip, remote-ip
up openvpn_officelan.up.sh
down openvpn_officelan.down.sh
secret openvpn_officelan.key
script-security 2 # needed to execute .sh scripts

/usr/local/etc/openvpn/openvpn_officelan.up.sh:

#!/bin/sh

/sbin/route add -net 192.168.20.0/24 -interface $1

/usr/local/etc/openvpn/openvpn_officelan.down.sh:

#!/bin/sh

/sbin/ifconfig $1 destroy
# chmod a+x *.sh

Client

/usr/local/etc/openvpn/openvpn_officelan.conf:

remote vpn.example.com 1194 # replace with your server address
dev tun0 # use unique tunN for every config
ifconfig 172.16.0.2 172.16.0.1 # our-ip, remote-ip
up openvpn_officelan.up.sh
down openvpn_officelan.down.sh
secret openvpn_officelan.key
script-security 2 # needed to execute .sh scripts

/usr/local/etc/openvpn/openvpn_officelan.up.sh:

#!/bin/sh

/sbin/route add -net 192.168.10.0/24 -interface $1

/usr/local/etc/openvpn/openvpn_officelan.down.sh:

#!/bin/sh

/sbin/ifconfig $1 destroy
# chmod a+x *.sh

Run

Create rc.d script and run the daemon.

Comments