Networking – How to enable LAN access to OpenVPN clients

networkingopenvpn

I have a server with 2 real NIC and 1 virtual NIC (tun0) created by OpenVPN.

eth0 is LAN - IP 192.168.2.1
eth1 is Internet - IP is public internet IP
tun0 is created by openvpn

What I need is that clients that connect to VPN server over eth1 will also get access to eth0 network, eg. will be able to connect to 192.168.2.21

This used to work in past until I rebooted the server and routing info got reset :/ I configured this couple years ago and forgot how I did that.

Routing table now looks like this:

Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
default         public gw       0.0.0.0         UG    0      0        0 eth1
public ip       *               255.255.255.0   U     0      0        0 eth1
192.168.2.0     *               255.255.255.0   U     0      0        0 eth0
192.168.8.0     192.168.8.2     255.255.255.0   UG    0      0        0 tun0
192.168.8.2     *               255.255.255.255 UH    0      0        0 tun0

When I launch OpenVPN it tries to add route

Tue Oct 11 19:29:58 2016 /sbin/ip route add 192.168.2.0/24 via 192.168.8.2
RTNETLINK answers: File exists
Tue Oct 11 19:29:58 2016 ERROR: Linux route add command failed: external program exited with error status: 2

It however doesn't seem to be possible because it already exists. When I remove this route openVPN succeeds in adding but it's no longer possible for server to reach 192.168.2.0/24 network.

How can I make it work?

EDIT: yes, I have both IPv4 and IPv6 forwarding enabled

Best Answer

you'll need ip_forward set in the sysctl, and an accept line in the FORWARD table in iptables (which often defaults to ACCEPT anyhow)

http://www.ducea.com/2006/08/01/how-to-enable-ip-forwarding-in-linux/

Related Question