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

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



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:
 
<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>
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.
[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)
 
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:0 errors:0 dropped:0 overruns:0 frame:0
          TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0
          RX bytes:0 (0.0 b)  TX bytes:0 (0.0 b)
 
can you please let me know, how can I assign a static IP to the Linux Container?
 
Regards,
Srikanth.

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