Ssh – Serve Internet to remote machine via SSH session

internetPROXYssh

The machine via which I'm SSHing to the remote/host machine (same network/LAN) has access to the Internet but the host doesn't.

Running updates and installing packages on the host gets quite inconvenient because then I have to start a proxy locally and then configure the remote machine to use it.

So I was wondering if there is a easier way of doing this via, maybe, SSH or something else?

I have a realization of the complexities that lie within, but was curious to know.

Using plink through Emacs (if it matters).

Best Answer

Let's call the machine that has internet access hasinet and the one that doesn't noinet.

If you can make an SSH connection from noinet to hasinet

You can do this easily with OpenSSH's built-in SOCKS proxy. This command will set up a SOCKS proxy on noinet listening on port 1080:

noinet$ ssh -D 1080 hasinet

If you can only make SSH connections to noinet from hasinet

You can run OpenSSH's SOCKS proxy on hasinet and then forward a port from noinet to hasinet. This can cleverly be done with one command like so (thanks @Patrick):

hasinet$ ssh -D 1080 localhost -t ssh -R 1080:localhost:1080 noinet

How to use the SOCKS proxy

How you use this proxy will depend on the application. Some applications have support for SOCKS proxies built in. If that's the case, you'll need to configure your app to use the proxy on localhost:1080. If not, you can use proxychains or redsocks, as @sciurus suggests. tsocks is a lighter-weight solution if you only need to provide network access for some commands.

Related Question