There are a few things that can cause problems accessing your virtual machine fully from your host machine. Lots of cases work straight away, but some may come about from mucking with settings your first time out, or from importing the virtual appliance from another machine. The following are the key sources for the causes of connectivity problems.
- Virtual Machine
- Hosts file
Here are some troubleshooting notes that cover most of the problems that I have encountered since I have learned how to set up virtual machines for website development. The following are still loose notes cleaned up from my own local notes file.
Don’t be above rebooting your router if you have a problem. See if it works after that on the same settings you are on, especially if the virtual machine and host interaction works as you expect it to work. If you are in a web cafe, and you cant get it to work, use your mobile phone as a wireless access point. It will likely be more stable than most web cafes out there.
In the hypervisor
Moving a vm over to a new host machine? Turn off appliance, turn off network>enable network adapter, exit virtual box, restart virtual box, re-enable same adapter, boot up vm.
When moving over to my macbook pro, I had to change the name of my bridged adapter to en1. ( how would I find that out?) I also had to change Advanced > Adapter type to Intel PRO/1000 MT Desktop (82540EM). So be aware of your adapter type.
How I usually operate is this way:
I have an internet connection, even if it is only provided by my mobile phone. Mobile phones are very handy for this purpose.
With your virtual appliance turned OFF:
- Select the virtual machine > Settings > Network > adapter 1
- If this is a virtual appliance you have
- Check enable network adapter. Toggle and close and reopen settings if this is an imported VM.
- Attached to: Bridged Adapter.
- Name: Your Ethernet connection, basically. On my Mac it says en1: Wi-Fi (AirPort)
- Advanced: Cable Connected is CHECKED.
In the Linux virtual machine
Find eth0. I want to see my IP addy in my ifconfig like I do in ipconfig in my win7 host.
ifconfig or ifconfig –a
to see what is up in the terminal window.
Ideally you should be seeing eth0 and a normal looking IP. Something like 192.168.1.80.
Sometimes, eth0 disappears. Are you on NAT? Try bridged.
Try restarting the network interface. Release dhcp…
- sudo ifconfig eth0 down
- sudo ifconfig eth0 up
- sudo dhclient eth0
- sudo dhclient –r
- sudo dhclient
Things to do to get eth0 back – try editing your network rules.
Sudo Vi /etc/udev/rules.d/70-persistent-net.rules
Look for eth0 in the NAME= attribute. If there are others, delete them. If there is eth1 but no eth0, You can overwrite eth1 with eth0, save and reboot the virtual machine.
Note, if you have this problem, it seems to work better to remove any superfluous entries in 70-persisiten-net.rules and overwrite the eth# that is up in your ifconfig –a result, then reboot the virtual machine, go to ifconfig –a, and you will see it up.
So now ifconfig –a tells me that my inet addr is 10.0.2.15. a step forward, but we still aren’t talking to the virtual machine seamlessly like it were a remote server.
Zurmo.org has a tutorial for installing their CRM software with a virtual machine. Consider trying their software to get started with virutalization. http://zurmo.org/wiki/how-to-install-zurmo-virtual-machine
NAT – When using NAT, its like putting the virtual machine behind a virtual router. Just like a router at home. Never mind port forwarding. I am at a new place, and bridged doesn’t seem to work. OK, so try NAT. NAT at least allows me to ping a website on the internet, which mysteriously doesn’t work anymore in Bridged. NAT gives me an ip address on eth0 of 10.0.2.15. Bridged gave me 192.168.1.113. I don’t remember what I did. I rebooted my router.
The normal settings are what works consistently. It does take some practice to get it to work, so don’t give up.
- General: Any time you move your computer to a different network, or reboot your router, your computer gets assigned a new IP address. You have to keep close tabs on your hosts file so it can be updated. Any line in a hosts file that starts with a ‘#’ is not executed.
- Windows: C:\Windows\System32\drivers\etc\hosts – find it, right click on it, and allow permissions for the current user to modify contents of the file. Save a shortcut to where you are going to have easier access on it.
- Mac: /etc/hosts – Mac users should know the password for their user profile. Open Terminal, and use a command line editor such as vi or emacs to open your hosts file. If you don’t know how to use vim or emacs, go find a tutorial on the web and practice it. You must open the file with the sudo command, and correct password challenge, such as sudo emacs /etc/hosts.
- Ubuntu Desktop: /etc/hosts - as above, know your user account password, hoping it has privileges to modify the hosts file with sudo. Get a tutorial on using vi, nano, emacs, or other editor when you get into Terminal so you know what to do when you are there.
There are probably more cases where the connectivity to the virtual machine is lost. I will add more solutions to this problem as I encounter and solve the cases for it.