Graphic tutorial on setting a fixed IP address for Ubuntu in vmvm

Source: Internet
Author: User
The virtual machine sets the internet access mode to NAT, which is the most convenient, because you do not need to manually set up the Internet access, but the NAT Internet access mode is by default DHCP dynamic allocation of IP, this means that you have different IP addresses each time you restart the virtual machine, which has no problem label for general users: Ubuntu

However, if your host is of special use, for example, as a server, you need IP address information or, like me, as a cloud computing node, its IP address is configured in the configuration file, if you have to modify the IP address in the configuration file every time you restart the system, it is simply not desirable. Therefore, it is necessary to set a fixed IP address for the VM to access the internet!
There are many ways to set a fixed IP address. we all know that there are three modes for VM access: bridged, host-only, and NAT. The NAT mode corresponds to the VMnet8 virtual network, and the host-only mode corresponds to the VMnet1 virtual network, the bridged mode corresponds to the VMnet0 virtual network, which is generated by the automatic configuration of the vmwarevm and does not need to be set by the user. VMnet8 and VMnet1 provide DHCP services, while VMnet0 does not.
Because the NAT method is the simplest, the following describes how to configure NAT.
Test environment:
Virtual Machine version: VMware Workstation 10
Ubuntu 12.10/13.04
1. set the VM access mode to NAT

2. configure VMnet8 Virtual Network Editor)
Because NAT corresponds to the VMnet8 Virtual Network, open the Virtual Network Editor, which comes with Vmware. the configuration is as follows:

Set the subnet IP address as needed. for example, if you want to set the fixed IP address to 192.168.1.151, enter 192.168.1.0 as the subnet IP address. In addition, remember to cancel the DHCP option service.


3. go to the Ubuntu system to configure the network
Configure the following three aspects:
(1) modify the file/etc/network/interfaces. Here are some configurations of IP address, Gateway, mask, etc;
(2) modify the/etc/resolv. conf file to save DNS information;
(3) solve the resolv. conf rewriting problem;
(4) restart the virtual machine network

The specific configuration method is as follows:
(1) modify the file/etc/network/interfaces
Command:

Copy codeThe code is as follows:
Sudo vi/etc/network/interfaces
Or
Sudo gedit/etc/network/interfaces

My configuration is as follows:

Copy codeThe code is as follows: # interfaces (5) file used by ifup (8) and ifdown (8)
Auto lo
Iface lo inet loopback
Auto eth0

Iface eth0 inet static
Address 192.168.1.151
Netmask 255.255.255.0
Gateway 192.168.1.2
The gateway must be consistent with the "NAT Settings..." in the Virtual Network Editor. generally, it seems to be 192.168.xx.2.

(2) modify the/etc/resolv. conf file.
Command:

Copy codeThe code is as follows: sudo vi/etc/resolv. conf
Or
Sudo gedit/etc/resolv. conf [code]
My configuration is as follows:
[Code] nameserver 202.38.64.1
Of course, this varies from person to person. just add your own DNS server, and my on-campus DNS is used.

(3) solve the resolv. conf rewriting problem
In step 2, although you have configured DNS, after you restart the virtual machine or restart the network,/etc/resolv. the conf file will be overwritten, that is, it will be restored to its original state, and your previous configuration will not exist. manual configuration every time is required, so this step is necessary, first, we need to figure out resolv. the reason and mechanism for conf being overwritten are different in different Ubuntu versions. How can we know? Generally, the resolv. conf file will tell you at the beginning.
There are actually two ways to solve this problem. if you are not afraid of trouble and want to understand the principle, refer to Method 1 (related to the version ), if you are in trouble, you don't want to go to Method 2 (it has nothing to do with the version ).

Method 1: related to version
A) Ubuntu 12.10
Open/etc/resolv. conf and you will see the first sentence:

Copy codeThe code is as follows: # Generated by NetworkManager
Note that the resolv. conf file is generated by the NetworkManager program (corresponding to the network-manager service). The solution is as follows: we can turn off the network-manager file and run the following command:

