[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

Re: [libvirt] Assigning a static IP to the Linux Container through libvirt.

On Fri, Mar 05, 2010 at 01:05:51PM +0530, Kumar L Srikanth-B22348 wrote:
> Hi,
> I want to assign a static IP to one of the containers
> created using libvirt.
> For that, I defined a network 'mynetwork' using net-define. The XML
> format for that network is shown below:

The 'net-XXXX' commands are for getting up NAT/routed networking on 
the host. The guest is then connected to this network & gets given
an IP from the range assigned.

> <network>
>   <name>mynetwork</name>
>   <uuid>f76c44dd-bcef-6b45-4a50-00d575a369ad</uuid>
>   <bridge name='virbr1' stp='on' delay='0' />
>   <ip address='' netmask=''>
>   </ip>
> </network>

This has configured your *host* to have, not the container.

> I started the network 'mynetwork' using net-start.
> virsh # net-list --all
> Name                 State      Autostart
> -----------------------------------------
> default                 active     yes
> mynetwork           active     no
> I created a domain 'vm1_fedora' with libvirt XML:
> <domain type='lxc' id='1'>
>   <name>vm1_fedora</name>
>     <memory>500000</memory>
>       <os>
>           <type>exe</type>
>           <init>/bin/bash</init>
>       </os>
>       <vcpu>1</vcpu>
>       <clock offset='utc'/>
>       <on_poweroff>destroy</on_poweroff>
>       <on_reboot>restart</on_reboot>
>       <on_crash>destroy</on_crash>
>       <devices>
>         <emulator>/usr/libexec/libvirt_lxc</emulator>
>         <filesystem type='mount'>
>           <source dir='/root/lxc/fedora12'/>
>           <target dir='/'/>
>         </filesystem>
>         <filesystem type='mount'>
>           <source dir='/root/lxc/fedora12/dev'/>
>           <target dir='/dev'/>
>         </filesystem>
>         <interface type='network'>
>           <source network='mynetwork'/>
>         </interface>
>         <console type='pty' />
>       </devices>
> </domain>
> But, when I start that domain and see for 'ifconfig', I am not able to
> see the IP address there.

The libvirt configuration only determines *how* a guest / container is
connected to the host. In this case you've conencted it to the virtual
network 'mynetwork'.  It does not do anything to actually configure
the network inside the container - that still needs to be done using the
regular distro initscripts or manual ifconfig inside the container.

> [root localhost /]# ifconfig
> eth0      Link encap:Ethernet  HWaddr 52:54:00:53:4D:BF
>           inet6 addr: fe80::5054:ff:fe53:4dbf/64 Scope:Link
>           UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
>           RX packets:18 errors:0 dropped:0 overruns:0 frame:0
>           TX packets:6 errors:0 dropped:0 overruns:0 carrier:0
>           collisions:0 txqueuelen:1000
>           RX bytes:840 (840.0 b)  TX bytes:384 (384.0 b)

Inside your container you need to setup the config for eth0 still - it does
not happen automatically

|: Red Hat, Engineering, London    -o-   http://people.redhat.com/berrange/ :|
|: http://libvirt.org -o- http://virt-manager.org -o- http://deltacloud.org :|
|: http://autobuild.org        -o-         http://search.cpan.org/~danberr/ :|
|: GnuPG: 7D3B9505  -o-   F3C9 553F A1DA 4AC2 5648 23C1 B3DF F742 7D3B 9505 :|

[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]