查看虚拟机网卡信息
[root@xa-radb-02 ~]# virsh domiflist --help
命令名称
domiflist - 列出所有域虚拟接口
概览
domiflist <domain> [--inactive]
说明
获取域虚拟接口小结
选项
[--domain] <字符串> 域名,id 或 uuid
--inactive 获取不活跃而不是运行的配置
[root@xa-radb-02 ~]# virsh domiflist ceph1
接口 类型 源 型号 MAC
-----------------------------------------------------
vnet1 bridge br0 virtio 52:54:00:9f:dd:4c
vnet10 bridge br0 virtio 52:54:00:f1:75:c6
添加虚机网卡接口
[root@xa-radb-02 ~]# virsh attach-interface --help
命令名称
attach-interface - 获得网络界面
概览
attach-interface <domain> <type> <source> [--target <字符串>] [--mac <字符串>] [--script <字符串>] [--model <字符串>] [--alias <字符串>] [--inbound <字符串>] [--outbound <字符串>] [--persistent] [--config] [--live] [--current] [--print-xml] [--managed]
说明
附加新网络界面.
选项
[--domain] <字符串> 域名,id 或 uuid
[--type] <字符串> 网络界面类型
[--source] <字符串> 网络界面源
--target <字符串> 目标网络名称
--mac <字符串> MAC 地址
--script <字符串> 构建网络界面用脚本
--model <字符串> 模型类型
--alias <字符串> custom alias name of interface device
--inbound <字符串> 控制域的进入流量
--outbound <字符串> 控制域的外出流量
--persistent 让实时更改持久
--config 影响下一次引导
--live 影响运行的域
--current 影响当前域
--print-xml print XML document rather than attach the interface
--managed libvirt will automatically detach/attach the device from/to host
#临时添加新网卡
[root@localhost~]# virsh attach-interface centos73 --type bridge --source br0
Interface
attached successfully
成功附加接口
#永久添加网卡,这种方式有时destroy后start网卡会失效
[root@xa-radb-02 ~]# virsh attach-interface ceph1 --type bridge --source br0 --model virtio --current
#查看虚机接口信息
[root@xa-radb-02 ~]# virsh domiflist ceph1
接口 类型 源 型号 MAC
-----------------------------------------------------
vnet1 bridge br0 virtio 52:54:00:9f:dd:4c
vnet10 bridge br0 virtio 52:54:00:f1:75:c6
命令行增加的网卡只保存在内存中,重启就失效,所以需要保存到配置文件中
注意通过virsh attach-interface命令增加的网卡时及时生效的,但是在虚拟机重启后新增加的网卡会消失。
那是因为该命令新增加的网卡,没有更新到虚拟机的配置文件中。要使该网卡永久生效,我们可以使用virsh dumpxml命令把该配置保存到虚拟机配置文件中
[root@xa-radb-02 ~]# virsh dumpxml ceph1 > /etc/libvir/qemu/ceph1.xml
#删除网卡命令
#virsh detach-interface ceph1 --type bridge --mac 52:54:00:9f:dd:4c
推荐使用:
#--config影响下次引导,重启后网卡生效
virsh attach-interface ceph1 --type bridge --source br0 --model virtio --config
virsh dumpxml ceph1 > /etc/libvirt/qemu/ceph1.xml #为了确保生效,保存xml文件(不加此步骤重启后网卡也会生效)