How to route only specific subnet to OpenVPN Server
I want to route only traffic for 192.168.255.0/24 through my remote openvpn server.
This answer suggests adding the following to the client .ovpn
route-nopull
route 192.168.255.0 255.255.255.0
However, this doesn't work as when I connect and then check my external IP address using the below, I get the IP of my openVPN server, not my local machine.
dig +short myip.opendns.com @resolver1.opendns.com
For context, the point of the VPN is to allow several remote clients to access each other from arbitrary locations, but they should use the default local routing for everything else: www PoE cameras etc. I set up openVPN server using https://github.com/kylemanna/docker-openvpn
client is OpenVPN 2.4.7 on Ubuntu 16.04
my local .ovpn config
client
nobind
dev tun
remote-cert-tls server
remote 157.245.203.172 1194 udp
route-nopull
route 192.168.255.0 255.255.255.0
# various certificates / keys
redirect-gateway def1
My server openvpn.conf
# client specific configurations
client-config-dir ccd
# allow clients to reach other
client-to-client
server 192.168.255.0 255.255.255.0
verb 3
key /etc/openvpn/pki/private/XXX.XXX.XXX.XXX.key
ca /etc/openvpn/pki/ca.crt
cert /etc/openvpn/pki/issued/XXX.XXX.XXX.XXX.crt
dh /etc/openvpn/pki/dh.pem
tls-auth /etc/openvpn/pki/ta.key
key-direction 0
keepalive 10 60
persist-key
persist-tun
proto udp
# Rely on Docker to do port mapping, internally always 1194
port 1194
dev tun0
status /tmp/openvpn-status.log
user nobody
group nogroup
comp-lzo no
### Route Configurations Below
route 192.168.254.0 255.255.255.0
### Push Configurations Below
push "block-outside-dns"
push "dhcp-option DNS 8.8.8.8"
push "dhcp-option DNS 8.8.4.4"
push "comp-lzo no"
Solution 1:
Remove the:
redirect-gateway def1
From your client configuration.