线上kvm客户机因业务需要,增加一块访问其它网段的虚拟网卡,命令如下:
1、添加网卡
virsh attach-interface <domain-name> --type bridge --source <net-bridge> --model virtio --config --live
说明:
- domain-name: 虚拟机名称或ID
- net-bridge:网桥名称
- –config:写入配置文件
- –live:在线添加(表面上添加了,实际上网络不通,需要重启)
2、重启服务器
3、查看网卡名称
cat /etc/udev/rules.d/70-persistent-net.rules
内容如下:
# This file was automatically generated by the /lib/udev/write_net_rules
# program, run by the persistent-net-generator.rules rules file.
#
# You can modify it, as long as you keep each rule on a single
# line, and change only the value of the NAME= key.
# PCI device 0x1af4:0x1000 (virtio-pci)
SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="52:54:00:4d:1d:50", ATTR{type}=="1", KERNEL=="eth*", NAME="eth0"
# PCI device 0x1af4:0x1000 (virtio-pci)
SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="52:54:00:4e:5d:df", ATTR{type}=="1", KERNEL=="eth*", NAME="eth1"
# PCI device 0x1af4:0x1000 (virtio-pci)
SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="52:54:00:12:9a:80", ATTR{type}=="1", KERNEL=="eth*", NAME="eth2"
其中最后一行,name=“eth2”即为网卡名称。
4、配置网卡
以网卡名eth2为例:
vim /etc/sysconfig/network-scripts/ifcfg-eth2"
添加下列内容:
DEVICE="eth2"
NAME=eth2
BOOTPROTO="static"
HWADDR="52:54:00:12:9a:80"
IPADDR="172.16.1.100"
# GATEWAY =
NETMASK="255.255.255.0"
NM_CONTROLLED="yes"
ONBOOT="yes"
TYPE="Ethernet"