I set up an OpenVPN server on a Debian 9 server, and everything seems to work fine: I can access Internet through that VPN. However, I figured out that any traffic targeting the server is still using either eth0
or wlan0
instead of tun0
. For example, if I am on a local network that does not allow ICMP:
ping google.com
will work as expected (using tun0
as output interface)
ping myvpn.com
(if myvpn.com is my vpn server) will not work, as it uses eth0 or wlan0 as output interface and so is blocked by the network firewall.
I looked at the routes and found that when connecting, OpenVPN client is adding an entry in the routing table:
1.2.3.4 via 10.0.0.1 dev wlp7s0 proto static metric 600
(where 1.2.3.4 is my vpn public IP)
I understand what this route is for: when OpenVPN client send packets to the OpenVPN server to be then rerouted to Internet, it has to send them through a physical interface. However, I would like that when I ping or SSH to the server, packets are send through the tun0 interface.
Is there an option to give to OpenVPN client or maybe an iptables
rule so that only OpenVPN generated packets are sent through a physical interface?
EDIT: Everything is working fine for outgoing traffic: it goes all through the VPN, except for the traffic that has for destination the server itself. I think the problem may be on the client side, where the route to the server is being added Here is server config file:
port 443
proto tcp
dev tun
ca /path/to/ca.crt
cert /path/to/server.crt
key /path/to/server.key
dh /path/to/dh.pem
server 10.8.0.0 255.255.255.0
keepalive 10 120
comp-lzo
persist-key
persist-tun
status openvpn-status.log
verb 3
push "redirect-gateway def1 bypass-dhcp"
push "route 10.8.8.0 255.255.255.0"
I tried to modify this line:
push "redirect-gateway def1 bypass-dhcp"
to this:
push "redirect-gateway autolocal def1 bypass-dhcp"
as suggested in answers, but result is still the same: I can ping google.com but not my VPN public IP