On 03/14/2014 05:12 PM, Peng Yu wrote:> Hi,
>
> I have the following configuration in the xml of the guest. But if I
> set a static ip on the guest, then the guest can not access the
> outside network. I don't find an example on how to set a static IP
> address for the guest. Could anybody know how to modify the following
> xml code to do so? Thanks.
>
> 41 <interface type='network'>
> 42 <mac address='52:54:00:6c:a7:6d'/>
> 43 <source network='default'/>
> 44 <model type='virtio'/>
> 45 <address type='pci' domain='0x0000'
bus='0x00' slot='0x03'
> function='0x0'/>
> 46 </interface>
>
You need to edit the network named "default" (since that is the
network
your guest is attaching to) to add a static dhcp host entry. There are a
couple different ways to do this:
1) using the command "virsh net-edit default" (as root) to add a
<host>
entry to the <dhcp> section of the network, similar to the example here:
http://www.libvirt.org/formatnetwork.html#elementsAddress
After you have edited this, you will need to destroy and re-start the
network, as well as shutting down and re-starting your guest, e.g:
virsh net-destroy default; virsh net-start default;
virsh shutdown $guestname
(wait while guest shuts down completely)
virsh start $guestname
2) If your libvirt is new enough (I think 0.10.2 is new enough), use the
"virsh net-update" command to add the new dhcp host entry without
restarting the network, for example:
virsh net-update default add dhcp-host \
'<host mac="52:54:00:6c:a7:6d"
ip="192.168.122.10"/>' \
--live --config
(note that "--live" tells it to make the change take effect
immediately,
and "--config" tells it to also make the change persistent, so that it
will still be there the next time the network is stopped and restarted).
In case (2), you will still need to do something to force your guest to
re-request a DHCP address. Usually this can be done by simply disabling
and re-enabling the interface in the guest itself.