158

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?

22 Answers 22

222

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.

6
  • 63
    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
    Commented Jan 5, 2020 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
    Commented Oct 4, 2020 at 17:31
  • 1
    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
    Commented Dec 3, 2021 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
    Commented Apr 25, 2022 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
    Commented Feb 2, 2023 at 8:50
126

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.

6
  • 48
    I used jupyter notebook --ip 0.0.0.0 --port 8888 Commented Aug 10, 2018 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 Commented Jun 7, 2019 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. Commented Jun 16, 2019 at 6:57
  • @Teo Kok Keong: Where do you enter the command? In the Shell prompt?
    – MSIS
    Commented Dec 11, 2020 at 1:05
  • I got can't assign requested address
    – dorien
    Commented Jun 16, 2023 at 7:02
71

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?

5
  • 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. Commented Aug 14, 2019 at 6: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
    Commented Dec 7, 2020 at 6:20
  • Works like a charm! Ubuntu 20.04 on a VirtualBox VM Commented Feb 11, 2021 at 14:01
  • The solution works wonderful! Is it possible to make it autostart on boot?
    – Perino
    Commented Mar 16, 2021 at 16:57
  • the ufw command will only work if that particular firewall application is installed. most users will not have ufw installed, so may need to do something else to configure their firewall. Most distributions by default probably don't need any additional configuration. Commented Sep 9, 2023 at 12:04
31

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.

6
  • 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
    Commented Sep 3, 2018 at 12:05
  • run notebook with specified ip and port is perfect
    – Wenmin Wu
    Commented Mar 18, 2019 at 6: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 Commented Apr 17, 2019 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
    Commented Sep 29, 2020 at 7: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
    Commented Oct 31, 2022 at 16:48
14

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.

2
  • 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
    Commented Mar 14, 2020 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
    Commented Feb 11, 2022 at 16:15
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.

11

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

9

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
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

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
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

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

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!
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
2
  • 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
    Commented Feb 13, 2023 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. Commented Feb 14, 2023 at 11:29
0

Try doing the below step:

The following command fixes the read/write

sudo chmod -R a+rw /home/ubuntu/certs/mycert.pem
0

Just use:

jupyter lab --ip=0.0.0.0 --no-browser --allow-root &
0

This command worked for me -

jupyter lab --ip 0.0.0.0 --port 8888

0

for example your computer's name is FEX-ple, your jupyter need run like

Use Control-C to stop this server and shut down all kernels (twice to

To access the server, open this file in a browser:
    file:///home/*******/.local/share/jupyter/runtime/jpserver-543245-open.html
Or copy and paste one of these URLs:
    http://FEX-ple:8888/tree?token=3445210404556345040gfhnsvsacasc404a8539cca455517
    http://127.0.0.1:8888/tree?token=3445210404556345040gfhnsvsacasc404a8539cca455517

with jupyter notebook --ip 0.0.0.0

then you access from ur browser with http://192.168.1.111:8888/tree?token=3445210404556345040gfhnsvsacasc404a8539cca455517

there should be no error

-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.

-3

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.