No, it isn't.
First, the command doesn't work because you're telling cURL to speak a completely different protocol than the server speaks. OpenVPN and http://
are nothing alike – the server doesn't recognize any requests sent by cURL, and cURL doesn't understand any responses.
Second, it cannot work because cURL does not support any VPN protocols. There is no way to correctly specify that cURL should speak the OpenVPN protocol, or any other VPN protocol, because that's not in the program.
(In theory it's not impossible to add this to cURL, but it would massively increase complexity compared to "proxy" protocols, because cURL would need to learn TCP and IP in addition to learning about the VPNs themselves – i.e. it would need to duplicate much of of the network stack that resides in the OS.)
If you have root access to the system, you can use various mechanisms to limit what the OpenVPN connection is used for:
- the regular IP routing table, to choose VPN usage based on destination IP address;
- policy routing, to select the connection depending on source IP address (e.g. make it so that
curl --interface tun0
would use the VPN but regular curl
would not);
- firewall rules, to select the connection depending on the protocol and ports used, and even based on user ID;
- network namespaces, to create two different "worlds" where some processes see only the VPN while all other processes only see the original connection.
For example, if you want to limit VPN usage to just 10.0.0.0/8 (or vice versa, to exclude that network from the VPN) that's trivial to do using just OpenVPN's route
options. For example, to limit the VPN to a specific network only:
route 10.0.0.0 255.0.0.0 vpn_gateway
route-nopull
And to exclude a specific network while using the VPN for everything else:
route 10.0.0.0 255.0.0.0 net_gateway
Hey Gravvity, how would you go about policy routing? I want to be able to do exactly what you said,
– Housemd – 2019-11-20T20:34:33.150curl --interface tun0 https://website.com
, but I don't know how. I've posted a question here (https://serverfault.com/questions/992624/vpn-client-doesnt-have-internet-connection) and it has reputation with your name on it :)@Housemd: Plenty of existing threads on that topic - see e.g. https://superuser.com/a/1503160/1686 or search for
– user1686 – 2019-11-20T21:27:02.420ip rule
.Thanks, but that answer uses CentOS, I use Ubuntu, and I have no idea what is
NetworkManager
ornetwork
in Ubuntu. – Housemd – 2019-11-22T19:18:21.830