Sunday, June 26, 2016

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

1)
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 10.140.15.64 --dport 8085 -j DNAT --to-destination 192.168.56.20:8083
$ sudo iptables -t nat -A POSTROUTING -j MASQUERADE


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

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

3)
Access shared directory from your laptop
http://10.140.15.64:8083




1 comment: