LoginSignup
103
91

More than 5 years have passed since last update.

jupyter notebook で外部からの接続を許可する

Last updated at Posted at 2017-03-13

VM 環境で jupyter を立ち上げた際、VM 側で jupyter 用のポートを localhost にフォワードするように設定していても接続を拒否されてしまう。
恐らく LISTEN が localhost とかになってるんやろな、ってのは想像ついたけど、調べてみるまで設定どうすればいいか全然分からなかったのでメモ。

まずは設定ファイルを作成する。

$ jupyter notebook --generate-config

デフォルトでは ~/.jupyter/ 内に jupyter_notebook_config.py というファイルが作成される。
このファイル内の下記あたりの行を編集。

## The IP address the notebook server will listen on.
c.NotebookApp.ip = 'localhost'

この localhost0.0.0.0 とか * とかに変えてやればおk。

## The IP address the notebook server will listen on.
c.NotebookApp.ip = '0.0.0.0'

これで VM の外からもアクセス出来るようになった。
ついでに書いとくと、Jupyter 起動時にいちいちブラウザが立ち上がるのがウザいって場合は

## Whether to open in a browser after starting. The specific browser used is
#  platform dependent and determined by the python standard library `webbrowser`
#  module, unless it is overridden using the --browser (NotebookApp.browser)
#  configuration option.
c.NotebookApp.open_browser = False

のように open_browser 値を False にしておけば、立ち上げ時に何も開かないようにできる。


追記

コメント欄で教えていただきましたが、アドホックにやりたかったら

$ jupyter notebook --ip=* --no-browser

で良いらしい。便利ですね。

103
91
3

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
103
91