143

I have started a Jupyter Notebook server on my centos6.5 server.And jupyter is running like

[I 17:40:59.649 NotebookApp] Serving notebooks from local directory: /root
[I 17:40:59.649 NotebookApp] 0 active kernels 
[I 17:40:59.649 NotebookApp] The Jupyter Notebook is running at:https://[all ip addresses on your system]:8045/
[I 17:40:59.649 NotebookApp] Use Control-C to stop this server and shut down all kernels (twice to skip confirmation).

When I want to access Jupyter remotely in the same local area network, say open http://192.168.1.111:8045/, I can't open a Jupyter page at all. By the way, I can access remote centos server successfully.

What's the possible reason?

CDspace
  • 2,639
  • 18
  • 30
  • 36
Peng He
  • 2,023
  • 5
  • 17
  • 24

20 Answers20

210

Have you configured the jupyter_notebook_config.py file to allow external connections?

By default, Jupyter Notebook only accepts connections from localhost (eg, from the same computer that its running on). By modifying the NotebookApp.allow_origin option from the default ' ' to '*', you allow Jupyter to be accessed externally.

c.NotebookApp.allow_origin = '*' #allow all origins

You'll also need to change the IPs that the notebook will listen on:

c.NotebookApp.ip = '0.0.0.0' # listen on all IPs

