Ipython remote kernel trials

From wikinotes


A series of unsuccessful attempts to connect an ipython kernel with a remote host (and why they did not succeed).

NOTE:


Strangely, nc -z 127.0.0.1 54925 on windows reported that the port was open but would not report the port as being open under linux. (even when linux was hosting the ipython kernel) Good to know when troubleshooting!


Attempt 1 (failed)

Changing the address IPython listens on to the real IP addr.

NOTE:

this might be worth trying again using a BRIDGED VM network connection instead of NAT. (that way the guest will actually be able to ping the guest).

## Host (windows)
ipython2 kernel --ip="192.168.1.219"

## Guest (Linux VirtualMachine)
ipython2 console --ip="192.168.1.219"


## IPython issues a message saying that it does not support binding to
## an interface that is not: 0.0.0.0, 10.0.0.*, or 127.0.0.1
##

Attempt 2 (successful)

This method requires an ssh server to be running on the windows machine. It forwards just the configured ports to the remote-machine using SSH.

The reason I thought this was failed before, was because I failed to copy the kernel.json file to the correct location (thinking that ipython2 console would read the local file.).


## Host (windows)
ipython2 kernel -f kernel.json			## reuse existing config (no need to parse)


## Guest (Linux VirtualMachine)
ssh -p 8610 -L 127.0.0.1:55534:127.0.0.1:55534 -N -f will@wintermute		## forward port 55534 on wintermute to localport 55534
																								## (do this for all ports in config)

cp kernel.json     /home/vagrant/.local/share/jupyter/runtime/kernel.json	## copy the windows kernel.json file to the linux machine
jupyter console --existing kernel.json

Attempt 3 (failed)

Using Vagrant/Virtualbox to forward a significant portion of the port-range to the VirtualMachine. That way, localhost can be used, to ipython, you're still using the loopback address.

  • CON: it takes MUCH longer to boot vagrant. Keep that range as small as you can!
  • CON: the limited port-range means this may not work 100% of the time. Especially if ports are consumed and discarded like they are with HTTP connections


WARNING:

this is both time consuming, and impossible. you cannot forward ports on the loopback address to another host.

Also, after attempting this, I noticed that the docs I found on forwarding ports using SSH were a part of the official documentation. That means that it really should only be using those ports.

for port in 51000..52000
	config.vm.network :forwarded_port, guest: port, host: port
end

Attempt 4 (failed)

Use vagrant to forward the required ports on the hosts's localhost to the guest's localhost.

## Vagrantfile

for port in [54925,54928,54939,54922,54931]
	config.vm.network :forwarded_port, 
		guest_ip: "127.0.0.1", guest: port,
		host_ip:  "127.0.0.1", host:  port
end

NOTE:

vagrant does not allow you to bind a port that is currently in use, for this to (theoretically) work, you'll need to start the vagrant VM first, then start the ipython kernel


WARNING:

this is impossible. you CANNOT forward a port on 127.0.0.1 to any other machine. period. See:

https://www.virtualbox.org/ticket/13971