VMWARE中的UBUNTU虚拟机设置静态IP通过NAT上网的方法
<p><span style='font-family: tahoma, arial, "Microsoft YaHei"; font-size: 14px;'>在http://blog.csdn.net/dctfjy/article/details/4233284中找到了解决办法: </span></p>
<div class="msgheader" style='margin: 3px auto 0px; padding: 0px 3px; outline: none; line-height: 21.6px; clear: both; border-width: 1px; border-style: solid; border-color: rgb(0, 153, 204); background: rgb(246, 251, 255); overflow: hidden; font-family: tahoma, arial, "Microsoft YaHei";'>
<p class="right">
<span><u>复制代码</u></span></p>
<p>
代码如下:</p>
</div>
<p class="msgborder" style='margin: 0px auto 3px; padding: 0px 3px; outline: none; line-height: 25.2px; font-size: 14px; clear: both; border-right: 1px solid rgb(0, 153, 204); background: rgb(221, 237, 251); overflow: hidden; border-left: 1px solid rgb(0, 153, 204); word-break: break-all; border-bottom: 1px solid rgb(0, 153, 204); word-wrap: break-word; font-family: tahoma, arial, "Microsoft YaHei";'>
<br>
移动/删除rules文件。(未验证) <br>
重启后Ubuntu会创建新的rules文件。 <br>
将新网卡辨认为eth0,沿用原eth0的网络配置。 <br>
如果网络配置是自动获取IP,则无需做其他修改。 <br>
sudo mv /etc/udev/rules.d/70-persistent-net.rules /etc/udev/rules.d/70-persistent-net.rules.old </p>
<p>
<br style='font-family: tahoma, arial, "Microsoft YaHei"; font-size: 14px;'><span style='font-family: tahoma, arial, "Microsoft YaHei"; font-size: 14px;'>重启之后,网络正常了。 </span><br style='font-family: tahoma, arial, "Microsoft YaHei"; font-size: 14px;'><span style='font-family: tahoma, arial, "Microsoft YaHei"; font-size: 14px;'>接下来是设置静态IP。一般来说,用NAT连接时,虚拟系统一般设置为DHCP,动态获取IP地址的。但是由于某些情况下,我们需要它是一个静态IP,方便我们进行管理和操作。那有没有办法呢?有的! </span><br style='font-family: tahoma, arial, "Microsoft YaHei"; font-size: 14px;'><span style='font-family: tahoma, arial, "Microsoft YaHei"; font-size: 14px;'>NAT网络中,相当于虚拟机的网卡和主机的VMware Network Adapter VMnet8虚拟网卡连接到虚拟机软件提供的VMnet8虚拟交换机上,因此主机是通过VMware Network Adapter VMnet8这个虚拟网卡通信的,并且可以知道VMware Network Adapter VMnet8就只是主机用来和虚拟机通信的一个虚拟网卡。在这种网络结构中,VMware为虚拟机提供了一个虚拟的NAT服务器和一个虚拟的DHCP服务器(其实就是主机系统服务中的两个服务),虚拟机便是利用这两个服务连接到Internet的,所以正常情况下,虚拟机系统只要设定自动获得IP就可以上网了。 </span><br style='font-family: tahoma, arial, "Microsoft YaHei"; font-size: 14px;'><span style='font-family: tahoma, arial, "Microsoft YaHei"; font-size: 14px;'>于是查看了VMware中虚拟交换机VMnet8的属性和虚拟网卡VMware Network Adapter VMnet8的NAT属性,发现VMnet8是处在192.168.110.0子网中,并且VMware中查看到VMware Network Adapter VMnet8的GATEWAY是192.168.110.2(edit->virtual network editor->选择VMnet8->点击nat setting就会发现gateway了),经过实验后,发现虚拟机使用DHCP时查看到的GATEWAY也是这地址,这个地址应该就是那个虚拟的NAT服务器的地址。所以这时我的虚拟机要设置静态IP,网关就是192.168.110.2。 </span><br style='font-family: tahoma, arial, "Microsoft YaHei"; font-size: 14px;'><span style='font-family: tahoma, arial, "Microsoft YaHei"; font-size: 14px;'>同时,为了保证虚拟机和主机的通信,虚拟机的IP需要和主机的VMware Network Adapter VMnet8网卡在同一网段,VMware Network Adapter VMnet8的IP是安装VMware时自动分配的,在我的电脑上查看到的是192.168.110.1。于是,设置虚拟机的IP为 192.168.110.172。DNS仍然是我的主机用的DNS服务器,就是学校网络中心的202.118.192.2。 </span><br style='font-family: tahoma, arial, "Microsoft YaHei"; font-size: 14px;'><span style='font-family: tahoma, arial, "Microsoft YaHei"; font-size: 14px;'>设置结果为: </span><br style='font-family: tahoma, arial, "Microsoft YaHei"; font-size: 14px;'><span style='font-family: tahoma, arial, "Microsoft YaHei"; font-size: 14px;'>vi /etc/network/interfaces </span></p>
<div class="msgheader" style='margin: 3px auto 0px; padding: 0px 3px; outline: none; line-height: 21.6px; clear: both; border-width: 1px; border-style: solid; border-color: rgb(0, 153, 204); background: rgb(246, 251, 255); overflow: hidden; font-family: tahoma, arial, "Microsoft YaHei";'>
<p class="right">
<span><u>复制代码</u></span></p>
<p>
代码如下:</p>
</div>
<p class="msgborder" style='margin: 0px auto 3px; padding: 0px 3px; outline: none; line-height: 25.2px; font-size: 14px; clear: both; border-right: 1px solid rgb(0, 153, 204); background: rgb(221, 237, 251); overflow: hidden; border-left: 1px solid rgb(0, 153, 204); word-break: break-all; border-bottom: 1px solid rgb(0, 153, 204); word-wrap: break-word; font-family: tahoma, arial, "Microsoft YaHei";'>
<br>
# This file describes the network interfaces available on your system <br>
# and how to activate them. For more information, see interfaces(5). <br>
# The loopback network interface <br>
auto lo <br>
iface lo inet loopback <br>
# The primary network interface <br>
auto eth0 <br>
iface eth0 inet static <br>
address 192.168.110.172 <br>
gateway 192.168.110.2 <br>
netmask 255.255.0.0 </p>
<p>
<br style='font-family: tahoma, arial, "Microsoft YaHei"; font-size: 14px;'><span style='font-family: tahoma, arial, "Microsoft YaHei"; font-size: 14px;'>重启网卡:/etc/init.d/networking restart </span><br style='font-family: tahoma, arial, "Microsoft YaHei"; font-size: 14px;'><span style='font-family: tahoma, arial, "Microsoft YaHei"; font-size: 14px;'>这样设置完成后,虚拟机就既能和主机通信,又能连接到Internet了。其中,虚拟机和主机通信是由其IP决定的,IP和主机的虚拟网卡 VMware Network Adapter VMnet8的IP一致,连接到Internet则是利用了VMware提供的NAT服务为虚拟交换机VMnet8作路由,也就是网关设置为虚拟NAT服务器的地址。这里,由于用了静态IP,所以没有用到VMware的DHCP服务。 </span><br style='font-family: tahoma, arial, "Microsoft YaHei"; font-size: 14px;'><span style='font-family: tahoma, arial, "Microsoft YaHei"; font-size: 14px;'>其实说了这么多,重点无非就是要获取网关等信息而已,知道了这些,和其他的静态IP设置没有区别。</span></p>
頁:
[1]