64

I am trying to run an ipython notebook / jupyter server on a machine behind a firewall. The only port which is open is port 80. So was wondering how I can change the default port from 8890 to 80?

I have ran the following command ipython profile create to create a profile.

Then edited ipython_notebook_config.py and edited it to contain the following:

c = get_config()
c.NotebookApp.port = 80

When I try to run python notebook. I get the following error:

ERROR: the notebook server could not be started because no available port could be found.


Hoever, nothing else seems to be using port 80. Apache does not boot at startup and is disabled. I have even used netstat to see what is using each port.

$ sudo netstat -lnp
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address           Foreign Address                 State       PID/Program name
tcp        0      0 0.0.0.0:21              0.0.0.0:*               LISTEN      1226/vsftpd     
tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN      1532/sshd       
tcp        0      0 127.0.0.1:631           0.0.0.0:*               LISTEN      3433/cupsd      
tcp        0      0 127.0.0.1:5984          0.0.0.0:*               LISTEN      1410/beam.smp   
tcp        0      0 127.0.0.1:3306          0.0.0.0:*               LISTEN      1653/mysqld     
tcp6       0      0 :::22                   :::*                    LISTEN      1532/sshd       
tcp6       0      0 ::1:631                 :::*                    LISTEN      3433/cupsd      
udp        0      0 0.0.0.0:52741           0.0.0.0:*                           796/avahi-daemon: r
udp        0      0 0.0.0.0:5353            0.0.0.0:*                           796/avahi-daemon: r
udp        0      0 0.0.0.0:31114           0.0.0.0:*                           1105/dhclient   
udp        0      0 0.0.0.0:68              0.0.0.0:*                           1105/dhclient   
udp        0      0 xxx.xxx.xxx.xxx:123        0.0.0.0:*                           2607/ntpd       
udp        0      0 127.0.0.1:123           0.0.0.0:*                           2607/ntpd       
udp        0      0 0.0.0.0:123             0.0.0.0:*                           2607/ntpd       
udp        0      0 0.0.0.0:631             0.0.0.0:*                           1630/cups-browsed
udp6       0      0 :::5353                 :::*                                796/avahi-daemon: r
udp6       0      0 :::69                   :::*                                1607/in.tftpd   
udp6       0      0 :::24682                :::*                                1105/dhclient   
udp6       0      0 xxxx::xxxx:xxxx:xxxx:123 :::*                                2607/ntpd       
udp6       0      0 ::1:123                 :::*                                2607/ntpd       
udp6       0      0 :::123                  :::*                                2607/ntpd       
udp6       0      0 :::59559                :::*                                796/avahi-daemon: r
Active UNIX domain sockets (only servers)
Proto RefCnt Flags       Type       State         I-Node   PID/Program name    Path
unix  2      [ ACC ]     STREAM     LISTENING     20483    3253/pulseaudio     /run/user/1003/pulse/native
unix  2      [ ACC ]     STREAM     LISTENING     18697    3179/gnome-session  @/tmp/.ICE-unix/3179
unix  2      [ ACC ]     STREAM     LISTENING     15765    2507/X              /tmp/.X11-unix/X0
unix  2      [ ACC ]     STREAM     LISTENING     20481    3253/pulseaudio     /tmp/.esd-1003/socket
unix  2      [ ACC ]     STREAM     LISTENING     18698    3179/gnome-session  /tmp/.ICE-unix/3179
unix  2      [ ACC ]     STREAM     LISTENING     15764    2507/X              @/tmp/.X11-unix/X0
unix  2      [ ACC ]     STREAM     LISTENING     10538    768/bluetoothd      /var/run/sdp
unix  2      [ ACC ]     STREAM     LISTENING     21564    3433/cupsd          /var/run/cups/cups.sock
unix  2      [ ACC ]     STREAM     LISTENING     10820    1653/mysqld         /var/run/mysqld/mysqld.sock
unix  2      [ ACC ]     STREAM     LISTENING     16666    3184/dbus-daemon    @/tmp/dbus-1gowauBlhV
unix  2      [ ACC ]     STREAM     LISTENING     14432    748/dbus-daemon     /var/run/dbus/system_bus_socket
unix  2      [ ACC ]     STREAM     LISTENING     8877     1/init              @/com/ubuntu/upstart
unix  2      [ ACC ]     STREAM     LISTENING     16698    3136/ibus-daemon    @/tmp/dbus-ue1VKkXx
unix  2      [ ACC ]     STREAM     LISTENING     12135    3005/gnome-keyring- /run/user/1003/keyring-htUkSg/control
unix  2      [ ACC ]     STREAM     LISTENING     14469    796/avahi-daemon: r /var/run/avahi-daemon/socket
unix  2      [ ACC ]     STREAM     LISTENING     10034    3102/dbus-daemon    @/tmp/dbus-SCYaEa0Hje
unix  2      [ ACC ]     STREAM     LISTENING     18577    3005/gnome-keyring- /run/user/1003/keyring-htUkSg/pkcs11
unix  2      [ ACC ]     STREAM     LISTENING     18581    3005/gnome-keyring- /run/user/1003/keyring-htUkSg/gpg
unix  2      [ ACC ]     STREAM     LISTENING     18583    3005/gnome-keyring- /run/user/1003/keyring-htUkSg/ssh
unix  2      [ ACC ]     STREAM     LISTENING     18569    3007/init           @/com/ubuntu/upstart-session/1003/3007
unix  2      [ ACC ]     SEQPACKET  LISTENING     11473    396/systemd-udevd   /run/udev/control
unix  2      [ ACC ]     STREAM     LISTENING     10725    1572/acpid          /var/run/acpid.socket

