KVM之十:虚拟机在线添加网卡

时间:2021-04-29 07:09:07

1、查看原有网卡信息

#virsh domiflist snale
Interface Type Source Model MAC
-------------------------------------------------------
vnet0 bridge br0 virtio :::8c:b8:

2、临时添加新网卡

#virsh attach-interface snale --type bridge --source br0
成功附加接口 永久添加网卡命令
#virsh attach-interface snale --type bridge --source br0  --config

3、查看

#virsh domiflist snale
Interface Type Source Model MAC
-------------------------------------------------------
vnet0 bridge br0 virtio :::8c:b8:
vnet1 bridge br0 - :::::cf #ip a
: lo: <LOOPBACK,UP,LOWER_UP> mtu qdisc noqueue state UNKNOWN
link/loopback ::::: brd :::::
inet 127.0.0.1/ scope host lo
inet6 ::/ scope host
valid_lft forever preferred_lft forever
: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu qdisc pfifo_fast state UP qlen
link/ether :::8c:b8: brd ff:ff:ff:ff:ff:ff
inet 192.168.0.23/ brd 192.168.0.255 scope global eth0
inet6 fe80:::ff:fe8c:b860/ scope link
valid_lft forever preferred_lft forever
: eth1: <BROADCAST,MULTICAST> mtu qdisc noop state DOWN qlen
link/ether :::::cf brd ff:ff:ff:ff:ff:ff

4、命令行增加的网卡只保存在内存中,重启就失效,所以需要保存到配置文件中

#virsh dumpxml snale >/etc/libvirt/qemu/snale.xml 
#virsh define /etc/libvirt/qemu/snale.xml

删除网卡命令

#virsh detach-interface snale  --type bridge --mac  :::::cf
成功分离接口

再重新保存配置