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

Kumar L Srikanth-B22348 B22348 at freescale.com
Fri Mar 5 10:42:31 UTC 2010


Thanks for the quick response Daniel.
If I want to assign IP address automatically through dhcp, I used
'default' network in the domain XML.
I am expecting incremental IP's to the containers in the series
192.168.122.*. But, I am not able to get the IP to the container.
After I start the container following is the ifconfig details in the
host machine:

[root at localhost lxc_devel]# ifconfig
eth0      Link encap:Ethernet  HWaddr 00:50:BF:27:AA:60
          inet6 addr: fe80::250:bfff:fe27:aa60/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:0 errors:0 dropped:0 overruns:0 frame:0
          TX packets:78 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:0 (0.0 b)  TX bytes:11724 (11.4 KiB)
          Interrupt:21 Base address:0x1140

lo        Link encap:Local Loopback
          inet addr:127.0.0.1  Mask:255.0.0.0
          inet6 addr: ::1/128 Scope:Host
          UP LOOPBACK RUNNING  MTU:16436  Metric:1
          RX packets:2669 errors:0 dropped:0 overruns:0 frame:0
          TX packets:2669 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0
          RX bytes:434713 (424.5 KiB)  TX bytes:434713 (424.5 KiB)

veth0     Link encap:Ethernet  HWaddr 1A:52:DA:BE:CE:DE
          inet6 addr: fe80::1852:daff:febe:cede/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:6 errors:0 dropped:0 overruns:0 frame:0
          TX packets:16 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:384 (384.0 b)  TX bytes:764 (764.0 b)

virbr0    Link encap:Ethernet  HWaddr 1A:52:DA:BE:CE:DE
          inet addr:192.168.122.1  Bcast:192.168.122.255
Mask:255.255.255.0
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:36 errors:0 dropped:0 overruns:0 frame:0
          TX packets:27 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0
          RX bytes:2304 (2.2 KiB)  TX bytes:4452 (4.3 KiB)

Please let me know.

Regards,
Srikanth.
-----Original Message-----
From: Daniel P. Berrange [mailto:berrange at redhat.com] 
Sent: Friday, March 05, 2010 3:56 PM
To: Kumar L Srikanth-B22348
Cc: Reddy B Veera-B22347; libvir-list at redhat.com
Subject: Re: 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 172.16.1.20 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='172.16.1.20' netmask='255.255.255.0'>
>   </ip>
> </network>

This has configured your *host* to have 172.16.1.20, 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 172.16.1.20 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 at 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


Regards,
Daniel
-- 
|: 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 :|





More information about the libvir-list mailing list