VMware CentOS6.5 设置固定IP

时间:2022-10-27 18:14:53

之前在VMware上使用CentOS6.5一直都是采用动态IP,IP经常变化,很麻烦,这次在网上找了一些资料,结合自己的实践,将设置固定IP的过程记录下来。

1、查看网关

VMware-->Edit-->Virtual Network Editor-->VMnet8 NAT-->NAT Settings-->Gateway IP:192.168.211.2

记录下网关IP:192.168.211.2

VMware CentOS6.5 设置固定IP

2、修改文件/etc/sysconfig/network

NETWORKING=yes 
NETWORKING_IPV6=no
GATEWAY=192.168.211.2
HOSTNAME=localhost.localdomain

3、修改文件/etc/sysconfig/network-scripts/ifcfg-eth0
这里主要指定IP获得方式(static),ip地址,子网掩码,网络类型

DEVICE="eth0"
#BOOTPROTO=dhcp
BOOTPROTO=static
#IPV6INIT="yes"
IPV6INIT="no"
NM_CONTROLLED="yes"
ONBOOT="yes"
IPADDR=192.168.1.103
NETMASK=255.255.255.0
TYPE="Ethernet"
UUID="8bed547a-efc2-4c72-80e4-c86b97bfb103"
DEFROUTE=yes
IPV4_FAILURE_FATAL=no
#IPV6_AUTOCONF=yes
#IPV6_DEFROUTE=yes
#IPV6_FAILURE_FATAL=no
NAME="System eth0"
HWADDR=00:0C:29:7C:8B:56
PEERDNS=yes
PEERROUTES=yes
#IPV6_PEERDNS=yes
#IPV6_PEERROUTES=yes
LAST_CONNECT=1408077824
DNS1=192.168.211.2

4、修改文件/etc/resolv.conf

# Generated by NetworkManager
nameserver 192.168.211.2

5、重启网络

[root@bogon etc]# service network restart
Shutting down interface eth0: Device state: 3 (disconnected)
[ OK ]
Shutting down loopback interface: [ OK ]
Bringing up loopback interface: [ OK ]
Bringing up interface eth0: Active connection state: activated
Active connection path: /org/freedesktop/NetworkManager/ActiveConnection/6
[ OK ]

6、查看IP地址

[root@bogon etc]# ifconfig
eth0 Link encap:Ethernet HWaddr 00:0C:29:7C:8B:56
inet addr:192.168.1.103 Bcast:192.168.1.255 Mask:255.255.255.0
inet6 addr: fe80::20c:29ff:fe7c:8b56/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:20362 errors:0 dropped:0 overruns:0 frame:0
TX packets:15250 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:28119213 (26.8 MiB) TX bytes:1087310 (1.0 MiB)
Interrupt:19 Base address:0x2000

lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
inet6 addr: ::1/128 Scope:Host
UP LOOPBACK RUNNING MTU:16436 Metric:1
RX packets:8 errors:0 dropped:0 overruns:0 frame:0
TX packets:8 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:480 (480.0 b) TX bytes:480 (480.0 b)

可以看到,IP地址已改成192.168.1.103,这是个固定IP
7、CentOS6.5网络连接类型要改成Bridged

VMware-->VM-->Setting-->Network Adapter-->Bridged

这样虚拟机上的CentOS6.5就可以与外界进行连通了。