torsdag den 14. januar 2016

Using Ipython Notebooks on external servers when behind restrictive firewalls

I recently held an introduction to Python for a group of colleagues (LINK), which was quite well received.
However, in testing out the setup (IPython notebooks running on a server in the cloud), I had trouble connecting to the server. This was because IPython notebooks use the nonstandard port 8080 for serving notebook traffic, and this port, along with all other ports outside the standard range, is blocked by the university's network.

Since the external server also runs an Apache web server, starting the notebook service with -port 80 gave an error. Rather than uninstall the web server with all the headaches that follow, I found a simple solution on Stackoverflow. (I've unfortunately lost the original source)

As root, run the command:
$ iptables -t nat -A PREROUTING -p tcp --dport 80 -j REDIRECT --to 8080

This redirects all incoming traffic on port 80 (the standard for http traffic) to port 8080 (on which the ipython server resides), and allows users to connect via the IP directly.

When the session was over, I simply restarted the web server to remove the redirection.