I want to use an OpenVPN connection to access my local resources.
I have iptables
set to allow connection from 192.168.1.0/24
subnet.
When I connect from my phone or Windows machine everything works perfectly fine.
But when I try to connect from Ubuntu it does not.
After checking tcpdump
and reading a lot of logs I see that packets from Ubuntu have SRC=real white ip
while for phone or Windows SRC=local tunnel ip
and it works as expected.
Then I inspected my routes when connected to the VPN, and found the following (assume 77.77.77.77
- OpenVPN server, 192.168.8.1
- my router):
Destination Gateway Genmask Flags Metric Ref Use Iface
0.0.0.0 192.168.255.5 0.0.0.0 UG 50 0 0 tun0
0.0.0.0 192.168.8.1 0.0.0.0 UG 600 0 0 wlp2s0
77.77.77.77 192.168.8.1 255.255.255.255 UGH 600 0 0 wlp2s0
192.168.8.0 0.0.0.0 255.255.255.0 U 600 0 0 wlp2s0
192.168.8.1 0.0.0.0 255.255.255.255 UH 600 0 0 wlp2s0
192.168.255.1 192.168.255.5 255.255.255.255 UGH 50 0 0 tun0
192.168.255.5 0.0.0.0 255.255.255.255 UH 50 0 0 tun0
I believe the root of my problem is:
77.77.77.77 192.168.8.1 255.255.255.255 UGH 600 0 0 wlp2s0
as it says to use my router as a gateway to access the VPN server itself. As a result, I see my real IP address instead of a tunnel IP address.
But I don't understand how to fix this. I already tried modifying the route manually to route traffic to the server over the tunnel, but it didn't help:
77.77.77.77 192.168.255.5 255.255.255.255 UGH 600 0 0 tun0
So, if all my investigation was understood correctly, to resolve the problem I need to route the traffic to vpn server itself over the tunnel instead of the default gateway.
I supposed redirect-gateway def1
directive should redirect ALL traffic over VPN, including itself. But looks like it does not.
My server.conf:
server 192.168.255.0 255.255.255.0
verb 3
key /etc/openvpn/pki/private/vpn.example.com.key
ca /etc/openvpn/pki/ca.crt
cert /etc/openvpn/pki/issued/vpn.example.com.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
port 1194
dev tun0
status /tmp/openvpn-status.log
user nobody
group nogroup
route 192.168.254.0 255.255.255.0
push "block-outside-dns"
push "dhcp-option DNS 192.168.1.1"
push "dhcp-option DOMAIN lan"
My client.ovpn:
client
nobind
dev tun
remote-cert-tls server
remote vpn.example.com 1194 udp
...certificates...
key-direction 1
redirect-gateway def1