7 Answers 7

96
jupyter notebook --ip=0.0.0.0 --port=80 or
ipython notebook --ip=0.0.0.0 --port=80

is what i did to run ipython in my vagrant box. (Opened up the ports on the vagrant box to access it on my host mac)

usage: ipython [-h] [--certfile NOTEBOOKAPP.CERTFILE] [--ip NOTEBOOKAPP.IP]
               [--pylab [NOTEBOOKAPP.PYLAB]]
               [--log-level NOTEBOOKAPP.LOG_LEVEL]
               [--port-retries NOTEBOOKAPP.PORT_RETRIES]
               [--notebook-dir NOTEBOOKAPP.NOTEBOOK_DIR]
               [--config NOTEBOOKAPP.CONFIG_FILE]
               [--keyfile NOTEBOOKAPP.KEYFILE] [--port NOTEBOOKAPP.PORT]
               [--transport KERNELMANAGER.TRANSPORT]
               [--browser NOTEBOOKAPP.BROWSER] [--script] [-y] [--no-browser]
               [--debug] [--no-mathjax] [--no-script] [--generate-config]

Incase the port is already occupied, see what's blocking it - inmy case it was an old instance of ipython which had not been terminated properly. I kiiled them all with this command

ps auxww | grep 'ipython' | awk '{print $2}' | xargs sudo kill -9
1
  • 3
    Thanks! The same works for jupyterlab as well! jupyter lab --port 8889
    – gneusch
    Oct 13, 2020 at 15:12
44

To change port temporarily, indicate a different port number when we start jupyter notebook server from a terminal by firing following command.

jupyter notebook --port 9999

Read more https://jupyter.readthedocs.io/en/latest/running.html

3
  • Please make it more clear. Your answer is vague now. Dec 12, 2017 at 4:26
  • While this link may answer the question, it is better to include the essential parts of the answer here and provide the link for reference. Link-only answers can become invalid if the linked page changes
    – Ram Koti
    Dec 12, 2017 at 4:43
  • 2
    I disagree with @Billa. I think this is the best answer. It is simplistic and it works. Nov 12, 2018 at 9:13
15

In Jupyter we can start the notebook on different port by two ways.

  1. Temporary port - By mentioning the port in args like below command we can run Jupyter on that port. But we have to mention the port in the command argument whenever we need to run Jupyter in a different port.
jupyter notebook --port 9999
  1. Permanent port Configuration - By changing the configuration we can run Jupyter on different port on the machine permanently. Please follow the below steps for that.

    • Open the configuration file in nano

    nano ~/.jupyter/jupyter_notebook_config.py

    • Change the port by changing the value of the below configuration

    c.NotebookApp.port = 9999

    • start the notebook by

    jupyter notebook

Bingo!!!

8

Something is already listening on 80, you cannot bind 2 servers to the same port. Use a proxy that listen to 80, and redirect to your other servers and IPython base on URL, or address. Also don't use 80, use 443, if you are running a public server it should be over TLS for security.

Note that for any low port number you might need to increase the process privileges to root, potentially using sudo.

