Hi,
I have a working routed OpenVPN setup as depicted by the following network diagram.
OpenVPN Server LAN: 192.168.1.0/24
OpenVPN Client LAN: 192.168.2.0/24
Below are my server and client configurations:
SERVER
local 192.168.1.10
dev tun
proto udp
port 11994
ca /etc/openvpn/ca-server01-ca.crt
cert /etc/openvpn/server01.crt
key /etc/openvpn/server01.key
dh /etc/openvpn/dh2048.pem
server 172.29.29.0 255.255.255.0
ifconfig-pool-persist /etc/openvpn/ipp.txt
route 192.168.2.0 255.255.255.0
push "route 192.168.1.0 255.255.255.0"
client-config-dir /etc/openvpn/ccd
tls-auth /etc/openvpn/ta.key 0
keepalive 15 120
cipher AES-256-CBC
auth SHA512
tls-cipher DHE-RSA-AES256-SHA
comp-lzo
max-clients 10
persist-key
persist-tun
log-append /var/log/openvpn.log
verb 3
management 127.0.0.1 11995
client-to-client
SERVER CCD (client01)
iroute 192.168.2.0 255.255.255.0
CLIENT
client
dev tun
proto udp
remote x.x.x.x 11994
nobind
persist-key
persist-tun
ca /etc/openvpn/ca-server01-ca.crt
cert /etc/openvpn/client01.crt
key /etc/openvpn/client01.key
dh /etc/openvpn/dh2048.pem
ns-cert-type server
tls-auth /etc/openvpn/ta.key 1
tls-remote server01
cipher AES-256-CBC
auth SHA512
tls-cipher DHE-RSA-AES256-SHA
comp-lzo
log-append /var/log/openvpn.log
verb 3
management 127.0.0.1 11995
The only "issue" I have is when new connectinos destined for the Server LAN originate directly from the OpenVPN Client. Instead of those connections originating from
its IP address (192.168.2.254), they originate from its TUN adapter's IP address (172.29.29.6). Because the OpenVPN Client server is also acting as a DNS server for
the LAN, this caused some grief when DNS broke when forwarding requests to the 192.168.1.0/24 network.
root@client01:~# route
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
default 192.168.2.252 0.0.0.0 UG 100 0 0 eth1
172.29.29.0 172.29.29.5 255.255.255.0 UG 0 0 0 tun0
172.29.29.5 * 255.255.255.255 UH 0 0 0 tun0
192.168.1.0 172.29.29.5 255.255.255.0 UG 0 0 0 tun0
192.168.2.0 * 255.255.255.0 U 0 0 0 eth1
root@client01:~# ip route get 192.168.1.2
192.168.1.2 via 172.29.29.5 dev tun0 src 172.29.29.6
cache
I have implemented a workaround by adding static routes to both gw01 and gw02 for 172.29.29.0/24 to be routed via the respective OpenVPN instance, however I would
rather not use routes to accomplish it. I would prefer the non-TUN IP address be used for all requests.
I have manually done this by manually deleting the route (that gets pushed after connect), and replacing it with one that specifies the source address to use.
root@client01:~# ip route del 192.168.1.0/24 dev tun0 ; ip route add 192.168.1.0/24 via 172.29.29.5 dev tun0 src 192.168.2.254
root@client01:~# route
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
default 192.168.2.252 0.0.0.0 UG 100 0 0 eth1
172.29.29.0 172.29.29.5 255.255.255.0 UG 0 0 0 tun0
172.29.29.5 * 255.255.255.255 UH 0 0 0 tun0
192.168.1.0 172.29.29.5 255.255.255.0 UG 0 0 0 tun0
192.168.2.0 * 255.255.255.0 U 0 0 0 eth1
root@client01:~# ip route get 192.168.1.2
192.168.1.2 via 172.29.29.5 dev tun0 src 192.168.2.254
cache
Now, the routing table is identical, just the IP address used for outbound connections destined for 192.168.1.0/24 is NOT the TUN interface IP address.
This appears to work as I expect, even after deleting the recently added routes for 172.29.29.0/24.
That brings me to my question: Is there a way to achieve this directly via OpenVPN's
--route (or similar) command? Or will it have to be done manually via running a
custom command via
--up or
--route-up? I don't care if it can be pushed or it needs to be set in the local config file.
Thanks.