虚拟机配置静态ip

镜像下载链接

https://wiki.centos.org/Download

环境:
CentOS-6.8-x86_64-bin-DVD1.iso

1、克隆虚拟机

修改主机名

[root@192 桌面]# vim /etc/sysconfig/network
1
2
NETWORKING=yes
HOSTNAME=192.168.1.104

修改网卡信息

[root@192 桌面]# vim /etc/udev/rules.d/70-persistent-net.rules

删除或者注释eth0该行;将eth1修改为eth0,同时复制物理ip地址00:0c:29:ac:81:e4

1
2
3
4
5
6
7
8
9
10
11
12
# 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 0x8086:0x100f (e1000)
#SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="00:0c:29:00:88:b3", ATTR{type}=="1", KERNEL=="eth*", NAME="eth0"

# PCI device 0x8086:0x100f (e1000)
SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="00:0c:29:ac:81:e4", ATTR{type}=="1", KERNEL=="eth*", NAME="eth0"
[root@192 桌面]#

更新物理ip地址HWADDR=00:0c:29:ac:81:e4

[root@192 桌面]# vim /etc/sysconfig/network-scripts/ifcfg-eth0 
1
2
3
4
5
6
7
DEVICE=eth0
HWADDR=00:0c:29:ac:81:e4
TYPE=Ethernet
UUID=55735d7f-16c6-46fe-9db8-f7d484b3e7c0
ONBOOT=none
NM_CONTROLLED=yes
BOOTPROTO=dhcp

2、NAT模式配置

编辑–虚拟网络编辑器

配置静态ip网段和子网掩码

NAT设置

网关ip不能和vmnet8的ip地址冲突

宿主机上的vmnet8网卡会自动分配ip

3、配置静态ip

ONBOOT=yes系统启动时激活网卡
BOOTPROTO=static通过指定方式的办法来获得地址,设置为静态手动配置
IPADDR=192.168.1.104主机ip地址
GATEWAY=192.168.1.2网关
NETMASK=255.255.255.0子网掩码
DNS1=8.8.8.8配置DNS域名解析访问互联网
DNS2=8.8.4.4

1
2
3
4
5
6
7
8
9
10
11
12
DEVICE=eth0
HWADDR=00:0c:29:ac:81:e4
TYPE=Ethernet
UUID=55735d7f-16c6-46fe-9db8-f7d484b3e7c0
ONBOOT=yes
NM_CONTROLLED=yes
BOOTPROTO=static
IPADDR=192.168.1.104
GATEWAY=192.168.1.2
NETMASK=255.255.255.0
DNS1=8.8.8.8
DNS2=8.8.4.4