Wednesday, April 25, 2007

Avoiding VPNs with SSH and Curl

All of the VPN clients I've used have an annoying habit of rebuilding my routing tables so that all traffic passes through the VPN, as opposed to target-network-specific traffic (by which I mean traffic destined for the network to which I've established the VPN connection). This can of course be fixed by manually rebuilding routing tables after the VPN connection is established: the default route (through the VPN) is reset to the gateway previously serving default traffic; usually, VPN clients add a specific route for the target network anyway, so no further change is needed.

But there is a good reason VPN clients route all traffic through the VPN. Frequently, the target network has permissions to access stuff out on the web that your host network might not. For instance, universities and libraries often maintain IP-pool-based subscriptions to online digital libraries. So, sitting on the university network, you can access material on the ACM or IEEE website; at home, you cannot. Since all traffic goes through the VPN, when you have established a connection to the university, you can access those materials.

Of course, that slows down all of your Internet browsing, since all requests and replies must pass through the VPN. Futhermore, it means that all of your data is passing through the target network - something you may not want, for privacy reasons. Hence the routing-table fix mentioned above.

So here's a way to get around all that. It assumes you have an account on machine in the target network, that said machine is accessible from the Internet, and that said machine runs SSH and has curl installed. Similarly to using SSH to move things, you can use SSH to fetch Internet resources that from within the target network, sans VPN.
ssh -l name host "curl address" > local_file
will do the trick. "name" is your account name on the machine "host," and "address" is the URL of the resource you want to access from within the target network; "local_file" is the name of the file on your local machine in which the fetched resource will be saved.

Not only does this let you grab things as if you were within the target network avoiding the time-consuming VPN connect/disconnect, it does so without placing any temporary files on the remote machine "host." And, since curl prints its status information to STDERR, you get to see your download's progress, even as curl saves the file to your local disk.

No comments: