Monday, November 08, 2010

Assign public IP on VM guest using KVM Ubuntu 10.04.1

For the last 5 days, I was doing the installation of KVM. Virtualization technology. I'm using Ubuntu 10.04.1 Server Edition 64 bit for the host. The installation was done via virt-install command. I am also using Ubuntu 10.04.1 Server Edition for guest OS.


The only problem was, I want my VM guest is accessible from internet. VM guest by default is using Private IP 192.168.122.x. It was generated by the host. Host will have virbr0 which has IP 192.168.122.1. After googling for a weeks, I found the answer.

These what I did.


1. Install the VM (of course)
2. Run :
virsh dumpxml [domain_id] > /tmp/domain_id.xml
 3. Edit, using your text editor :

    < interface type='network bridge' >
      < mac address='52:54:00:74:fa:dd'/ >
      < source bridge='network br0'/ >
    < /interface >
   
4. Run :
virsh define /tmp/domain_id.xml

5. The important thing that I missed. Restart the libvirt-bin service
sudo /etc/init.d/libvirt-bin restart

6. Go to the VM console. You can use Virtual Machine Manage or ssh to the guest.
7. Edit the network manually. Here's my /etc/network/interfaces file on guest VM :
# The loopback network interface
auto lo iface lo inet loopback

# The primary network interface
auto eth0
iface eth0 inet static
address 202.x.x.x
netmask 255.255.255.x
network 202.x.x.x
bcast   202.x.x.x
gateway 202.x.x.x      

8. Just want to make sure, I did step 5 again.

That's all.

Hope this article can help someone.

Here's the reference that I was read about KVM :
  1. http://embr.cygni.se/forme/2009/06/getting-started-with-kvm-on-ubuntu-904/
  2. http://blog.codefront.net/2010/02/01/setting-up-virtualization-on-ubuntu-with-kvm/
  3. http://ubuntuforums.org/showthread.php?t=966739
  4. http://reidablog.blogspot.com/2008/06/with-correct-bios-settings-enabled-on.html
  5. http://www.openg.info/entry/kvm-network-bridge-public-static-ip-host-guests
  6. http://www.linux-kvm.com/content/using-bridged-networking-virt-manager
  7. http://blog.loftninjas.org/2009/04/06/quick-bridging-with-kvm-on-ubuntu-jaunty/
  8. http://www.cyberciti.biz/faq/troubleshooting-kvm-virtualization-problem-with-log-files/
  9. http://fedoraproject.org/wiki/Archive:Virtualization_in_Fedora_8#Managing_Virtual_Machines_from_the_command_line_with_virsh
  10. http://www.techotopia.com/index.php/Installing_a_KVM_Guest_OS_from_the_Command-line_%28virt-install%29
  11. http://www.ideyatech.com/2010/05/virtualization-with-ubuntu-1004-lucid-lynx/
  12. http://www.linux-kvm.org/page/Networking
  13. https://help.ubuntu.com/community/KVM/Networking#Troubleshooting
  14. http://www.mythicalbeast.co.uk/linux/kvm_howto.html
  15. http://wiki.xensource.com/xenwiki/XenNetworking -- (it's about Xen. I just took the concept)
  16. http://www.digitalpains.net/networking/kvm-and-bridge-network-definition-on-ubuntu
  17. http://www.digitalpains.net/linux/kvm/ideal-virtualization-solution-using-ubuntu
  18. http://ubuntuforums.org/showthread.php?t=837025
  19. http://www.linuxquestions.org/questions/linux-virtualization-90/using-kvm-public-bridge-manually-826299/
  20. http://www.cyberciti.biz/faq/linux-kvm-disable-virbr0-nat-interface/
  21. http://wiki.centos.org/HowTos/KVM#head-8424c473b52c407c62d08e8a37406821d05f5862 -- (it's about Xen. I just took the concept)
  22. https://help.ubuntu.com/community/KVM/Directly
  23. http://wiki.debian.org/NetworkConfiguration#BringingupaninterfacewithoutanIPaddress
  24. https://help.ubuntu.com/community/IptablesHowTo
  25. https://help.ubuntu.com/community/KVM/Managing
Post a Comment