Make sure that you uncomment these settings (remove the # at the beginning) after making any modifications. If you don't, they'll be interpreted as comments, and they won't change the behavior of the Jupyter notebook client.

Also see the details in a subsequent answer in this thread.

Documentation on the Jupyter Notebook config file.

Nick ODell
  • 15,465
  • 3
  • 32
  • 66
James023
  • 2,116
  • 1
  • 8
  • 7
  • 45
    Using jupyter with `jupyter notebook --ip 0.0.0.0` you can decide on runtime with the same result, but without the need for a configuration file. – janniks Jan 05 '20 at 14:00
  • 2
    Any other additional idea? I tried literally every answer available on this question, and none of them worked for me. I've set the configs, allowed external accesses, allowed all IPs and origins... still getting a connection refused. I don't understand why does it have to be so hard. Using Windows really annoys me. – Lucas Lima Oct 04 '20 at 17:31
  • While above settings will work, strongly suggest to read notebook config documentation on setting up SSL, password and/or auth token. Exposing any server to all IPs without hardening local network is a considerable security risk. – Samir Dec 03 '21 at 16:36
  • By doing this, how can I access my jupyter notebook externally? Do I need to memorize the link for it? (The link anaconda prompt gives me when I type 'jupyter notebook'?) – Robin311 Apr 25 '22 at 13:37
  • This isn't solving a (seemingly similar) problem for me on ubuntu. I'm accessing the server via SSH port forwarding, so it should *look* like an access from localhost to the server anyway. I can tell that my remote connections *are* getting through, because the server prints `channel 3: open failed: connect failed: Connection refused` every time I try to load the page. – MRule Feb 02 '23 at 08:50
105

I managed to get the access my local server by ip using the command shown below:

jupyter notebook --ip xx.xx.xx.xx --port 8888

replace the xx.xx.xx.xx by your local ip of the jupyter server.

David Parks
  • 30,789
  • 47
  • 185
  • 328
Teo Kok Keong
  • 1,166
  • 1
  • 7
  • 3
  • 42
    I used `jupyter notebook --ip 0.0.0.0 --port 8888` – Talha Junaid Aug 10 '18 at 11:01
  • 2
    `0.0.0.0` will enable access to the notebook on all network interfaces, not just localhost. If you're running it and accessing it on the same machine, or you're running a server like nginx in front of it, you should limit it to `127.0.0.1` only – theferrit32 Jun 07 '19 at 21:53
  • Also if you are running on a cloud instance like EC2 then make sure you edit your security group to allow inbound traffic on port 8888. – Mad Scientist Jun 16 '19 at 06:57
  • @Teo Kok Keong: Where do you enter the command? In the Shell prompt? – MSIS Dec 11 '20 at 01:05
  • I got can't assign requested address – dorien Jun 16 '23 at 07:02
69

James023 already stated the correct answer. Just formatting it

if you have not configured jupyter_notebook_config.py file already

Step1: generate the file by typing this line in console

jupyter notebook --generate-config

Step2: edit the values

gedit  /home/koushik/.jupyter/jupyter_notebook_config.py

( add the following two line anywhere because the default values are commented anyway)

c.NotebookApp.allow_origin = '*' #allow all origins

c.NotebookApp.ip = '0.0.0.0' # listen on all IPs

Step3: once you closed the gedit, in case your port is blocked

sudo ufw allow 8888 # enable your tcp:8888 port, which is ur default jupyter port

Step4: set a password

jupyter notebook password # it will prompt for password

Step5: start jupyter

jupyter notebook

and connect like http://xxx.xxx.xxx.xxx:8888/login?

Koushik Paul
  • 995
  • 9
  • 13
  • 1
    One more thing. If you are still facing issues, before the `c.NotebookApp.allow_origin`, add `c=get_config()`. Also while opening the link in your personal computer, instead of using `https` use `http`. so it will open something like `http://external_ip_from_GCP_console:8888`. using `http` is important, its a small detail and easy to overlppk. Thanks @Koushik for compiling the answer. I upvoted your answer because it worked for me. – StatguyUser Aug 14 '19 at 06:53
  • where is the password stored? can't seem to find it in `jupyter_notebook_config.py` after setting the password at step 4 – liang Dec 07 '20 at 06:20
  • Works like a charm! Ubuntu 20.04 on a VirtualBox VM – Rodrigo Hjort Feb 11 '21 at 14:01
  • The solution works wonderful! Is it possible to make it autostart on boot? – Perino Mar 16 '21 at 16:57
30

In RedHat 7, we need to allow the specific port before running the Jupiter command. Say the port is 8080.

iptables -I INPUT 1 -p tcp --dport 8080 -j ACCEPT

Then we can run it normally. For instance, using:

jupyter notebook --ip 0.0.0.0 --no-browser --port=8080 --allow-root

or whatever you like.

ch271828n
  • 15,854
  • 5
  • 53
  • 88
Vikas Gupta
  • 1,293
  • 1
  • 15
  • 21
  • thanks, my system is Centos 7 but jupyter have problems to serve. first i have disabled firewall but still cannot serve but in especially applying second line ===> jupyter notebook --ip 0.0.0.0 --no-browser --port=8080 --allow-root solve the problem. it works now. – RedArrow Sep 03 '18 at 12:05
  • run notebook with specified `ip` and `port` is perfect – Wenmin Wu Mar 18 '19 at 06:21
  • This solved access problems with jupyterhub as well, for me. The standard port jupyterhub uses does not allow connections outside 127.0.0.1 – Eduardo Pignatelli Apr 17 '19 at 10:40
  • Works for ec2 instances as well. It's a bit confusing cause security group has that port allowed but server is not available till you run with these params. – Vadim Sep 29 '20 at 07:43
  • This solution worked for me using WSL2 - for some reason my browser would not run with just `jupyter notebook` and none of the other solutions helped – d-man Oct 31 '22 at 16:48
12

From your command line, we can see your jupyter server is running normally.The reason you can't access your remote jupyter server is that your remote centos6.5 server's firewall rules block the incoming request from your local browser,i.e. block your tcp:8045 port.
sudo ufw allow 80 # enable http server
sudo ufw allow 443 # enable https server
sudo ufw allow 8045 # enable your tcp:8045 port
then try to access your jupyter again.


Maybe you also need to uncomment and edit that place in your jupyter_notebook_config.py file:

c.NotebookApp.allow_remote_access = True

and even shut down your VPN if you have one.

Hu Xixi
  • 1,799
  • 2
  • 21
  • 29
12

Alternatively you can just create a tunnel to the server:

ssh -i <your_key> <user@server-instance> -L 8888:127.0.0.1:8888

Then just open 127.0.0.1:8888 in your browser.

You also omit the -i <your_key> if you don't have an identity_file.

Jordan
  • 1,375
  • 14
  • 17
  • 1
    In case one uses different ports, `8888:127.0.0.1:8888`, the first `8888` is the port on the local machine, the later one is the port on the remote machine. – fytao Mar 14 '20 at 19:56
  • this worked well, instead of login to the server and then trying to open a jupyter notebook. After entering this line of code, I simply typed "jupyter notebook" so the bash gave me the http to be copy/pasted on my server. – josepmaria Feb 11 '22 at 16:15
11

jupyter notebook --ip 0.0.0.0 --port 8888 will work.

ABCD
  • 7,914
  • 9
  • 54
  • 90
6

To begin with, if not available, create a config file first

jupyter notebook --generate-config

Then head over to the file and edit it

cd ~/.jupyter

Uncomment the three lines or delete all and add the three lines

c.NotebookApp.allow_origin = '*' #allow all origins
c.NotebookApp.ip = '0.0.0.0' # listen on all IPs
c.NotebookApp.allow_remote_access = True

Try to connect with remote IP. (If you are using AWS EC2, you'll need to whitelist your ip and enable inbound connections for your client pc or all IP address over the port 8888)

If you still can't connect, you can try

jupyter notebook --ip 0.0.0.0 --port 8888
Charith Jayasanka
  • 4,033
  • 31
  • 42
4

The other reason can be a firewall. We had same issue even with

jupyter notebook --ip xx.xx.xx.xxx --port xxxx.

Then it turns out to be a firewall on our new centOS7.

2

I'm using Anaconda3 on Windows 10. When you install it rembember to flag "add to Enviroment Variables".


Prerequisite: A notebook configuration file

Check to see if you have a notebook configuration file, jupyter_notebook_config.py. The default location for this file is your Jupyter folder located in your home directory:

  • Windows: C:\\Users\\USERNAME\\.jupyter\\jupyter_notebook_config.py
  • OS X: /Users/USERNAME/.jupyter/jupyter_notebook_config.py
  • Linux: /home/USERNAME/.jupyter/jupyter_notebook_config.py

If you don't already have a Jupyter folder, or if your Jupyter folder doesn't contain a notebook configuration file, run the following command:

$ jupyter notebook --generate-config

This command will create the Jupyter folder if necessary, and create notebook configuration file, jupyter_notebook_config.py, in this folder.


By default, Jupyter Notebook only accepts connections from localhost.

Edit the jupyter_notebook_config.py file as following to accept all incoming connections:

c.NotebookApp.allow_origin = '*' #allow all origins

You'll also need to change the IPs that the notebook will listen on:

c.NotebookApp.ip = '0.0.0.0' # listen on all IPs

madx
  • 6,723
  • 4
  • 55
  • 59
0

if you are using Conda environment, you should set up config file again. And file location will be something like this. I did not setup config file after I created env in Conda and that was my connection problem.

C:\Users\syurt\AppData\Local\Continuum\anaconda3\envs\myenv\share\jupyter\jupyter_notebook_config.py
scyrt
  • 326
  • 1
  • 2
  • 13
0

If you are still having trouble and you are running something like EC2 AWS instance, it may just be a case of opening the port through the AWS console.

see this answer

Isopycnal Oscillation
  • 3,234
  • 6
  • 21
  • 37
0

edit the following on jupyter_notebook_config file
enter actual computer IP address
c.NotebookApp.ip = '192.168.x.x'
c.NotebookApp.allow_origin = '*'

on the client side launch jupyter notebook with login password
jupyter notebook password

after setting password login on browser and then type the remote server ip address followed by the port. example 192.168.1.56:8889

chris mahn
  • 117
  • 1
  • 2
0

Try doing the below step:

The following command fixes the read/write

sudo chmod -R a+rw /home/ubuntu/certs/mycert.pem
upe
  • 1,862
  • 1
  • 19
  • 33
0

I faced a similar issue, and I solved that after doing the following:

  1. check your jupyter configuration file: this is described here in details; https://testnb.readthedocs.io/en/stable/examples/Notebook/Configuring%20the%20Notebook%20and%20Server.html

-- you will simply need from the link above to learn how to make jupyter server listens to your local machin IP -- you will need to know your local machin IP (i use "ifconfig -a" on ubuntu to find that out) - please check for centos6

after you finish setting your configuration, you can run jupyter notebook at your local IP: jupyter notebook --ip=* --no-browser

please replace * with your IP address for example: jupyter notebook --ip=192.168.x.x --no-browser

you can now access your jupyter server from any device connected to the router using this ip:port (the port is usually 8888, so for my case for instance I used "192.168.x.x:8888" to access my server from other devices)

now if you want to access this server from public IP, you will have to:

  1. find your public IP (simply type on google what is my IP)
  2. use this IP address instead of your local IP to access the server from any device not connected to the same router kindly note: if your linux server runs on Virtual machine, you will need to set your router to allow accessing your VB from public IPs, settings depends on the router type. otherwise, you should be able to access the server using the public IP and the port set for it from any device not connected to your router, or using your local IP and the port set from any device connected to the same router!
Waly
  • 157
  • 1
  • 4
  • 12
0

setting up a nohup jupyter notebook on a remote linux server using port 8888 as follows:

nohup jupyter notebook --no-browser --port 8888 &

will not work through multiple firewalls if using WSL2 (Debian/OpenSUSE or Ubuntu on Windows). The firewall will block the service at the jump to your remote server reporting a bind error on port 8888 when using:

ssh -N -L 8888:localhost:8888 remote-server-alias

I'm assuming a remote-server-alias is something that I have defined in my .ssh/config file using JumpProxy.

If you change port 8888 to 8889 you will see that jupyter can be loaded on all platforms including Windows 10. This is not an obvious gotcha and had me stumped for a whole day. Also needless to say, you must have an apache2 server up and running on the Windows machine.

So the magic is to always use:

 ssh -N -L 8889:localhost:8888 remote-server-alias
Eamonn Kenny
  • 1,926
  • 18
  • 20
  • Why would you need an apache2 server up and running on the Windows machine? And stepping back, what role is this Windows machine even playing? Are you using it as an example of a machine that will act as client to Jupyter on OP's remote Centos host? Or are you giving at as an example of an alternate server? Regardless, I'm mystified how apache fits in here. – gwideman Feb 13 '23 at 13:03
  • @gwideman its just an example of what you can do with a Windows machine when running jupyter on a remote host behind a firewall. This is a problem that many of us have on college servers, when our day-to-day computer needs to be windows and we want to have a linux development environment inside, and a remote cluster to run GPU based jobs. The tunnelling has been a lifesaver for many in our college. Gone are the day when we need to use paravirtualisation or dual booting. This gives you everything for development with really fast connections. – Eamonn Kenny Feb 14 '23 at 11:29
0

Just use:

jupyter lab --ip=0.0.0.0 --no-browser --allow-root &
Jon
  • 11
-1

Is that your private IP address? If so you'll need to use your public one. Go to ipchicken to find out what it is. I know you are in the same LAN, but try this to see if it resolves any issues.

-1

I got the same problem but none of workarounds above work for me. But if I setup a docker version jupyter notebook, with the same configuration, it works out for me.

For my stituation, it might be iptables rule issues. Sometimes you may just using ufw to allow all route to your server. But mine just iptables -F to clear all rule. Then check iptables -L -n to see if its works.

Problem fixed.

Diya Li
  • 1,048
  • 9
  • 21
-2

Anyone who is still stuck - follow the instructions on this page.

Basically:

  1. Follow the steps as initially described by AWS.

    1. Open SSH as normal.
    2. source activate python3
    3. Jupyter Notebook
  2. Don't cut and paste anything. Instead open a new terminal window without closing the first one.

  3. In the new window enter enter the SSH command as described in the above link.

  4. Open a web browser and go to http://127.0.0.1:8157

karel
  • 5,489
  • 46
  • 45
  • 50