How to access internet and run apt-get through a middle server?

I have a machine running ubuntu 16.04. The machine can only access 1 remote server (also running ubuntu). The remote server has full access to internet though.

root@localmachine:~# ifconfig usb0
usb0      Link encap:Ethernet  HWaddr 02:1e:10:1f:00:00  
          inet addr:10.1.0.94  Bcast:10.1.0.95  Mask:255.255.255.252
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:4366027 errors:0 dropped:0 overruns:0 frame:0
          TX packets:1813925 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:669835698 (669.8 MB)  TX bytes:265999026 (265.9 MB)

root@localmachine:~# ping 10.0.0.1
PING 10.0.0.1 (10.0.0.1) 56(84) bytes of data.
64 bytes from 10.0.0.1: icmp_seq=1 ttl=62 time=58.4 ms
64 bytes from 10.0.0.1: icmp_seq=2 ttl=62 time=59.2 ms

I need to install some package on this local machine via apt-get.

Is there a way to access internet throught the public server at 10.0.0.1 ?

Thank you for your reply.


Solution 1:

Open a terminal and start ssh dynamic port forwarding:

ssh -D 1080 [email protected]

This will start a socks proxy on your computer on port 1080.

Add this line to your /etc/apt/apt.conf file:

Acquire::socks::Proxy "socks5h://localhost:1080";

Then you can run your apt update / apt install commands. When you're done, you can close the ssh connection and revert the changes in apt.conf.

You can also tell your Browser or other applications to use that Socks proxy and access the Internet.

Solution 2:

The easiest way would be that you set up a proxy server on the middle server/gateway and set up your apt to use this proxy:

sudo vi /etc/apt/apt.conf.d/proxy.conf

And add this line:

Acquire::http::Proxy "http://user:[email protected]:port/";