VPNs (normally) tunnel layer 2 or 3 network packets through a specific channel. From the perspective of application layer, you don't have to take care of lower levels, as routing the network packages is taken care by the OS. OpenVPN for example creates a TUN
or TAP
virtual interface and channels all packets send by OS to these interfaces through a secure tunnel. The decision which interface to use is done regarding the routing table. A web proxy server is much simpler than a VPN since it just accept HTTP requests (application layer) and relays them.
It really depends on what kind of VPN you are using. Lets say that you're using OpenVPN and it creates a virtual interface for you (e.g. tun0
), this interface has its own IP address (e.g. 10.124.1.6
) and maybe (depending on the server's topology) a P2P address (e.g. 10.124.1.5
). You could instruct Node to bind the network connections through a specific (local) network interface using the localAdress
:
var options = {
host: "example.com",
path: "/path/to/web/service",
localAddress: '10.124.1.6', // IP address network interface
};
http.request(options);
Hypothetically, this would be the solution of selectively tunneling specific requests through a VPN interface. If this works or not, I cannot guarantee. But I'd say it would get you started with some ideas.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…