KVM虚拟机在线添加网卡

查看虚拟机网卡信息

[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文件(不加此步骤重启后网卡也会生效)
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

侯侯Hou

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值