[libvirt] networking static ip address

Hi, we are using the 0.6.0 version and an Ubuntu guest os under KVM virtualization. We have tried several ways to assign a static ip address to the guest os eth0 device on boot, but we didn't success. Is there any easy way to do it? We are trying to have a guest with the ip 192.168.0.1 in the eth0 device, enslaved to the br0 bridge on the host machine, which seems to be a pretty easy setup to test. When the guest OS is booted, the eth0 device exists, but is not up, and doesn't have the IP. Regards, Francisco.

On Friday 20 February 2009 13:54:20 Francisco José Martín wrote: Hi,
We have tried several ways to assign a static ip address to the guest os eth0 device on boot, but we didn't success. Is there any easy way to do it?
Yes. Create a network definition, specify a host element to the dhcp definition, attach the machine to the created bridge and it should work. <network> <name>sample</name> <forward dev='eth0' mode='nat'/> <bridge name='intbr0' stp='on' forwardDelay='0' /> <ip address='192.168.122.1' netmask='255.255.255.0'> <dhcp> <range start='192.168.122.2' end='192.168.122.254' /> <host mac='AA:BB:CC:DD:EE:FF' ip='192.168.122.102'/> </dhcp> </ip> </network> Snippet for the domain definition: <interface type='bridge'> <mac address='AA:BB:CC:DD:EE:FF'/> <source bridge='intbr0'/> <target dev='vnet0'/> </interface>
When the guest OS is booted, the eth0 device exists, but is not up, and doesn't have the IP.
Is dnsmasq installed and running? Does the guest system use dhcp? Uli

Thanks for the input. Then, I suppose there's no way to assign the IP on boot without DHCP, there is? Can it be done without using <network> type elements? Regards, Francisco. On Fri, Feb 20, 2009 at 19:52, Ulrich Dangel <uli@spamt.net> wrote:
On Friday 20 February 2009 13:54:20 Francisco José Martín wrote: Hi,
We have tried several ways to assign a static ip address to the guest os eth0 device on boot, but we didn't success. Is there any easy way to do it?
Yes. Create a network definition, specify a host element to the dhcp definition, attach the machine to the created bridge and it should work.
<network> <name>sample</name> <forward dev='eth0' mode='nat'/> <bridge name='intbr0' stp='on' forwardDelay='0' /> <ip address='192.168.122.1' netmask='255.255.255.0'> <dhcp> <range start='192.168.122.2' end='192.168.122.254' /> <host mac='AA:BB:CC:DD:EE:FF' ip='192.168.122.102'/> </dhcp> </ip> </network>
Snippet for the domain definition:
<interface type='bridge'> <mac address='AA:BB:CC:DD:EE:FF'/> <source bridge='intbr0'/> <target dev='vnet0'/> </interface>
When the guest OS is booted, the eth0 device exists, but is not up, and doesn't have the IP.
Is dnsmasq installed and running? Does the guest system use dhcp?
Uli
-- Libvir-list mailing list Libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list

Francisco José Martín wrote:
Then, I suppose there's no way to assign the IP on boot without DHCP, there is?
Plenty of ways, but they aren't things libvirt (or physical hardware) has control over. Two approaches I use (in situations which call from them respectively): Build the VM image from a kickstart file with the static IP substituted in. Boot (using -kernel, -initrd and -append) into a custom initrd which rewrites /etc/sysconfig/network-scripts/ifcfg-* (and friends) for the desired configuration within a given guest. I suppose you could also use an expect script to log into a booted guest at its console (via a serial console redirected to a VT or socket or such -- libvirt has plenty of options in this respect) and modify its network configuration that way.
participants (3)
-
Charles Duffy
-
Francisco José Martín
-
Ulrich Dangel