No, you can't directly specify this behavior in the OpenVPN client config file. However, you can use "route-nopull" option in your config file, which will ignore routes pushed by the server. Then, you can manually add specific routes you need. Remember, this requires a good understanding of your network topology.
dev tun
tls-client
remote your-vpn-server.example.com 1194
# The "float" tells OpenVPN to accept authenticated packets from any address,
# not only the address which was specified in the --remote option.
# This is useful when you are connecting to a peer which holds a dynamic address
# such as a dial-in user or DHCP client.
# (Please refer to the manual of OpenVPN for more information.)
#float
# If redirect-gateway is enabled, the client will redirect its
# default network gateway through the VPN.
# It means the VPN connection will first connect to the VPN Server
# and then to the internet.
# (Please refer to the manual of OpenVPN for more information.)
#redirect-gateway def1
# dhcp-option DNS: To set primary domain name server address.
# Repeat this option to set secondary DNS server addresses.
# Example of a specific route to a local resource
route 192.168.x.x 255.255.255.255 net_gateway 10
#dhcp-option DNS DNS_IP_ADDRESS
pull
# If you want to connect by Server's IPv6 address, you should use
# "proto udp6" in UDP mode or "proto tcp6-client" in TCP mode
proto udp
script-security 2
If I use just
route 192.168.x.x 255.255.255.255 net_gateway, route print shows it working but the metric part is important for me to make it work the way I want it to.
My objective: Have OpenVPN always on. When the client is on my home network, have OpenVPN do
nothing, no routing whatsoever. When the client is
not on my home network, have OpenVPN route traffic to my file server but do no other routing whatsoever.
Folks told me this is what routing metrics are for.