VMware virtual machine Linux system NAT mode network configuration and virtual machine cloning essentials

VMware virtual machine and Linux system have actually been installed many times, but I have always searched for a fool-like tutorial on the Internet, and then installed it almost without thinking.
Whether it is VMware itself, or installing a virtual machine in VMware, or installing a Linux system in a virtual machine, it should be relatively simple.
However, many times I have installed it, as well as some other colleagues I have learned about, and I often get stuck on the network. After the installation is over, I can’t connect to the Internet, and then I may continue to search and try again. In fact, it’s all blind people touching the elephant. Once again, there were various problems.
In the previous installation, the network was in the bridge mode. This time, I chose the NAT mode according to a certain tutorial. The difference from the previous one is that the content mastered this time can ensure that future installations will no longer be troubled by the network.

The network configuration itself, whether it is windows or Linux, is actually divided into two steps. The first step is to find the location of the network card configuration, and the second step is to configure the network.

Network configuration in windows

Windows is accustomed to the operation of the graphical interface, the general steps are:

  1. The location of the network icon in the lower right corner of the computer, right-click and select "Open network and internet settings";
  2. Choose Ethernet or other specific network types;
  3. Choose to change the adapter option;
  4. There are many network card configurations in the above interface. If you choose Ethernet, double-click to open the Ethernet item;
  5. Click Properties, and then double-click "Internet Protocol Configuration 4", here is the configuration of ipv4.
  6. In the ipv4 configuration interface, you can choose to automatically obtain the ip address and dns address, or manually configure the static ip and dns.

The first three parts above can be understood as finding the location of the network card configuration, and the last three steps can be understood as the configuration of the network card. For the windows system, I didn't pay much attention to this detail. It seems that the default automatic acquisition can be configured without configuration.

Linux network configuration in VMware

The Linux system also has a graphical interface, but for most of us who use this system, they may be more accustomed to and more accustomed to command line operations.
In the command line operation mode, the network card configuration is still divided into two steps, the same as windows, to find the network card configuration location and configure the network.

Network card configuration file location

The location of the network card configuration file in the lcentos system is in the /etc/sysconfig/network-scripts directory. For personal use, just use the ifcfg-eth0 file.

Network Configuration

Just installed the Linux system, open the network card configuration above, the content is as follows:

DEVICE=eth0
HWADDR=00:0C:29:A4:2A:31
TYPE=Ethernet
UUID=da6741e2-9b2c-464f-9a5b-cbe65402e21c
ONBOOT=no
NM_CONTROLLED=yes
BOOTPORTO=dhcp

The meanings of the above items are as follows:

DEVICE:网卡的名字
HWADDR:HWADDR HardWare Address 硬件地址 MAC地址
TYPE:网络类型 Ethernet以太网
UUID:唯一编号
ONBOOT:在开机或重启网卡的时候是否启动网卡
NM_CONTROLLED:是否受network程序管理
BOOTPROTO:网卡获取ip地址的方式,分为dhcp自动获取ip地址,none固定的ip地址,static固定的ip地址

For the above configuration, to change to NAT mode, first change the value of ONBOOT to yes, and then change the ip acquisition method to static, that is, static.
If you need to clone the current virtual machine later, it is best to delete both HWADDR and UUID . These two are themselves to ensure the uniqueness of the virtual machine network. If they are not deleted, the cloned network card and the unique number will be duplicated, which may result in failure to access the Internet.

After the above modification last night, since it is a static ip, you need to do static ip-related configuration, and you need to add four more configurations:

IPADDR:设置的静态IP
NETMASK:子网掩码
GATEWAY:网关
DNS:dns解析地址

For the above four configurations, DNS is a better choice. Generally 114.114.114.114, this is the first open DNS service address in China and the third in the world.
Multiple DNS can be configured, so it can be configured here DNS1=114.114.114.114.

How to configure the remaining few is more critical. To set a static IP, you must know what the network segment is and which IPs are available.
At this time, you can use the function of VMware to get it, as shown in the following figure:
Insert picture description here
First click on the edit at No. 1, and the No. 2 interface on the right will pop up, then at No. 3, choose to change the settings as an administrator, and then the next pop up After clicking OK, the following interface will appear: In the
Insert picture description here
figure above, you need to select the NAT mode at the top, and then you will see a subnet IP 192.168.139.0, which proves that our network is actually in this network segment and 192.168.139.0 It is used.
Then at No. 2, is the subnet mask we need, then we can modify the configuration NETMASK=255.255.255.0of.
Next, click "NAT Settings" at No. 3, and you will see the following pop-up interface:
Insert picture description here
In the position where the icon is red, you can actually see the subnet ip and subnet mask above. At the same time, we can also find the gateway we need. Then the configuration can be further improved GATEWAY=192.168.139.2, and it also means that there is another ip of the current network segment that we cannot use ourselves.
At this point, it seems that you can configure a static IPADDR. In fact, there is a little problem, as shown in the figure below:
Insert picture description here
The position of number 4 will connect the network of the actual physical machine with the network of the virtual machine, and create one on the physical machine. Virtual network card, that is, VMnet8: After
Insert picture description here
double-clicking to open it, clicking on the details will find that there is an ip inside 192.168.139.1, which represents the ip of the host virtual network card, which means that we can’t use this ip either.
Therefore, it is finally confirmed that the IP network segment to be configured is 192.168.139, and the final IP cannot be 255, 0, 1, 2, and after selecting an IP less than 255 in addition to these numbers, the complete network configuration can be modified as follows:

DEVICE=eth0
HWADDR=00:0C:29:A4:2A:31
TYPE=Ethernet
UUID=da6741e2-9b2c-464f-9a5b-cbe65402e21c
ONBOOT=yes
NM_CONTROLLED=yes
BOOTPORTO=static
DNS1=114.114.114.114
NETMASK=255.255.255.0
GATEWAY=192.168.139.2
IPADDR=192.168.139.99

After the above configuration is saved, execute the network card restart command service network restart, the virtual machine can successfully surf the Internet and can be used ping www.baidu.comfor verification.

The above are the steps and techniques of NAT mode network configuration in the Linux system in VMware. I believe that with this configuration, there is no need to worry about the problem of virtual machine Internet access, and I hope it can be helpful to other students.

Virtual machine cloning in VMware

Learning big data technology often requires multiple virtual machine nodes. If each one is installed in the usual steps, it will be time-consuming, so a more convenient way is to clone an existing virtual machine.
Before cloning, it is best to take a snapshot of the source virtual machine, and then clone it again.
After the cloned virtual machine, no matter the network card, ip or hostname is exactly the same as the original one, this is problematic, so in fact, the new virtual machine system configuration needs to be modified after cloning.
From the above network configuration, it is only known that the IPADDR that is not working needs to be modified. If you need to modify these two items without deleting the physical network card and UUID, it is best to delete them.
In addition, the hostname must be modified. Those who have used Kafka may know that this hostname is very important, and this configuration is in the /etc/sysconfig/networkfile.
The last place that needs to be modified is still related to the physical network card. You need to delete /etc/udev/rules.dthe 70-persistent-net.rules file in the directory. After deletion, the file will be regenerated when the network card is restarted, and it will not be the same as the cloned one. This kind of network problem can be avoided.

Guess you like

Origin blog.csdn.net/tuzongxun/article/details/107031865