Are you using bridged networking? This is usually the easiest way to set up networking in KVM under Linux. I would assume one reason you might be able to have network connectivity on the guest VM without having set up its IP explicitly is that it's getting a valid IP from a DHCP server, either through NAT from the host OS or from a DHCP server on your network. However, usually you choose network interfaces during install (using virt-install, KVM, etc) to make available to the guest. How did you install the guest OS?
To find its IP, you would need to run ifconfig
on the guest, not the host. If you get an IP on the same subnet as your host OS's IP, you can connect to it using that IP -- in that case treat it like it's any other computer on the network.
UPDATE:
Per my comment below, to set up bridged networking, on the host OS edit the /etc/network/interfaces
file to look like the following:
auto lo
iface lo inet loopback
auto eth0
iface eth0 inet manual
auto br0
iface br0 inet static
address 192.168.0.10 #change these 5 lines
network 192.168.0.0 #to match your IP/network info
netmask 255.255.255.0 #
broadcast 192.168.0.255 #
gateway 192.168.0.1 #
bridge_ports eth0
bridge_stp off
bridge_fd 0
bridge_maxwait 0
if you use DHCP to get your IP, set the br0 section to look like this instead of the last part above:
auto br0
iface br0 inet dhcp
bridge_ports eth0
bridge_stp off
bridge_fd 0
bridge_maxwait 0
You can set the network when you install the guest using libvirt:
sudo virt-install --vnc -n vm1 -r 1024 --vcpus=1 \
--os-type=linux --os-variant=ubuntulucid --hvm --accelerate \
--network=bridge:br0 -c ~/isos/ubuntu_lucid_amd64.iso \
-f ~/vms/vm1ubuntu.vm -s 50
This would install an Ubuntu Lucid guest named 'vm1' from an iso file, giving it 1 vCPU, 1024MB of RAM, and a 50GB qcow2 disk image file.
If you've installed your guest with this or another method, you can run sudo virsh dumpxml vm1 > vm1.xml
to dump information about that guest, edit the file to change a setting, and use sudo virsh create vm1.xml
to recreate the guest with the new settings (you'll need to run sudo virsh destroy
and sudo virsh undefine
in between or use some other method to stop and remove the guest in its current format before re-creating).