Copy codeThe code is as follows: sudo service network-manager stop
Or
Sudo/etc/init. d/network-manager stop
However, this method does not work once and for all, because the service will be automatically started every time the system is restarted, so we need to completely disable network-manager to start.
Edit the network manager configuration file/etc/init/network-manager.conf:

Copy codeThe code is as follows: sudo vi/etc/init/network-manager.conf
Just comment out the start on section:

Copy codeThe code is as follows: # network-manager-network connection manager
#
# The Network Manager daemon manages the system's network connections,
# Automatically switching between the best available.

Description "network connection manager"

# Start on (local-filesystems
# And started tables
# And static-network-up)
Stop on stopping restart

Wrong CT fork
Respawn

Script
# Set $ LANG so that messages appearing on the GUI will be translated. See LP: 875017
If [-r/etc/default/locale]; then
./Etc/default/locale
Export lang language LC_MESSAGES LC_ALL
Fi

B) Ubuntu 13.04
I do not know which version of Ubuntu is not from which NetworkManager generates resolv. conf, at least in 13.04, because resolv. conf starts with the following sentence:

Copy codeThe code is as follows: # Dynamic resolv. conf (5) file for glibc resolver (3) generated by resolvconf (8)
# Do not edit this file by hand -- YOUR CHANGES WILL BE OVERWRITTEN
It is generated by resolvconf, and NetworkManager still exists because it is indispensable for DHCP to access the internet. However, disabling NetworkManager to start is no longer a problem because resolv. conf is no longer owned by it. let's take a look at resolv. what is the relationship between conf and resolvconf? view:

Copy codeThe code is as follows: hadoop @ Master :~ $ Ll/etc/resolv. conf
Lrwxrwxrwx 1 root 29 August 29, September 11 2013/etc/resolv. conf-> ../run/resolvconf/resolv. conf
Description:/etc/resolv. conf is actually a link. it actually points to/run/resolvconf/resolv. conf, which explains why it will be overwritten every time you restart. you only change the link, which has no effect on the original file, and you have to load the content of the original file every time you restart the link, the link modification is invalid.
Solution: modify the original file as follows:

Copy codeThe code is as follows: sudo vi/etc/resolvconf/resolv. conf. d/head
This file is exactly the same as the/etc/resolv. conf file. you can add your own nameserver to it so that it will not be overwritten after each restart.
PS: some people on the Internet also say that modifying the/etc/resolvconf/resolv. conf. d/base file is fine. I did not test it myself. if you are interested, you can test it on your own.

Having said so much, the differences between different versions seem quite troublesome. I don't know if the latest or later versions will change, in fact, there is a simpler version-independent method to prevent resolv. the conf file is overwritten, that is, Method 2.
Method 2: version-Independent
As mentioned above, the fixed IP address is mainly used to modify the/etc/network/interfaces file and configure the IP address and Gateway. In fact, there is a parameter that can be configured, that is, DNS, the corresponding parameter is dns-nameservers. the priority set here is higher than resolv. the conf is high, that is, the network reads the DNS configuration from here. if it is not configured, the resolv will be viewed. conf, so it is easier to configure DNS here.

Copy codeThe code is as follows: # interfaces (5) file used by ifup (8) and ifdown (8)
Auto lo
Iface lo inet loopback
Auto eth0

Iface eth0 inet static
Address 192.168.1.151
Netmask 255.255.255.0
Gateway 192.168.1.2
Dns-nameservers 202.38.64.1
(4) restart the virtual machine network
After the configuration is complete, restart the network. There are also several methods:

Copy codeThe code is as follows: sudo service networking restart
Or
Sudo/etc/init. d/networking restart
You can also restart the NIC:

Copy codeThe code is as follows: sudo ifconfig eth0 down
Sudo ifconfig eth0 up
Restarting the NIC does not affect other NICs. we recommend that you restart the NIC.
Ping www.baidu.com. you should be able to access the Internet.

PS: of course, you can also configure it through the graphic interface network manager, but I personally think this method is the best, so we recommend it!

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.