Reference Chunks

Programming and data notes

Forward Flask Server Through NAT Virtualbox Guest

if you’ve setup port forwarding but you cannot see the content that the flask server is supposedly serving on port 5000, even though ports like 80 or 22 are working it might be because (as outlined in the docs) flask, by default, serves only on the localhost.

Check that ports are set up

Make sure that you’ve set up the portforwarding appropriately on the host…

1
VBoxManage.exe modifyvm "VMnameInQuotes" --natpf1 "guestFlask,tcp,,5555,,5000"

Check the ports on the guest Check…

1
netstat -nao

or…

1
netstat -nao | grep 5000

While the server is running and you should see a line like this…

1
tcp        0      0 127.0.0.1:5000          0.0.0.0:*               LISTEN      off (0.00/0/0)

Change the flask files

To be able to load the app on that port in your host machine…

Stop the server with Ctrl-C.

then change your

1
app.run()

to

1
app.run(host="0.0.0.0")

and restart the server

netstat should now show

1
tcp        0      0 0.0.0.0:5000            0.0.0.0:*               LISTEN      off (0.00/0/0)

and you should be able to access the guest server from the host using localhost:5555 (or whatever other port you forwarded it to)

References https://groups.google.com/forum/?fromgroups#!topic/utahpython/RFFdwBVKWz0 http://flask.pocoo.org/docs/quickstart/#a-minimal-application