In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/01 Report--
This article will explain in detail how to set up fixed IP Internet access in Ubuntu VM virtual machine. The content of the article is of high quality. Therefore, Xiaobian shares it with you as a reference. I hope you have a certain understanding of relevant knowledge after reading this article.
However, if your machine has special uses, such as a server, IP address information is needed, or like me, as a cloud computing node, its IP is configured in the configuration file, if every time you restart the system, you have to run to modify the IP in the configuration file, it is simply not advisable. Therefore, it is necessary to set a fixed IP for the virtual machine to access the Internet!
There are many ways to set a fixed IP. As we all know, there are three modes for virtual machine Internet access: bridged, host-only, and NAT. NAT mode corresponds to VMnet8 virtual network, host-only mode corresponds to VMnet1 virtual network, and bridged mode corresponds to VMnet0 virtual network. All of them are generated by VMware virtual machine automatic configuration and do not need to be set by users themselves. VMnet8 and VMnet1 offer DHCP services, while VMnet0 virtual networks do not.
Because NAT is the simplest way, here is how to set up NAT:
Test environment:
Virtual machine version: VMware Workstation 10
Ubuntu Version: Ubuntu 12.10/13.04
1. Set the virtual machine Internet access mode to NAT
2. Configure VMnet8 Virtual Network Editor
Because NAT corresponds to VMnet8 virtual network, open Virtual Network Editor, which comes with VMware. The configuration is as follows:
The subnet IP is set according to your own situation. For example, if I want to set the fixed IP address to 192.168.1.151, then the subnet IP here will be 192.168.1.0. Also, remember to cancel the DHCP option service.
3. Go to Ubuntu to configure the network
The following three aspects are mainly configured:
(1) Modify the file/etc/network/interfaces, which is some configuration of IP, gateway, mask, etc.;
(2) Modify the file/etc/resolv.conf, which stores information about DNS;
(3) Solve the problem of resolv.conf being rewritten;
(4) Restart the virtual machine network
The following is the specific configuration method:
(1) Modify the file/etc/network/interfaces
Command:
The code is as follows:
sudo vi /etc/network/interfaces
or
sudo gedit /etc/network/interfaces
My configuration is as follows:
The 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 should be compatible with NAT Settings in Virtual Network Editor. "In general, it seems to be 192.168.xx.2.
(2) Modify the file/etc/resolv.conf
Command:
The 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 is different from person to person, plus your own DNS server can be, mine is the school DNS.
(3) Solve resolv.conf rewriting problem
In the second step, although you configured DNS, but every time you restart the virtual machine or restart the network, the/etc/resolv.conf file will be rewritten, that is, it will be restored to its original state. Your previous configuration does not exist. It is extremely undesirable to manually configure it every time, so this step is necessary. First of all, we have to figure out the reasons and mechanisms for resolv.conf to be rewritten. This varies under different Ubuntu versions. How do we know? The resolv.conf file usually tells you at the beginning.
There are actually two ways to solve this problem. Those who are not afraid of trouble and want to understand the principle please refer to Method 1 (related to the version). Those who are afraid of trouble and do not want to toss consciously go to Method 2 (unrelated to the version).
Method 1: Version-related
a)Ubuntu 12.10
Open/etc/resolv.conf and you'll see the first sentence:
The code is as follows:
# Generated by NetworkManager
Description resolv.conf This file is generated by NetworkManager this program (corresponding to the network-manager service), then the solution also comes: we can turn off the network-manager, the command is as follows:
The code is as follows:
sudo service network-manager stop
or
sudo /etc/init.d/network-manager stop
However, this method is not one-off, because this service will automatically start after each restart of the system, so we need to completely prohibit network-manager startup.
Edit the network manager configuration file/etc/init/network-manager.conf:
The code is as follows:
sudo vi /etc/init/network-manager.conf
Note out the start on part:
The 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 dbus
# and static-network-up)
stop on stopping dbus
expect 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 don't know which version of Ubuntu isn't resolv.conf generated by NetworkManager, at least in 13.04, because resolv.conf begins with this sentence:
The 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
Said to be generated by resolvconf, NetworkManager still exists, because it is indispensable for DHCP Internet access, but at this time prohibit NetworkManager startup has no effect, because resolv.conf has not been under its control, we try to see what resolv.conf has to do with resolvconf, see:
The code is as follows:
hadoop@Master:~$ ll /etc/resolv.conf
lrwxrwxrwx 1 root root 29 Sep 11 2013 /etc/resolv.conf -> ../ run/resolvconf/resolv.conf
Note/etc/resolv.conf is actually just a link, it actually points to/run/resolvconf/resolv.conf, which explains why every restart will be rewritten, you change only a link, has no effect on the original file, and each restart of this link also has to load the contents of the original file, so the modification of the link is invalid.
The solution is to modify the real original file as follows:
The code is as follows:
sudo vi /etc/resolvconf/resolv.conf.d/head
Found this file and/etc/resolv.conf file exactly the same, this is correct, in which you can add your own nameserver, so that each restart will not be rewritten.
PS: Some people on the Internet also say that modifying the file/etc/resolvconf/resolv.conf.d/base is also OK. I didn't test it myself. Interested parties can test it themselves.
Having said that, the differences between the versions seem to be quite troublesome. I don't know if the latest version or future versions will change again. In fact, there is a simpler version-independent way to prevent the resolv.conf file from being rewritten. That is Method 2.
Method 2: Version-independent
As mentioned above, the fixed IP Internet access method is mainly to modify the/etc/network/interfaces file, configure IP, gateway or something, in fact, there is a parameter that can be configured, that is DNS, the corresponding parameter name is dns-nameservers, the priority set here is higher than resolv.conf, that is, the network will read DNS configuration from here, if not configured to see the settings in resolv.conf, so it is easier to configure DNS here.
The 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 ways:
The code is as follows:
sudo service networking restart
or
sudo /etc/init.d/networking restart
You can also restart the network card:
The code is as follows:
sudo ifconfig eth0 down
sudo ifconfig eth0 up
Restart the network card has no effect on other network cards, more recommended some.
Please ping www.baidu.com, you should be able to surf the Internet.
How to set up fixed IP Internet access in Ubuntu VM virtual machine is shared here. I hope the above content can be of some help to everyone and learn more knowledge. If you think the article is good, you can share it so that more people can see it.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 298
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un