4
  • 1
    As far as I know no other process is using port 80. Unfortunately I don't have a say in what ports numbers are accessible outside of my organisation. To be honest the actual number is arbitrary, but is setting up a proxy really the best way?
    – jonhurlock
    Jul 7, 2015 at 14:38
  • 2
    Are you running as root ? you won't be able to bind to lower port without enough privileges.
    – Matt
    Jul 7, 2015 at 19:15
  • 2
    It was because it was a lower port, so I had to sudo the command to start the server sudo ipython notebook --profile=nbserver / sudo ipython notebook --port 80. Cheers @matt
    – jonhurlock
    Jul 7, 2015 at 22:55
  • 1
    This is the right answer. Port 80 is special, and there is a good reason why applications make it hard to access it (e.g. it's a security thing). Please never run publicly accessible things as Sudo user. Set up Apache (or nginx, or whatever), set the proxy settings to forward to port 8888. Done and secure. If you add other apps on that server, Apache can handle them all.
    – hendrixski
    May 20, 2016 at 21:21
1

In some cases port is picked up by environment variable (like in docker images). You can update this variable. I guess this should work in all cases:

# Export
export JUPYTER_PORT=80

# Start the notebook
jupyter notebook
0

Just FYI, running in a Docker container and changing the config to use port 80:

c.NotebookApp.port = 80

Causes these errors in turn:

[W 18:11:42.852 NotebookApp] Permission to listen on port 80 denied.
[W 18:11:42.853 NotebookApp] Permission to listen on port 81 denied.
[W 18:11:42.854 NotebookApp] Permission to listen on port 82 denied.
[W 18:11:42.855 NotebookApp] Permission to listen on port 83 denied.
[W 18:11:42.856 NotebookApp] Permission to listen on port 84 denied.
[W 18:11:42.857 NotebookApp] Permission to listen on port 49 denied.
[W 18:11:42.857 NotebookApp] Permission to listen on port 24 denied.
[W 18:11:42.858 NotebookApp] Permission to listen on port 114 denied.
[W 18:11:42.859 NotebookApp] Permission to listen on port 58 denied.
[W 18:11:42.860 NotebookApp] Permission to listen on port 81 denied.
[W 18:11:42.860 NotebookApp] Permission to listen on port 153 denied.
[W 18:11:42.861 NotebookApp] Permission to listen on port 66 denied.
[W 18:11:42.862 NotebookApp] Permission to listen on port 60 denied.
[W 18:11:42.862 NotebookApp] Permission to listen on port 73 denied.
[W 18:11:42.863 NotebookApp] Permission to listen on port 103 denied.
[W 18:11:42.863 NotebookApp] Permission to listen on port 123 denied.
[W 18:11:42.864 NotebookApp] Permission to listen on port 131 denied.
[W 18:11:42.864 NotebookApp] Permission to listen on port 123 denied.
[W 18:11:42.865 NotebookApp] Permission to listen on port 21 denied.
[W 18:11:42.865 NotebookApp] Permission to listen on port 66 denied.
[W 18:11:42.866 NotebookApp] Permission to listen on port 156 denied.
[W 18:11:42.867 NotebookApp] Permission to listen on port 107 denied.
[W 18:11:42.867 NotebookApp] Permission to listen on port 1 denied.
[W 18:11:42.868 NotebookApp] Permission to listen on port 140 denied.
[W 18:11:42.869 NotebookApp] Permission to listen on port 54 denied.
[W 18:11:42.869 NotebookApp] Permission to listen on port 81 denied.
[W 18:11:42.869 NotebookApp] Permission to listen on port 134 denied.
[W 18:11:42.870 NotebookApp] Permission to listen on port 148 denied.
[W 18:11:42.871 NotebookApp] Permission to listen on port 27 denied.
[W 18:11:42.871 NotebookApp] Permission to listen on port 1 denied.
[W 18:11:42.872 NotebookApp] Permission to listen on port 137 denied.
[W 18:11:42.873 NotebookApp] Permission to listen on port 33 denied.
[W 18:11:42.874 NotebookApp] Permission to listen on port 163 denied.
[W 18:11:42.875 NotebookApp] Permission to listen on port 1 denied.
[W 18:11:42.876 NotebookApp] Permission to listen on port 59 denied.
[W 18:11:42.877 NotebookApp] Permission to listen on port 34 denied.
[W 18:11:42.878 NotebookApp] Permission to listen on port 74 denied.
[W 18:11:42.879 NotebookApp] Permission to listen on port 126 denied.
[W 18:11:42.880 NotebookApp] Permission to listen on port 92 denied.
[W 18:11:42.880 NotebookApp] Permission to listen on port 161 denied.
[W 18:11:42.881 NotebookApp] Permission to listen on port 1 denied.
[W 18:11:42.882 NotebookApp] Permission to listen on port 124 denied.
[W 18:11:42.883 NotebookApp] Permission to listen on port 146 denied.
[W 18:11:42.883 NotebookApp] Permission to listen on port 1 denied.
[W 18:11:42.884 NotebookApp] Permission to listen on port 155 denied.
[W 18:11:42.884 NotebookApp] Permission to listen on port 57 denied.
[W 18:11:42.885 NotebookApp] Permission to listen on port 1 denied.
[W 18:11:42.886 NotebookApp] Permission to listen on port 1 denied.
[W 18:11:42.887 NotebookApp] Permission to listen on port 139 denied.
[W 18:11:42.887 NotebookApp] Permission to listen on port 68 denied.
[W 18:11:42.887 NotebookApp] Permission to listen on port 14 denied.
-1

jupyter notebook --port 3 [ or any port range 0 to 65353 you like which can not conflict with any running application current time.

1
  • 2
    Hi, welcome to Stack Overflow, thank you for answer. Is your answer contributing new information to the post? This post is 6 years old, and it is recommended to post an answer only if you have something new and relevant to add.
    – pyeR_biz
    Jul 30, 2021 at 13:19

Your Answer

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

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