0

Given a windows machine A and an linux machine B, I tried to implement this solution (also reading on this website) to access internet on B via A (machine A has internet access).

On the windows machine A, I opened a powershell and wrote

netsh winhttp set proxy 127.0.0.1:8000

On the linux machine B, I set inside the /etc/environment file

export http_proxy=http://127.0.0.1:7000
export https_proxy=http://127.0.0.1:7000

and then I sourced the variables with

source /etc/environment

Then, following the refered links, I did a remote port forwarding (as I understand it this means that everything happening on port 7000 of the linux machine B will be forwarded to port 8000 of the windows machine A), so I wrote this inside a terminal on the windows machine A:

ssh -R 7000:localhost:8000 user@hostB

Now I thought I was done. However when I tried this command from the linux machine B

wget http://google.com

I get

--2022-04-03 10:08:28--  http://google.com/
Resolving localhost (localhost)... 127.0.0.1, ::1
Connecting to localhost (localhost)|127.0.0.1|:7000... connected.
Proxy request sent, awaiting response... No data received.
Retrying.

--2022-04-03 10:08:31--  (try: 2)  http://google.com/
Connecting to localhost (localhost)|127.0.0.1|:7000... connected.
Proxy request sent, awaiting response... No data received.
Retrying.

--2022-04-03 10:08:35--  (try: 3)  http://google.com/
Connecting to localhost (localhost)|127.0.0.1|:7000... connected.
Proxy request sent, awaiting response... No data received.
Retrying.
...

I am total beginner so I appreciate if someone could explain me how to get this to work.

roi_saumon
  • 101
  • 2
  • After your first `netsh` do you not find that machine A has lost its access to the Internet? I believe this is an unnecessary and indeed incorrect step. – roaima Apr 04 '22 at 12:09
  • @roaima I still got access to internet on machine A after this step. I did this because in the first link it is mentioned that we also need a proxy on machine A. I thought this was to redirect the internet flow from machine A onto port 8000. However, if I skip the netsh step I get the same result – roi_saumon Apr 04 '22 at 12:13
  • Your netsh has only configured windows to access a proxy server on itself. I don't see any sign of a proxy server being installed or configured. Unless you are using windows server then I suspect you will struggle to accomplish what you want here. If you use the linux box as a router and set up NAT forwarding or run a proxy server such as squid on it, then I think your chances are much better – SEWTGIYWTKHNTDS Apr 04 '22 at 13:00
  • @SEWTGIYWTKHNTDS, okay I then installed squid proxy and configured its listening port to 8000, but still I have the same issue... – roi_saumon Apr 04 '22 at 14:20
  • OK so with squid running on windows you need to set up linux to access it. on linux box export http_proxy=http://WindowsIPAddress:8000 and export https_proxy=https://WindowsIPAddress:8000. Then your wget should contact the windows computer which is running squid and the web page should be retrieved by the proxy and returned you your linux box – SEWTGIYWTKHNTDS Apr 04 '22 at 15:07
  • @SEWTGIYWTKHNTDS, I exported the variables and now I get the same message but it takes more time (say 2 minutes) between each request `--2022-04-03 13:40:38-- http://google.com/ Connecting to ip.ip.ip.ip:8000... failed: Connection timed out. Retrying. --2022-04-03 13:42:47-- (try: 2) http://google.com/ Connecting to ip.ip.ip.ip:8000...`. But are you sure we have to export the ip of the windows machine on the linux machine? In the first link the export 127.0.0.1 – roi_saumon Apr 04 '22 at 15:19
  • Yes, 127.0.0.1 is the loopback interface of whichever computer you access it on, the linux and windows boxes need to talk to each other so you must use their real ip addresses. Check the squid logs and see if there are any messages. you can also check squid is functioning by setting the proxy settings and using a web browser to browse. – SEWTGIYWTKHNTDS Apr 04 '22 at 15:54
  • I tried some stuff but it wont work. I cannot even open google.com:8000 or google.com:3128 or anything else than google.com:80 because of some firewall settings I cannot change. However, I still didn't get why proxies are actually needed on machine A and B. It seems to me that if we have access on internet on A and a connection between A and B it would be enough no? – roi_saumon Apr 05 '22 at 21:14
  • I don't see why any proxies are required. It's you that involved then in the first place so we're trying to continue using them. If you don't need a proxy don't include it in the problem scenario – roaima Apr 07 '22 at 22:39
  • 1
    @roaima, I included them because it is the method I found and that is suggested in the first link. I didn't came up with this idea – roi_saumon Apr 08 '22 at 10:17
  • @SEWTGIYWTKHNTDS if you have an answer please write it as an answer. Even if you don't want the points it can be useful for future readers of this question – roaima Apr 13 '22 at 20:53

1 Answers1

0

If your applications on your Linux system can use SOCKS, you can use the SOCKS Proxy of ssh to faciliate the network connection

Windows:

ssh -D 1080 linuxServer    # add -fN to run in the background

You now have a SOCKS server listening on port 1080 on the linuxServer, routed via the ssh session back through your Windows client.

Linux:

You need to install a SOCKS Proxy such as tsocks or else use a SOCKS-aware application such as wget. Run these as root (use sudo -s to get a root shell):

apt install tsocks                                  # Install the tool
cp -p /etc/tsocks.conf /etc/tsocks.conf.ORIGINAL    # I like to save configuration files before changing them
echo server = 127.0.0.1 >/etc/tsocks.conf           # Minimal configuration

Now you can prefix your network command or application with tsocks to use the SOCKS proxy you created in the very first step:

tsocks wget https://bbc.co.uk/

Not all commands with work with tsocks. In particular ping cannot work and you'll receive the error, ERROR: ld.so: object 'libtsocks.so' from LD_PRELOAD cannot be preloaded (cannot open shared object file): ignored..

roaima
  • 107,089
  • 14
  • 139
  • 261