1

I want to set up an OpenVPN-based private VPN so I can access my home LAN while on the road. I'm looking to have these capabilities:

  • Remote clients should be on a separate subnet (which seems to be the easiest way to set up OpenVPN)
  • Remote clients can "see" and interact with all the devices on my home LAN;
  • Home clients can "see" and interact with remote clients;
  • All "non LAN" traffic from the remote clients should use the remote client's existing internet connection (i.e., I don't want remote clients to access the internet by routing through the OpenVPN server and my home LAN's own internet connection)

That last requirement, if I'm understanding things correctly, involves setting up a split tunnel.

Here's a picture which may help illustrate what I'm trying to achieve:

enter image description here The OpenVPN server is running under Debian Buster. Most, but not all, of the various remote and client machines are Windows- or iOS- based.

The VPN subnet is 192.168.5.0/24. My home LAN's subnet is 192.168.1.0/24. My home LAN's internet gateway is 192.168.1.254.

I have been able to create remote connections which appear to be split tunnels. From my iPhone I can successfully create a link to the OpenVPN server and the iPhone is assigned an IP address from the VPN subnet but I am still able to surf the web (which I believe means the "non LAN" traffic is being routed to the iPhone's internet connection).

The iPhone can ping either the client side of the VPN server (192.168.5.1) or a device from the home LAN side (192.168.1.5, which is the home LAN address of the VPN server) But I cannot establish an SSH or RDP connection from the client side from the iPhone. Sometimes pinging just isn't enough :).

Here is my OpenVPN server.conf file:

port **redacted**
proto udp
dev tun

ca /etc/openvpn/server/ca.crt
cert /etc/openvpn/server/mycroft-server.crt
key /etc/openvpn/server/mycroft-server.key
dh /etc/openvpn/server/dh.pem

topology subnet
server 192.168.5.0 255.255.255.0
client-to-client

push "route 192.168.1.0 255.255.255.0 192.168.5.1"
push "dhcp-option DNS 192.168.1.5"
push "dhcp-option DOMAIN localnet"
push "block-outside-dns"

cipher AES-256-CBC

tls-version-min 1.2
tls-crypt /etc/openvpn/server/ta.key
tls-cipher TLS-DHE-RSA-WITH-AES-256-GCM-SHA384:TLS-DHE-RSA-WITH-AES-256-CBC-SHA256:TLS-DHE-RSA-WITH-AES-128-GCM-SHA256:TLS-DHE-RSA-$

auth SHA512
auth-nocache

keepalive 10 60

persist-key
persist-tun

compress lz4

daemon

user nobody
group nogroup

status /etc/openvpn/openvpn-status.log
status-version 3
log-append /var/log/openvpn.log

verb 3

Here is my client ovpn file, minus the various cryptographic elements:

client
dev tun
proto udp
remote moose.zapto.org 37639

route 192.168.1.0 255.255.255.0 192.168.5.1

cipher AES-256-CBC

auth SHA512
auth-nocache

tls-version-min 1.2
tls-cipher TLS-DHE-RSA-WITH-AES-256-GCM-SHA384:TLS-DHE-RSA-WITH-AES-256-CBC-SHA256:TLS-DHE-RSA-WITH-AES-128-GCM-SHA256:TLS-DHE-RSA-$

resolv-retry infinite
compress lz4
nobind

persist-key
persist-tun

mute-replay-warnings

verb 3

Additional Info

I should've included this but forgot. Here's the output of route -n run on the OpenVPN server:

Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
0.0.0.0         192.168.1.254   0.0.0.0         UG    202    0        0 eth0
192.168.1.0     0.0.0.0         255.255.255.0   U     202    0        0 eth0
192.168.5.0     0.0.0.0         255.255.255.0   U     0      0        0 tun0

The last entry is apparently created by OpenVPN.

I tried adding a route from to the VPN subnet from my home LAN's subnet with this command:

sudo ip route add 192.168.5.0/24 via 192.168.1.5 dev tun0

but it produces the following error:

Error: Nexthop has invalid gateway.

Ping and Traceroute

From my iPhone I can ping both the client-side of the VPN server (192.168.5.1) and the machine the VPN server is running on (i.e., from its "LAN side": 192.168.1.5).

From the client side tracert 192.168.1.5 succeeds with a single hop.

4
  • So much text... what is the actual question? ;) Would be helpful if you start with that...
    – Albin
    Oct 18, 2020 at 17:50
  • There’s no pleasing everybody :). I’m trying to get a functioning VPN with the specs set out at the start of the post. The rest is config information — whose length I don’t control — and things I’ve tried/what I’ve observed. Oct 18, 2020 at 17:54
  • So you can't ping a device on the LAN with a device connected via VPN? The routes from that device might be helpful a traceroute (for a LAN IP, a VPN IP and a Internet IP) from the device as well.
    – Albin
    Oct 18, 2020 at 18:48
  • I interpret your core question as "why a device connected via VPN can not communicate with a device on the LAN."
    – Albin
    Oct 18, 2020 at 18:50

2 Answers 2

1

You are almost there.

sudo ip route add 192.168.5.0/24 via 192.168.1.5 dev tun0

Above command did not work because interface and next-hop belong to different subnets.

You need the following lines in the server.conf:

# Define VPN virtual subnet
server 192.168.5.0 255.255.255.0
# Specify local LAN, and permit routing
push "route 192.168.1.0 255.255.255.0"
route 192.168.5.0 255.255.255.0

Assuming that eth0 is internet facing, eth1 is LAN facing and tun0 is the tunnel interface (assuming that UDP 1194 have already been added to the firewall exceptions)

$ sudo echo 1 > /proc/sys/net/ipv4/ip_forward
$ sudo iptables -t nat -A POSTROUTING -s 192.168.5.0/24 -o eth1 -j MASQUERADE
$ sudo iptables -A FORWARD -i tun0 -j ACCEPT
$ sudo iptables -A FORWARD -i tun0 -o eth0 -s 192.168.5.0/24 -j ACCEPT
$ sudo iptables -A FORWARD -i eth1 -o tun0 -d 192.168.5.0/24 -j ACCEPT
$ sudo iptables -A FORWARD -m state --state ESTABLISHED,RELATED -j ACCEPT
$ sudo iptables -A FORWARD -j REJECT
1
  • Thanx, @Bruce! I’d stumbled onto most of that since I posted the question but it’s good to have it all in one place and explained. Turns out another problem, though, is that the OpenVPN iOS client doesn’t support compression and fails silently if you enable it. Oct 21, 2020 at 15:13
0

For anyone interested in a more detailed write-up on the problems I encountered getting OpenVPN to run on a Debian Buster Raspberry Pi please see https://imperfect.olbert.com/my-vpn-saga-take-two/.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .