Linux – Automatically setup routing after OpenVPN connection

iptableslinuxopenvpnroutingvpn

I'm using Debian 6 as my server, I have configured OpenVPN server there, and clients are connecting successfully using tap mode. This server is available from the internet, but It's also connected to internal network.

Local LAN: 192.168.3.0/24 – eth0 on OpenVPN server
OpenVPN clients: 192.168.199.0/24 – tap0 on OpenVPN server

It would be great if someone could give mi steps I have to follow to allow clients who connect to OpenVPN server to see and be able to connect to each machine within LAN where OpenVPN server is located (192.168.3.0/24 network).
It would be perfect if you could tell me how to setup this routing automatically after client connects.

Best Answer

If you really need a TAP-style connection, you would need to specify the server-bridge option without further parameters - this would enable bridging mode and OpenVPN pass on DHCP requests (DHCP proxy mode). You also would need to bridge your tun interface with whatever your LAN interface is using brctl:

brctl addbr br0
brctl addif br0 eth0
brctl addif br0 tun0
ifconfig br0 inet 192.168.3.99 netmask 255.255.255.0

see the server-bridge option description in the OpenVPN documentation for details.

But honestly, you should rather route than bridge whenever possible - it allows for better debugging and less unnecessary network noise (broadcasts) transmitted through your VPN.

For this case, a config file containing the push "route 192.168.3.0 255.255.255.0" on the server and the accompanying client-style config file (specifying the client option) would do. Example:

local <your public IP address>
port <your OpenVPN port>
proto udp
dev tun0
# reduce MTU if necessary
# tun-mtu 1400

# place your cert/key/DH paths here
ca keys/ca.crt
cert keys/server.crt
key keys/private/server.key
dh keys/dhparm.pem

# OpenVPN client network
server 192.168.99.0 255.255.255.0

# push client route
push "route 192.168.3.0 255.255.255.0"

keepalive 10 60

status /var/log/openvpn-status.log

daemon

# logging options
verb 4
mute 20

See the documentation for details on option parameters.