为KVM虚拟机添加网卡,并配置IP

环境:

[root@room1pc01 ~]# uname -a
Linux room1pc01.tedu.cn 2.6.32-573.el6.x86_64 #1 SMP Thu Jul 23 15:44:03 UTC 2015 x86_64 x86_64 x86_64 GNU/Linux
[root@room1pc01 ~]# virsh -V
Virsh command line tool of libvirt 0.10.2
See web site at http://libvirt.org/

Compiled with support for:
 Hypervisors: QEMU/KVM LXC ESX Test
 Networking: Remote Network Bridging Interface netcf Nwfilter VirtualPort
 Storage: Dir Disk Filesystem SCSI Multipath iSCSI LVM
 Miscellaneous: Daemon Nodedev SELinux Secrets Debug DTrace Readline

1、查看虚拟机原有网卡信息

[root@room1pc01 ~]# virsh domiflist rh6_node13
Interface  Type       Source     Model       MAC
-------------------------------------------------------
-          network    private1   virtio      54:52:01:01:13:01
-          network    private2   virtio      54:52:01:01:13:02
-          network    public1    virtio      54:52:01:01:13:03
-          network    public2    virtio      54:52:01:01:13:04

2、为虚拟机添加新的网卡(需要虚拟机在开机状态下操作)

[root@room1pc01 data]# virsh attach-interface --domain rh6_node01 --type bridge  --source br0 --config
成功附加接口
[root@room1pc01 data]# virsh domiflist rh6_node01
Interface  Type       Source     Model       MAC
-------------------------------------------------------
vnet0      network    private1   virtio      54:52:01:01:01:01
vnet1      network    private2   virtio      54:52:01:01:01:02
vnet2      network    public1    virtio      54:52:01:01:01:03
vnet3      network    public2    virtio      54:52:01:01:01:04
vnet4      bridge     br0        -           52:54:00:12:32:3f

删除网卡

[root@room1pc01 data]# virsh detach-interface rh6_node01 bridge 52:54:00:31:1b:18 --config
成功分离接口

3、在虚拟机拷贝网卡文件,修改相关配置,并重启网络服务使配置生效

[root@node2 ~]# cd /etc/sysconfig/network-scripts/
[root@node2 network-scripts]# cp ifcfg-eth0 ifcfg-eth4
[root@node2 network-scripts]# vim ifcfg-eth4
DEVICE=eth4
TYPE=Ethernet
ONBOOT=yes
IPV6INIT=no
USERCTL=no
BOOTPROTO=static
IPADDR=192.168.181.102
NETMASK=255.255.255.0
GATEWAY=192.168.181.2
[root@node2 network-scripts]# /etc/init.d/network restart

4、测试配置是否生效

[root@node2 network-scripts]# ping 192.168.181.5
PING 192.168.181.5 (192.168.181.5) 56(84) bytes of data.
64 bytes from 192.168.181.5: icmp_seq=1 ttl=64 time=4.44 ms
64 bytes from 192.168.181.5: icmp_seq=2 ttl=64 time=0.580 ms


你可能感兴趣的:(Linux)