Reputation: 187
So I'm trying to connect to my jupyter notebook from a remote pc, since my own pc doesn't have a global IP I have to first connect to another pc in the local network(server 1) and then ssh to my own pc with jupyter running on it(server 2) so its something like this:
my laptop -> server 1 -> server 2
I used to do this when both servers were Linux like this:
On my laptop:
ssh -NL 2323:localhost:2323 server1_username@golbalIp
On server 1:
ssh -NL localhost:2323:localhost:8888 server2_username@localip
On server 2:
python3 -m jupyterlab --NotebookApp.token='' --NotebookApp.password='' --port 8888
but now my server 2 is a windows pc and my jupyter is on wls2, so I figured since on windows' localhost:8888 runs wsl2's jupyter then doing the same thing would work but it doesn't, How can I fix this?
Upvotes: 2
Views: 2586
Reputation: 187
I found out why my initial attempt did not work, So, wsl has its own local IP which usually changes every time you start it. I tried to make it a static IP but even editing the config files didn't work so instead we just have to check the IP and the port every time you start jupyter on Server 2
On server 2:
python3 -m jupyterlab --NotebookApp.token='' --NotebookApp.password='' \
--ip $(python3 -c "import subprocess; subprocess>
the you will get an output like this
[I 2022-05-17 12:25:06.476 ServerApp] nbclassic | extension was successfully loaded.
[I 2022-05-17 12:25:06.476 ServerApp] Serving notebooks from local directory: /mnt/d
[I 2022-05-17 12:25:06.476 ServerApp] Jupyter Server 1.4.1 is running at:
[I 2022-05-17 12:25:06.476 ServerApp] http://172.28.20.187:8888/lab
[I 2022-05-17 12:25:06.476 ServerApp] or http://127.0.0.1:8888/lab
[I 2022-05-17 12:25:06.476 ServerApp] Use Control-C to stop this server and shut down all kernels (twice to skip confirmation).
So 172.28.20.187:8888
is the IP and the Port used by Jupyter which changes every time. every other step is the same.
On server 1: ssh -NL localhost:<SOME_PORT_U_LIKE, ex:2323>:<IP, ex:172.28.20.187>:<PORT, usually:8888> server2_username@localip
On my laptop: ssh -NL <SOME_PORT_U_LIKE, ex:2323>:localhost:<SOME_PORT_U_LIKE, ex:2323> server1_username@golbalIp
also to avoid finding a the port every time I forwarded my wsl 8888 port to some other port on my windows so now If I ssh to that port on my windows I can directly connect to my jupyter notebook.
I first allow the port 2322 through windows firewall and after that enabled ssh on my wsl and run this commands every time I restart my pc:
@echo off
setlocal
C:\Windows\System32\bash.exe -c "sudo /usr/sbin/service ssh start"
C:\Windows\System32\netsh.exe interface portproxy delete v4tov4 listenport=2322 listenaddress=0.0.0.0 protocol=tcp
for /f %%i in ('wsl hostname -I') do set IP=%%i
C:\Windows\System32\netsh.exe interface portproxy add v4tov4 listenport=2322 listenaddress=0.0.0.0 connectport=2322 connectaddress=%IP%
endlocal
Upvotes: 1
Reputation: 2062
Its not at all obvious, but the solution is that Windows 10 does not like port 8888 and requires you to use 8889 to get the port forwarding to work on WSL2. Took me a long time to work this out. Under native linux there is no issue at all with port, unless the remote host has specific customised firewall rules.
So you must use:
ssh -NL 8889:localhost:8888 remote-server-alias
where remote-server-alias is something you have defined in your .ssh/config with JumpProxy and you must also have your apache2 server running on your Debian on Windows (WSL2) installation (for example). Check localhost in a browser first to ensure that the apache server is running correctly.
Before you begin you must do the following:
ssh remote-server-alias
nohup jupyter notebook --no-browser --port 8888 &
The token will be stored for you in nohup.out.
Upvotes: 0