I need to tunnel my OpenVPN traffic through SSH. After some struggle with the setup I am able to connect to my openvpn server through a ssh tunne. I had to disable -> push "redirect-gateway def1 bypass-dhcp" <- in my server.conf to get the openvpn connection working. Otherwise my ssh tunnel dies and drops the vpn connection.
But all of my traffic is routed through the public client interface now and not through the vpn connection.
Setup:
SSH Tunnel opened from client:
autossh -M 0 -o "ServerAliveInterval 30" -o "ServerAliveCountMax 3" -f root@ovpnserver -N -L 442:localhost:442
port 442
proto tcp
dev tun
ca ca.crt
cert server.crt
key server.key
dh dh.pem
server 172.9.0.0 255.255.255.0
#push "redirect-gateway def1 bypass-dhcp"
push "dhcp-option DNS 208.67.222.222"
push "dhcp-option DNS 208.67.220.220"
keepalive 10 120
tls-auth ta.key 0
cipher AES-256-CBC
user nobody
group nogroup
persist-key
persist-tun
status /var/log/openvpn/openvpn-status.log
log /var/log/openvpn/openvpn.log
log-append /var/log/openvpn/openvpn.log
duplicate-cn
verb 3
explicit-exit-notify 0
client
dev tun
proto tcp
remote localhost 442
resolv-retry infinite
nobind
user nobody
group nogroup
persist-key
persist-tun
ca ca.crt
cert client.crt
key client.key
remote-cert-tls server
tls-auth ta.key 1
cipher AES-256-CBC
script-security 2
up /etc/openvpn/update-resolv-conf
down /etc/openvpn/update-resolv-conf
verb 3
I have found an article
https://community.openvpn.net/openvpn/wiki/Concepts-PolicyRouting-Linux?__cf_chl_jschl_tk__=9ae2ae44a51d992ce1b6076f548d3b3f2f03bcb3-1616533753-0-AeSmQhPsK6CZ0qdr9gxjL3rDVTLjn3346wHOrBDkNXldm1wf9HZldQlACAfzXWY_79HwU7S5VJ7fFx3PidABQq_HEk_heaZMs-zXn__r8_sm9proIvIqeyAtTwZiYXKZEYQ70fiXcMv7dqxPFF_zsDGnlWbThFxz0PQXJOhw98Vgs5EWUU60_jXHRMNgD7wi7DTdJjpPeUfwf1zRaqwu1fFJDeDMapPuB-LQguc2--xdRO-YBLZvaY4PX4r3G3ElwgFmxjwRF1QPkIfMBYbn43ORixp5R0rYrHWmeUDgMdCfDL_bdVkt_47lhz7Fft9uy-tb6mAMJpPlgdeum88NLJZpbHoO6GL3CPYrgxnwjfcREOYGQBz_docafzJCSeAtDw ... but I do not understand how to reach this solution:
There are two solutions to the problem. If you know in advance the external source of the connection, you can add a higher-priority route using the local gateway. This is not generally the case, and so will not work as a generic solution.
So all traffic from ovpnserver to client WAN is routed with higher priority? Does anyone have a example for that route?
Thanks in advance.