OpenVPN how to route all IPV4 traffic through the OpenVPN tunnel
Introduction
Originally I was connected from a Windows 10 machine via OpenVPN to a network (segment?) for "our" project. I could access all servers and websites related to it. But when switching to another project (using the same OpenVPN settings) I could only access the new project's servers when at the premise of that project. At home or from any other place, I could not get to the servers, e.g Jenkins. The error shown was "This site can't be reached" in Chrome. See screenshot below for the exact error:But I could get to the microservices pods directly by IP address, e.g 172.18.33.xyz (xyz are not the same in below example IP addresses, just obfuscators). So quite strange.
The administrator of the OpenVPN server didn't know how to fix the problem either. Suggested was to make sure "to route all IPV4 traffic through VPN". That made me search on the interwebs and I found below solution to work, without having to change any server settings. (I did not even have access to those server settings.)
Analyzing the problem
A) Trying the website with the hostname:C:\Users\moi>tracert website.eu
Tracing route to website.eu [183.45.163.xyz] over a maximum of 30 hops:
1 1 ms 1 ms 1 ms MODEM [192.169.178.x]
2 20 ms 19 ms 20 ms d13.xs4all.com [195.109.5.xyz]
3 22 ms 22 ms 22 ms 3d13.xs4all.com [195.109.7.xyz]
...
B) Trying the well-known google gateway:
C:\Users\moi>tracert 8.8.8.8
Tracing route to google-public-dns-a.google.com [8.8.8.8] over a maximum of 30 hops:
1 1 ms 1 ms 1 ms MODEM [192.169.178.x]
2 21 ms 20 ms 21 ms d12.xs4all.com [195.109.5.xyz]
...
Hmm so its route goes via the same initial gateway for both external IPs and the hostname, so not via the VPN.
C) Trying with the IP that works (note not the IP for the hostname from above!):
C:\Users\moi>tracert 172.18.33.xyz
Tracing route to 172.18.33.xyz over a maximum of 30 hops
1 97 ms 21 ms 20 ms 192.169.200.xyz
2 45 ms 98 ms 29 ms 172.16.11.xyz
3 130 ms 65 ms 68 ms 172.16.11.xyz
...
As you can see, the first entrypoint gateway is a different one, and most likely the wrong one.
The solution
The solution was to add this to the .ovpn OpenVPN configuration file:route-method exe
route-delay 2
redirect-gateway def1
For me even only the last line (redirect-gateway def1) was sufficient, but for others the other two lines had to be added too.
D) After adding the setting, you can see the IP of the gateway changed to, the what turns out to, be the correct one:
C:\Users\moi>tracert website.eu
Tracing route to website.eu [183.45.163.yyy] over a maximum of 30 hops:
1 143 ms 31 ms 21 ms 192.169.200.xyz
2 21 ms 20 ms 21 ms static.services.de [88.20.160.xyz]
3 21 ms 21 ms 25 ms 10.31.17.xyz
4 25 ms 21 ms 91 ms 10.31.17.xyz
...
References used:
- http://superuser.com/questions/120069/routing-all-traffic-through-openvpn-tunnel
- http://askubuntu.com/questions/665394/how-to-route-all-traffic-through-openvpn-using-network-manager
No comments:
Post a Comment