Background
Running the operating system under a virtual machine, especially a Linux system, is a very common practice. Sometimes you want to set up a (simulated) server under a virtual machine for host access, such as building a telnet/ssh. At this point you will find that every time you start a virtual machine, VMware assigns a dynamic IP to the virtual machine system, which makes it inconvenient to connect to the virtual machine's Telnet every time. It would be nice if it was set to a static IP.
VMnet8 and NAT
If your virtual machine is connected to the Internet in a NAT way, then the IP address of the virtual machine is not available, and the gateway and Internet access are provided by VMware's called VMnet8 Virtual network card. So all the settings related to setting up static IPs can be found here. Through the VMNET8 virtual network card, the host can access the virtual machine's IP, and the virtual machine can connect to the host's Internet connection into the extranet.
Confirm that the VMNET8 virtual network card is enabled
By default, VMWare workstation has enabled the VMNET8 virtual network card, under Windows 7, you can view the status of the virtual network card by going to Control Panel > Network and internet> Network and Sharing Center > changing adapter settings. As shown in 1-1.
Figure 1-1
Get the available IP range, gateway, and subnet mask
In the VMware main interface, click the Edit>virtual Network Editor menu to enter the virtual network card parameter Settings interface (Figure 1-2). Select the VMnet8 entry and click the NAT Settings button to see our VMware Workstation default gateway for NAT-connected virtual machines, here is 192.168.91.2, and the subnet mask, here is 255.255.255.0, As shown in 1-3.
Figure 1-2
Figure 1-3
Click the DHCP Settings button to see the range of available subnet IP VMnet8 assigned to the virtual machine, as shown in 1-4.
Figure 1-4
Here, our subnet IP available range is 192.168.91.128~192.168.91.254
OK, so far, all the information we need has been obtained, here is a summary,
-Subnet IP available range: 192.168.91.128~192.168.91.254
-Subnet Mask: 255.255.255.0
-Gateway: 192.168.91.2
Below begins to set the static IP into Ubuntu virtual machine.
Setting up a static IP in Ubuntu 12.04.1
1. Start the virtual machine Ubuntu system, open the terminal and use the following command to open and edit the network interface configuration file:
sudo vi/etc/network/interfaces
2. Edit the file as follows:
Auto loiface lo inet loopback# assgin static IP by Eric on 26-sep-2012iface eth0 inet staticaddress 192.168.91.200 #change To your static ipnetmask 255.255.255.0 #change to your netmaskgateway 192.168.91.2 #change to your getway#we must Specify Dns-nameserver here#in order to get internet access from Hostdns-nameservers 192.168.91.2auto eth0
Description
Address is the static IP address you want to assign to your virtual machine, and you can choose one of the available subnet IP ranges we just found here.
Netmask is a subnet mask
Gateway is gateways
Note: In a relatively early version, you need to set the resolv.conf file in/etc and add nameserver so that you can connect to the Internet. However, after Ubuntu 12.04, this is not recommended, because no matter what value you want to set in the configuration file, the restart will be reverted to its original state. The recommended practice is to add the Dns-nameserver < gateway Ip> Line directly to the interfaces configuration file.
3. Restart the Ubuntu network card
sudo/etc/init.d/networking restart
Configure a static IP (NAT) ping-through host for Ubuntu under VMware virtual machines