In a scenario where one machine has access to the internet, and a remote machine does not (due to firewall restrictions), but is accessible via a VPN or something. There is a way to provide internet access for this remote machine.
One way this can be achieved with dynamic port forwarding in SSH, at least for HTTP requests.
Suppose hostA
is the local machine, which can access the internet; and hostB
is the machine that is accessible from hostA
but its access do the internet is blocked by a firewall.
From hostA
, connect to hostB
:
ssh -R localhost:9000 user@hostB
This will open a socks proxy in hostB
in port 9000, that will forward connections through the SSH connection to be coming out of hostA
.
Next step is to setup this proxy to be used by hostB
. For several terminal applications its possible to set this up by exporting a few environment variables.
export http_proxy="socks5h://localhost:9000"
export https_proxy="socks5h://localhost:9000"
This way, the HTTP (and HTTPS) requests should be redirected via our new proxy. Using "socks5h"
will also resolve the DNS for these requests via proxy, "socks5"
will try to resolve DNS locally and then make the request to the proxy. This should work for most applications that uses HTTP requests through cURL.
Of course circumventing firewall restrictions with this can be a security hazard and can be against company security rules.