On Linux you can adjust the routing rules using
ip rule and
ip route commands. The latter one is a more advanced equivalent for the
In your case you might obtain the desired behavior by having a separate routing table where the default gateway on
wlan0 interface is the only (or anyway preferred) default gateway present, and then set a routing rule stating that all traffic coming from the
tun0 interface is to use this separate routing table.
That is obtainable for example through the following two commands:
ip route add default via 192.168.222.1 table 100 # <-- 100 is an arbitrary number for the separate routing table
ip rule add iif tun0 table 100
while to clear them up, use:
ip rule del iif tun0 table 100
ip route flush table 100
You can test the commands live, after establishing the VPN, and see that everything works as intended.
Then you might want to have those commands (or their best equivalent for your overall setup) executed by
openvpn when needed. To do so the simplest way is to put those commands in two scripts (respectively), and then call them via OpenVPN's
Depending on how you actually use OpenVPN, you need to either run
--route-up script-that-adjusts-routing.sh and
--route-pre-down script-that-undoes-routing.sh (and possibly also
--script-security 2) from the command line, or add these configurations in the OpenVPN
.conf file of your tunnel.
If you already have
route-pre-down scripts, then you need to add the adjusting commands to your pre-existing scripts instead, and this may require additional care depending on what these scripts do.