0

Ive got access to a server over ssh to run some experiments and need to download some packages over the internet to perform these. Unfortunately, the server has no connection to the internet, or blocks the outgoing connection, I'm not sure. But as mentioned before, I can connect to the machine over ssh or transfer files via scp from my local machine.

Is there a way I can relay the internet connection of the server over my local machine so that I can download the required packages? Ive looked into ssh tunneling but due to my inexperience I was unsuccessful.

Edit: Server system is Ubuntu 14.04.4 LTS, my local machine is mac os x, but I have a Ubuntu virtual machine.

2
  • More details are required here. What OSes are we talking? Presumably at least one of them is linux, seeing as you're talking about ssh/scp. Also, how is your routing tables set up?
    – Jarmund
    Jun 29, 2016 at 6:49
  • Of course. I added details to the question. I don't know how the routing tables are set up. Is there a way I can find out?
    – spurra
    Jun 29, 2016 at 11:50

1 Answer 1

2

You can. I used to be in a similar situation, and I used an ssh connection from the server to the client to set-up a SOCKS proxy. You can set it up straightforwardly with the aid of the flag -D port number (for instance 10001) when making an SSH connection from the server to the client.

(on the server, make a SSH connection to the client and leave this open:)

ssh -D 10001 client

Subsequently, you can use proxychains in another terminal to allow programs to make TCP connection to the outside world through the newly created SOCKS proxy. The configuration of proxychains is very straightforward, just add one row to your proxychains.conf file:

socks5 127.0.0.1 10001

to notify the proxychains how the proxyserver can be reached. After that, you can use proxychains in the following way, for example to tell wget to use the proxy:

proxychains wget address

As soon as you close the first connection, the proxy ceases to exist.

You didn't mention whether you are able to connect from the server directly to the client (maybe due to firewall settings you can't?). If that is the case, you could still use this method, although you could make a reverse tunnel first:

(on the client, make an SSH connection to the server and make a reverse tunnel:)

ssh -R 9999:localhost:22 server

This makes a connection to the server, and creates a port (in this example 9999) that connects back to the client on port 22 (defaults SSH port). On the server, you can then make a connection to the client connecting through this tunnel:

ssh -p 9999 -D 10001 localhost

If you don't want to set-up a SOCKS proxy altogether, then you are probably better off making an SSH connection from the server to the client, and make a local tunnel (with -L) to the destination if you only want to reach a specific server.

8
  • I'm using proxychains-ng for this, proxychains didn't seem to function properly. You may have a mistake in your code: ssh -R 9999:localhost:22 server opens port 9999 on the server and connects to port 22 on my machine. So shouldn't the subsequent command be ssh -p 22 -D 10001 client, that is -p should have the value 22 and not 9999? I've tried both variants and unfortunately, neither can establish a connection to the client.
    – spurra
    Jun 30, 2016 at 10:40
  • 1
    I'm not sure whether 'proxy_dns' in the configuration file for proxychains is uncommented by default, but you want to use this too as your machine probably has no access to a DNS server either. By doing so, you allow the domain name translations to be done by the proxy too.
    – Sander
    Jun 30, 2016 at 10:56
  • 1
    You are right, the last one should not say client but localhost. Sorry, will fix that in the post. Once you've opened the reverse tunnel, it indeed opens port 9999 on the server and connects to port 22 on the client, as you want. You should leave this terminal as is, because it keeps that tunnel alive. In another terminal on the server, you should then be able to ssh -p 9999 -D 10001 localhost to go through the tunnel to your client, and get the proxy alive. Then, you should then be able to use the proxy with proxychains-ng just fine, I've just tested it once more.
    – Sander
    Jun 30, 2016 at 11:33
  • 1
    In case you only want to download files from known locations, it turns out you don't need proxychains and use wget directly, which knows how to access SOCKS proxies
    – Sander
    Jun 30, 2016 at 11:36
  • Thanks for the update. I was capable of connecting the server to my client thanks to your fix! Concerning proxchains, am I suppose to run this on the client or on the server? Because running it on the server does not seem to function. E.g /proxychains4 -f src/proxychains.conf ping www.google.de (the long command is taken from the github readme of proxychain-ng)
    – spurra
    Jun 30, 2016 at 18:55

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .