Ubuntu – How to connect to Internet through a remote server via SSH connection


I have a problem in accessing Internet through an ssh-accessible server


EDIT: FYI, my OS is Ubuntu 16.04, and IIRC, same as the server.

Ok, here's the deal.

  • My company provide me a PC with network connection (through a proxy), but got limited to some resources on the net (I can neither add external PPA or apt-get update after manually adding them, nor can't access to some download section of some applications, but still can install package by using apt-get install or pip).
  • Besides, my (above) PC have access to some of my company's servers via ssh connection. One of them (deliberately) has unrestricted Internet access (sounds weird, but that the way it is). I asked my boss if I can somehow can make my computer connect to the Internet without restriction through that server, and he told me that's possible but he doesn't know how to. And FYI, though he doesn't encourage me to do so, I'm not forbidden.

My question

Is there any way I can do what I've just describe? From my PC, access (unrestricted) to Internet via a remote server (with unrestricted Internet access)

What I've tried so far

Not much, actually, because I don't know how to search (hard to think of a keyword) for the problem. Most of the time I tried to config the proxy, so I can (partially) solve the problem (for PPA, I tried adding to source.list and add the sign, add proxy entries to /etc/apt/apt.conf, …). Still no candy for the baby. If anyone need to see the error, tell me, but I want to solve the problem completely 🙁

I'm grateful to any suggestion. Thanks in advance!

Best Answer

Try SSH tunneling/port forwarding. There is a lot of information in Internet. Read this: SSH/OpenSSH/PortForwarding and SSH tunneling with ubuntu.

I like to use SSH socks-proxy. Install plink:

sudo apt install plink

Run command in your local computer (SSH client) with restricted access to Internet:

plink -ssh -C -N -l user -D

where - IP-address of your remote SSH-server with unrestricted access and user - your SSH-server username.

Thats all. Now you have SOCKS proxy - all of the traffic through the proxy will be encrypted and routed through your remote SSH-server. Settings for the proxy are: host, port 8081.

Add this settings as Ubuntu system-wide proxy settings and instruct browsers, bash etc. to use system proxy. It's possible to add system proxy with Ubuntu System Settings GUI (mine has Ukrainian locale): enter image description here

If you want to use the proxy for apt, read Configure proxy for APT?, only take into account you have socks-proxy, thus the proxy URLs should be socks4:// or socks5:// instead of, for example:

export http_proxy="socks4://"
Related Question