Custom Search

Sunday, June 26, 2016

How to share file and directory from vagrant VM using port forwarding and python SimpleHTTPServer

Run following commands in baremetal node when vagrant VMs are running
$ sudo sysctl net.ipv4.ip_forward=1
$ sudo iptables -t nat -L
$ sudo iptables -t nat -A PREROUTING -p tcp -d --dport 8085 -j DNAT --to-destination
$ sudo iptables -t nat -A POSTROUTING -j MASQUERADE

* Replace -A with -D to delete the rule.
* Run this commands in baremetal node "".
* === IP of baremetal node where vagrant with virtualbox is running.
* === Hostonly adapter IP of virtualbox VM running on baremetal node

Run python SimpleHTTPServer from the directory which you want to share.
Run this command in your vagrant VM.
$ sudo python -m SimpleHTTPServer 8085

Access shared directory from your laptop