CentOS虚机Ip配置

前提:虚机网络配置选择NAT

CentOS虚机Ip配置

 

1.查看本虚机的Ip,地址是多少,点击vm编辑-虚拟网络编辑器

CentOS虚机Ip配置

 

2.选择VMnet8, 点击Nat设置

CentOS虚机Ip配置

3.记住这些地址

CentOS虚机Ip配置

 4.进入系统,进入文件  vi /etc/sysconfig/network-scripts/ifcfg-eth0  修改其中的配置,和刚刚配置的一致

DEVICE=eno【数字】          // 这是网卡的名称
NAME=eno【数字】
ONBOOT=yes                 // 是否随着开机自启动
BOOTPROTO=static           // static表示固定ip地址,dhcp表示随机获取ip
IPADDR=***.***.***.150      // 手动设置的固定ip地址
NETMASK=255.255.255.0      // mask地址,就是掩码

CentOS虚机Ip配置

5.

[[email protected] network-scripts]# service network restart                  重启网络服务

就这样,内网连接完成,如何测试是否成功呢?

方法:1 在windows上cmd中,ping 你设置的IPADDR。如果发送成功,表明成功。

        2 在CentOS中,ping  VMnet8的IPv4地址。如果发送成功,表明成功。

 

6.如果重启网络出现错误。ifconfig...没有看到eth0网卡   Bringing up interface eth0:  Device eth0 does not seem to be present,delaying initialization.                    [FAILED]

解决办法:

首先,打开/etc/udev/rules.d/70-persistent-net.rules内容如下面所示:

# vi /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 0x1022:0x2000 (pcnet32)
SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="00:0c:29:8f:89:9

7", ATTR{type}=="1", KERNEL=="eth*", NAME="eth0"
# PCI device 0x1022:0x2000 (pcnet32)
SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="00:0c:29:50:bd:1

7", ATTR{type}=="1", KERNEL=="eth*", NAME="eth1"

记录下eth1网卡的mac地址00:0c:29:50:bd:17

接下来,打开/etc/sysconfig/network-scripts/ifcfg-eth0网卡配置文件

# vi /etc/sysconfig/network-scripts/ifcfg-eth0

将 DEVICE="eth0"  改成  DEVICE="eth1"  ,
将 HWADDR="00:0c:29:8f:89:97" 改成上面的mac地址  HWADDR="00:0c:29:50:bd:17"

最后,重启网络

# /etc/init.d/network restart

正常了。

 

 

参考:

http://sunxy.blog.51cto.com/9357725/1723480/

http://www.linuxidc.com/Linux/2016-11/137137.htm