简体   繁体   English

如何即时更改 KVM 的网络设置?

[英]How to change network settings for a KVM on-the-fly?

Every time I add a new VM and try to attach a static ip, it won't work from the first attempt.每次我添加一个新的虚拟机并尝试附加一个 static ip 时,它从第一次尝试就无法工作。

So I install a new VM with virt-install , then I add a static host to my virtual network interface ( virsh net-edit default ):因此,我使用virt-install安装了一个新 VM,然后将 static 主机添加到我的虚拟网络接口( virsh net-edit default ):

  <name>default</name>
  <uuid>5582ba50-a089-4210-8163-cf79987bff8d</uuid>
  <forward mode='nat'/>
  <bridge name='virbr0' stp='on' delay='0'/>
  <mac address='52:54:00:60:cc:1a'/>
  <ip address='192.168.100.1' netmask='255.255.255.0'>
    <dhcp>
      <range start='192.168.100.100' end='192.168.100.254'/>
      <host mac='52:54:00:db:f4:3b' name='machine1' ip='192.168.100.2'/>
      <host mac='52:54:00:d5:6b:bb' name='machine2' ip='192.168.100.3'/>
    </dhcp>
  </ip>
</network>

I turn off the VM and do我关闭虚拟机并执行

virsh net-destroy default
virsh net-start default
systemctl restart libvirtd

Then when the VM boots, it either gets an ip from the DHCP range, or it doesn't get an ip address at all.然后,当 VM 启动时,它要么从 DHCP 范围中获得 ip,要么根本没有获得 ip 地址。 After multiple restarts, the VM gets the correct ip.多次重启后,VM 得到正确的 ip。 What am I doing wrong?我究竟做错了什么? What is the proper way to modify network settings for a specific VM without hurting the others?在不伤害其他虚拟机的情况下修改特定虚拟机的网络设置的正确方法是什么? I do "net-destroy", so all VMs get shut down during this process.我做“net-destroy”,所以在这个过程中所有的虚拟机都会被关闭。

According to my observations, this works ok:根据我的观察,这可以正常工作:

After a host was added (virsh net-edit), the VM should be shut down by means of virsh ( virsh shutdown machine-name )添加主机后(virsh net-edit),应通过virsh关闭虚拟机( virsh shutdown machine-name

Then virsh net-destroy default && virsh net-start default然后virsh net-destroy default && virsh net-start default

systemctl restart libvirtd is not required at all systemctl restart libvirtd根本不需要

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM