kvm虚拟机添加网卡

kvm虚拟机添加网卡

1
https://www.cnblogs.com/libertylife/p/10266190.html

1. 查看笔记本ip信息

1
ifconfig

会输出如下信息:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
eno1: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.50.146  netmask 255.255.255.0  broadcast 192.168.50.255
        inet6 fe80::db32:5e2b:38b0:8ec1  prefixlen 64  scopeid 0x20<link>
        ether 84:34:97:19:76:89  txqueuelen 1000  (Ethernet)
        RX packets 806  bytes 114275 (111.5 KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 2342  bytes 399691 (390.3 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

lo: flags=73<UP,LOOPBACK,RUNNING>  mtu 65536
        inet 127.0.0.1  netmask 255.0.0.0
        inet6 ::1  prefixlen 128  scopeid 0x10<host>
        loop  txqueuelen 1  (Local Loopback)
        RX packets 3273  bytes 687330 (671.2 KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 3273  bytes 687330 (671.2 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

virbr0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.122.1  netmask 255.255.255.0  broadcast 192.168.122.255
        ether 52:54:00:c0:3c:b0  txqueuelen 1000  (Ethernet)
        RX packets 0  bytes 0 (0.0 B)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 1603  bytes 67455 (65.8 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

vnet0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet6 fe80::fc54:ff:fe68:4f61  prefixlen 64  scopeid 0x20<link>
        ether fe:54:00:68:4f:61  txqueuelen 1000  (Ethernet)
        RX packets 0  bytes 0 (0.0 B)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 256  bytes 11683 (11.4 KiB)
        TX errors 0  dropped 706 overruns 0  carrier 0  collisions 0

vnet1: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet6 fe80::fc54:ff:fefb:f5d6  prefixlen 64  scopeid 0x20<link>
        ether fe:54:00:fb:f5:d6  txqueuelen 1000  (Ethernet)
        RX packets 0  bytes 0 (0.0 B)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 1700  bytes 73011 (71.2 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

zt5u4qbuhh: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 2800
        inet 172.26.115.151  netmask 255.255.0.0  broadcast 172.26.255.255
        inet6 fe80::140f:85ff:fec9:96ff  prefixlen 64  scopeid 0x20<link>
        ether 16:0f:85:c9:96:ff  txqueuelen 1000  (Ethernet)
        RX packets 0  bytes 0 (0.0 B)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 30  bytes 4108 (4.0 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

备注:
eno1 //与物理机通信
virbr0 //与虚拟机通信
zt5u4qbuhh //与zerotier通信

eno1网卡的信息

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
TYPE="Ethernet"
PROXY_METHOD="none"
BROWSER_ONLY="no"
BOOTPROTO="dhcp"
DEFROUTE="yes"
IPV4_FAILURE_FATAL="no"
IPV6INIT="yes"
IPV6_AUTOCONF="yes"
IPV6_DEFROUTE="yes"
IPV6_FAILURE_FATAL="no"
IPV6_ADDR_GEN_MODE="stable-privacy"
NAME="eno1"
UUID="b6ad092a-6096-4977-a96e-74d9a153def6"
DEVICE="eno1"
ONBOOT="yes"
ZONE=public

2. 新建一张网卡brv

1
2
cd /etc/sysconfig/network-scripts
vi ifcfg-brv

输入如下信息:

1
2
3
4
5
6
7
8
DEVICE=brv
TYPE=Bridge
ONBOOT=yes
NM_CONTROLLED=yes
BOOTPROTO=static
IPADDR=192.168.50.122
NETMASK=255.255.255.0
GATEWAY=192.168.50.255

3. 重启系统,就可以看到已经激活的网卡了

4. 把这网卡添加到kvm22虚拟机中

1
2
virsh attach-interface kvm22 --type bridge --source brv               //临时添加,重启失效
virsh attach-interface kvm22 --type bridge --source brv --config      //永久添加.

5. 查看虚拟机网卡就能看到已经添加成功

1
virsh domiflist kvm22

6. 把网卡信息写入虚拟机,以免失效

1
virsh dumpxml kvm22  > /etc/libvirt/qemu/kvm22.xml

7. 删除网卡命令

1
virsh detach-interface kvm22  --type bridge --mac  52:54:00:fb:f5:d6
备注:
上面这方法加的是静态IP,只能访问笔记本,无法访问虚拟机.

Leave a Reply

Your email address will not be published. Required fields are marked *