As a web developer, what is the most efficient (automated) way to connect to a virtual machine (VM) running a development webserver from its host machine (the machine running the VM) when you do not have control over the networks (home, Starbucks, work, etc) you are connected to?
Currently I start my VM (a VirtualBox VM running CentOS), run
ifconfig to determine the VM’s current IP. I then take that IP and map it to my Host machine’s host file so that I can access the VM’s webserver from the Host.
I feel that this is not an efficient way to connect to my VM’s webserver because each time I connect to a new network (a few times a day) I need to repeat the IP lookup and host file update, and sometimes restart the VM's network service.