I have a setup of three local VMs in two networks.
The OpenVPN server config:
port 1194
proto udp
dev tun
ifconfig 172.16.0.1 172.16.0.2
secret static.key
push "redirect-gateway def1"
push "remote-gateway 172.16.0.1"
The OpenVPN client config:
remote 192.168.0.1 1194
dev tun
ifconfig 172.16.0.2 172.16.0.1
redirect-gateway def1
secret static.key
Iptables is configured on the server to perform `NAT`ing from the VPN interface to the interface, where the third VM is connected.
iptables -I FORWARD -i tun0 -o enp0s8 -s 172.16.0.0/24-m conntrack --ctstate NEW -j ACCEPT
iptables -I FORWARD -m conntrack --ctstate RELATED,ESTABLISHED -j ACCEPT
iptables -t nat -I POSTROUTING -o enp0s8 -s 172.16.0.0/24 -j MASQUERADE
The problem is, that the default route is never configured on the client, when it connects to the VPN server.
If I manually set the default route on the client with:
sudo ip route add 0.0.0.0/0 via 172.16.0.1
The client can ping the third VM perfectly fine.
I've read trough
https://openvpn.net/index.php/open-source/documentation/howto.html#redirect and numerous other similar issues, where the answer was to use redirect-gateway or iptables configuration on the server, but that did not help.
How do I successfully push the default gateway to the client with the OpenVPN config, so that all traffic is redirected trough the VPN server?