kvm 给虚机增加网卡
[root@666 ok]# virsh domiflist c03 Interface Type Source Model MAC ------------------------------------------------------- vnet1 bridge br0 rtl8139 52:54:00:cf:e1:a3 [root@666 ok]# virsh list Id Name State ---------------------------------------------------- 1 c01 running 2 c03 running 3 c70 running
临时增加网卡:
[root@666 ok]# virsh attach-interface c03 --type bridge --source br0 Interface attached successfully 查看: [root@666 ok]# virsh domiflist c03 Interface Type Source Model MAC ------------------------------------------------------- vnet1 bridge br0 rtl8139 52:54:00:cf:e1:a3 vnet3 bridge br0 rtl8139 52:54:00:7e:c2:6a [root@c03 conf]# ip a 1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00 inet 127.0.0.1/8 scope host lo inet6 ::1/128 scope host valid_lft forever preferred_lft forever 2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000 link/ether 52:54:00:cf:e1:a3 brd ff:ff:ff:ff:ff:ff inet 10.100.0.61/24 brd 10.100.0.255 scope global eth0 inet6 fe80::5054:ff:fecf:e1a3/64 scope link valid_lft forever preferred_lft forever 3: eth1: <BROADCAST,MULTICAST> mtu 1500 qdisc noop state DOWN qlen 1000 link/ether 52:54:00:2b:9e:6c brd ff:ff:ff:ff:ff:ff
永久增加网卡:
命令行增加网卡只保存在内存中,重启就失效,所以要保存在配置文件中
[root@666 ok]# virsh dumpxml c03 >/etc/libvirt/qemu/c03.xml [root@666 ok]# virsh define /etc/libvirt/qemu/c03.xml Domain c03 defined from /etc/libvirt/qemu/c03.xml
重启虚机后再次查看网卡:
[root@c03 ~]# ip a 1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00 inet 127.0.0.1/8 scope host lo inet6 ::1/128 scope host valid_lft forever preferred_lft forever 2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000 link/ether 52:54:00:cf:e1:a3 brd ff:ff:ff:ff:ff:ff inet 10.100.0.61/24 brd 10.100.0.255 scope global eth0 inet6 fe80::5054:ff:fecf:e1a3/64 scope link valid_lft forever preferred_lft forever 3: eth2: <BROADCAST,MULTICAST> mtu 1500 qdisc noop state DOWN qlen 1000 link/ether 52:54:00:7e:c2:6a brd ff:ff:ff:ff:ff:ff
增加并配置配置文件:
[root@c03 network-scripts]# cp ifcfg-eth0 ifcfg-eth2^C [root@c03 network-scripts]# pwd /etc/sysconfig/network-scripts [root@c03 network-scripts]# cp ifcfg-eth0 ifcfg-eth2 配改MAC并查看: DEVICE=eth0 | DEVICE=eth2 HWADDR=52:54:00:CF:E1:A3 | HWADDR=52:54:00:7e:c2:6a TYPE=Ethernet | TYPE=Ethernet UUID=4edbb7bf-e64f-402a-854c-ff259250c497 | #UUID=4edbb7bf-e64f-402a-854c-ff259250c497 ONBOOT=yes | ONBOOT=yes NM_CONTROLLED=yes | NM_CONTROLLED=yes BOOTPROTO=dhcp | BOOTPROTO=dhcp
查看IP
[root@c03 network-scripts]# ip a 1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00 inet 127.0.0.1/8 scope host lo inet6 ::1/128 scope host valid_lft forever preferred_lft forever 2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000 link/ether 52:54:00:cf:e1:a3 brd ff:ff:ff:ff:ff:ff inet 10.100.0.61/24 brd 10.100.0.255 scope global eth0 inet6 fe80::5054:ff:fecf:e1a3/64 scope link valid_lft forever preferred_lft forever 3: eth2: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000 link/ether 52:54:00:7e:c2:6a brd ff:ff:ff:ff:ff:ff inet 10.100.0.58/24 brd 10.100.0.255 scope global eth2 inet6 fe80::5054:ff:fe7e:c26a/64 scope link valid_lft forever preferred_lft forever
删除网卡命令:
# ip a 1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00 inet 127.0.0.1/8 scope host lo inet6 ::1/128 scope host valid_lft forever preferred_lft forever 2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000 link/ether 52:54:00:cf:e1:a3 brd ff:ff:ff:ff:ff:ff inet 10.100.0.61/24 brd 10.100.0.255 scope global eth0 inet6 fe80::5054:ff:fecf:e1a3/64 scope link valid_lft forever preferred_lft forever 3: eth2: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000 link/ether 52:54:00:7e:c2:6a brd ff:ff:ff:ff:ff:ff inet 10.100.0.58/24 brd 10.100.0.255 scope global eth2 inet6 fe80::5054:ff:fe7e:c26a/64 scope link valid_lft forever preferred_lft forever [root@666 ok]# virsh detach-interface c03 --type bridge --mac 52:54:00:7e:c2:6a Interface detached successfully 查看IP # ip a 1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00 inet 127.0.0.1/8 scope host lo inet6 ::1/128 scope host valid_lft forever preferred_lft forever 2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000 link/ether 52:54:00:cf:e1:a3 brd ff:ff:ff:ff:ff:ff inet 10.100.0.61/24 brd 10.100.0.255 scope global eth0 inet6 fe80::5054:ff:fecf:e1a3/64 scope link valid_lft forever preferred_lft forever 再次保存配置文件: [root@666 ok]# virsh dumpxml c03 >/etc/libvirt/qemu/c03.xml [root@666 ok]# virsh define /etc/libvirt/qemu/c03.xml Domain c03 defined from /etc/libvirt/qemu/c03.xml
联系方式QQ:326528263 EMAIL:clnking@163.com 网名:bass 分享技术 突破难点 创新思维