Running an operating system under a virtual machine, especially a Linux system, is already a very common practice. Sometimes you want to build a (simulated) server under a virtual machine for host access, such as setting up a telnet/ssh server. At this point, you will find that every time you start a virtual machine, VMWare assigns a dynamic IP address to the virtual machine system, which makes it inconvenient to connect to the virtual machine through telnet every time.
Running an operating system under a virtual machine, especially a Linux system, is already a very common practice. Sometimes you want to build a (simulated) server under a virtual machine for host access, such as setting up a telnet/ssh server. At this point, you will find that every time you start a virtual machine, VMWare assigns a dynamic IP address to the virtual machine system, which makes it inconvenient to connect to the virtual machine through telnet every time. Set static IP addresses.
VMnet8 and NAT
If your virtual machine is connected to the Internet through NAT, the IP address of the virtual machine is not configured, and the gateway and Internet access permissions are provided by the VMnet8 virtual network card provided by VMWare. All settings related to static IP settings can be found here. With the VMnet8 Virtual NIC, the host can access the IP address of the virtual machine, and the virtual machine can connect to the Internet of the host to connect to the Internet.
Make sure VMnet8 is enabled
By default, VMWare Workstation has enabled the VMnet8 Virtual NIC. in Windows 7, go to Control Panel> network and Internet> Network and Sharing Center> Change adapter settings to view the status of the virtual network card. 1-1.
-1
Obtain the available IP range, Gateway, and subnet mask.
On the VMWare main interface, click the Edit> Virtual NetworkEditor menu to go to the Virtual Nic parameter settings page (-2 ). Select the VMnet8 entry and click the NATSettings button. we can see that our VMWareWorkstation is the default gateway set for the virtual machine connected to the NAT gateway, 192.168.91.2, and subnet mask, as shown in 255.255.255.0, 1-3.
-2
-3
Click the DHCP Settings button to view the available subnet IP ranges allocated to the VM by VMnet8, as shown in Figure 1-4.
-4
Here, our subnet IP available range is 192.168.91.128 ~ 192.168.91.254
OK. Now, all the information we need has been obtained. here, we will summarize it,
-Available subnet IP addresses: 192.168.91.128 ~ 192.168.91.254
-Subnet mask: 255.255.255.0
-Gateway: 192.168.91.2
Next, enter the Ubuntu virtual machine to set the static IP address.
Set static IP in Ubuntu 12.04.1
1. start the Ubuntu system of the VM, 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 lo
Iface lo inet loopback
# Assgin static IP by eric on 26-SEP-2012
Iface eth0 inet static
Address 192.168.91.200 # change to your static IP
Netmask 255.255.255.0 # change to your netmask
Gateway 192.168.91.2 # change to your getway
# We must specify dns-nameserver here
# In order to get internet access from host
Dns-nameservers 192.168.91.2
Auto eth0
Description
Address is the static IP address you want to assign to your virtual machine. you can choose one from the available subnet IP range that we just found.
Netmask is a subnet mask.
Gateway is a gateway
Note:In earlier versions, you need to set the resolv. conf file under/etc and add nameserver to connect to the Internet. However, this method is not recommended after Ubuntu12.04, because no matter what value you want to set in the configuration file, it will be restored to the initial state after restart. We recommend that you add dns-nameserver directly to the interfaces configuration file. <网关ip> This line.
3. restart the ubuntu Nic
Sudo/etc/init. d/networking restart
4. ping to test Internet connectivity
Ping www.server110.com
If ping responds, congratulations. you have successfully set the virtual machine to a static IP address and connected to the Internet.