update: 2018-05-26
在Ubuntu14.04上使用Virtual Machine Manager安装 Cent7 (v1503), 安装选RHEL7类型, 完毕需要登入到VM,更改网络配置如下:
1)/etc/sysconfig/network-scripts/ifcfg-eth0
[root@cent7 ~]# cat /etc/sysconfig/network-scripts/ifcfg-eth0
HWADDR="52:54:00:e8:4d:87"
TYPE="Ethernet"
BOOTPROTO="none"
DEFROUTE="yes"
PEERDNS="yes"
PEERROUTES="yes"
IPV4_FAILURE_FATAL="no"
IPV6INIT="yes"
IPV6_AUTOCONF="yes"
IPV6_DEFROUTE="yes"
IPV6_PEERDNS="yes"
IPV6_PEERROUTES="yes"
IPV6_FAILURE_FATAL="no"
NAME="eth0"
# same with GATEWAY
DNS1="192.169.122.1"
DNS2="114.114.114.114"
DNS3="8.8.8.8"
# This is system specific and can be created using 'uuidgen eth0' command #
UUID="cc53e3d4-2c07-4c42-915c-c55075c5cbb3"
DEVICE="eth0"
ONBOOT="yes"
IPADDR="192.168.122.182"
NETWORK="255.255.255.0"
BROADCAST="192.168.122.255"
其中:
HWADDR=
可以通过 ip a 命令获得。或者在虚拟机的主机的虚拟机配置文件中找到:
/etc/libvirt/qemu/centos7.0-vm1.xml
UUID=
这个被 NetworkManager 服务(yum provides "*/nmcli")使用(通过命令 nmcli),如果不在意可以不管它。但是最好还是用命令生成一个唯一的:
uuigen eth0
然后把新生成的值填入配置文件:ifcfg-eth0
此时再使用命令查看网卡的 UUID:
# nmcli con | sed -n '1,2p'
NAME UUID TYPE DEVICE
eth0 cc53e3d4-2c07-4c42-915c-c55075c5cbb3 802-3-ethernet eth0
与下面的值比较:
# cat /etc/sysconfig/network-scripts/ifcfg-eth0 | grep UUID
UUID="cc53e3d4-2c07-4c42-915c-c55075c5cbb3"
2)/etc/sysconfig/network
更改如下:
[root@cent7 ~]# cat /etc/sysconfig/network
# Created by anaconda
NETWORKING=yes
HOSTNAME=cent7.pepstack.com
GATEWAY=192.168.122.1
resolv.conf更改如下(重启网络会被覆盖):
[root@cent7 ~]# cat /etc/resolv.conf
nameserver 192.168.122.1
重启网络:
# systemctl restart network
现在虚拟机网络可以使用了。