简体   繁体   中英

How to set up port forwarding to access a website hosted on WSL through SSH and intranet penetration

Hi all, here is the premise of my question :

Our lab just bought a Windows workstation that comes with some softwares for the instruments we also bought. People are coming and going to use these softwares, but I also need to use it for some data analysis using R. Obviously the computer cannot be all mine to use, so I installed WSL 2 Ubuntu 20.04 on the computer hoping to run rstudio server on it and connect to the R session remotely and write my code.

The R studio server runs fine. I can start the server on WSL, open a localhost:8787 webpage in Windows, and R studio is there.

Then I needed to figure out how to connect WSL to my own laptop. Following this tutorial , I first SSH to the workstation with Windows SSH and use bash as my default shell. This will automatically launch WSL on the workstation for me to use.

Also, the workstation and my laptop are not in the same network, so I used ngrok to expose the workstation's port 22 for the SSH to go through. I would run ngrok tcp 22 in the workstation's cmd, and this connects port 22 to a public ip such as 0.tcp.ngrok.io:11111. Then from my laptop I run ssh -p 11111 username@0.tcp.ngrok.io to access WSL on the workstation.

So far so good. I can connect to the workstation from my laptop and run R on the commandline. The thing is I have no idea how to open the rstudio server webpage on my laptop. I read about port forwarding and tried ssh -L 8787:localhost:8787 -p 11111 username@0.tcp.ngrok.io but when I tried to open localhost:8787 on my laptop, it said no data sent from localhost:8787 (or something similar along the line). I searched for solutions and made changes on the WSL side according to this tutorial . After changing, the website is still not working. I also tried setting up a firewall rule on my laptop as netsh advfirewall firewall add rule name=”Rstudio Server” dir=in action=allow protocol=TCP localport=8787 and it does not work neither.

So my question is :

How should I set this up properly as there are too many ports going on here: my computer's 8787 port, ngrok's 11111 port, Workstation Windows' 22 port, whatever port that is working with Windows on WSL, and rstudio server's 8787 port.

I found the answer to my question today, hooray. It seems my intuition about too many ports being there isn't entirely wrong. After setting the host name of WSL to another name from localhost following this tutorial and changed nothing else, my laptop knows which website it is supposed to open. So now I can open localhost:8787 on my laptop and use R studio remotely, finally!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM