虚拟机配置静态ip

Posted by 小兵兵 on Friday, February 15, 2019

目录

镜像下载链接

https://wiki.centos.org/Download

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

1、克隆虚拟机

修改主机名

[root@192 桌面]# vim /etc/sysconfig/network
	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

	# 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 
	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

	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

简洁版

[zbiti@hadoop100 桌面]$ cat /etc/sysconfig/network-scripts/ifcfg-eth0 
DEVICE=eth0
TYPE=Ethernet
ONBOOT=yes
BOOTPROTO=static
IPADDR=192.168.1.100
GATEWAY=192.168.1.2
NETMASK=255.255.255.0
DNS1=8.8.8.8
DNS2=8.8.4.4