Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Summary of network settings of linux system in virtual machine

2025-03-26 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/03 Report--

Due to the use of redis and ZooKeeper in the project, a virtual machine was installed on the personal notebook today and a linux development environment was built. In the whole process, there is nothing to say about virtual machine installation, software installation and so on, that is, when setting up the linux system in the virtual machine to access the external network, either the external network can not be accessed or the ip is lost, so it is necessary to make a detailed description of the network setting of the linux system in the virtual machine for later use, and it is also convenient for other people who encounter the same problem to use for reference: after the installation of the virtual machine is completed. You can see three kinds of virtual networks: VMnet0, VMnet1 and VMnet8. Check out the figure:! [] (https://s1.51cto.com/images/blog/201806/28/b7d3dd45873cf74088194424dd72df1f.png?x-oss-process=image/watermark,size_16,text_QDUxQ1RP5Y2a5a6i,color_FFFFFF,t_100,g_se,x_10,y_10,shadow_90,type_ZmFuZ3poZW5naGVpdGk=)

These three kinds of networks are local connection, self-connection and NAT connection, respectively, which represent the strategy adopted by the operating system and external network in the virtual machine in the future. In addition, we can see from the network connection of the host (my personal laptop) that two virtual machine network cards have been generated:

Then some people will say, why is there no VMnet0 here? This is because of the connection of VMnet0, the virtual machine does not belong to the host and has the same status as the host, which is described in detail below.

These three network settings are described in detail below: first, VMnet0 is a local connection, also known as a bridge connection. This kind of connection is essentially a virtual machine, and the virtual machine and the host are in the same position and share the same local area network, and it will also occupy an ip; in the local network segment. At this time, the host connects to the external network and the virtual machine connects, which may be wired or wireless, depending on the specific circumstances of the host. To set up a virtual machine, use a bridge: right-click on the virtual machine-> Settings:! [] (execute the ipconfig command under the https://s1.51cto.com/images/blog/201806/28/4c20843ff3b5e967075c357e9bdd3244.png?x-oss-process=image/watermark,size_16,text_QDUxQ1RP5Y2a5a6i,color_FFFFFF,t_100,g_se,x_10,y_10,shadow_90,type_ZmFuZ3poZW5naGVpdGk=) host cmd Check (I am using) the wireless local area network IPRG! [] (https://s1.51cto.com/images/blog/201806/28/f14a747a734bb8499e2b24a619d06b8e.png?x-oss-process=image/watermark,size_16,text_QDUxQ1RP5Y2a5a6i,color_FFFFFF,t_100,g_se,x_10,y_10,shadow_90, Type_ZmFuZ3poZW5naGVpdGk=) the ip that is viewed by ifconfig in linux is also an IP ifconfig of the 31 network segment! [] (https://s1.51cto.com/images/blog/201806/28/8506ae27cbb0ae2aef81cd2d47c9ddda.png?x-oss-process=image/watermark,size_16,text_QDUxQ1RP5Y2a5a6i,color_FFFFFF,t_100,g_se,x_10,y_10,shadow_90,type_ZmFuZ3poZW5naGVpdGk=) at this time if the host is connected to the public network The virtual machine can also be connected to the external network. Second: VMnet1 is self-connected, the virtual machine can only communicate with the host, in the same network segment, its ip is one of the VMnet1 network segment; even if the host has an external network, the virtual machine is not connected to the external network. Set up the virtual machine to use self-connection. Execute ipconfig command under host cmd View the VMnet1 IP VMnet1! [] (the ip that https://s1.51cto.com/images/blog/201806/28/2f2536565bcf3c6712b1c2c5b3d11ee6.png?x-oss-process=image/watermark,size_16,text_QDUxQ1RP5Y2a5a6i,color_FFFFFF,t_100,g_se,x_10,y_10,shadow_90,type_ZmFuZ3poZW5naGVpdGk=) performs ifconfig to view in linux is also an IP VMnet1 of 17 network segments! [] (https://s1.51cto.com/images/blog/201806/28/102923281ed78b987d5898fdbc938672.png?x-oss-process=image/watermark, Size_16,text_QDUxQ1RP5Y2a5a6i,color_FFFFFF,t_100,g_se,x_10,y_10,shadow_90,type_ZmFuZ3poZW5naGVpdGk=) at this time, even if the host is connected to the external network The virtual machine also cannot connect to the external network. Third: the VMnet8 is a NAT connection, and the virtual machine takes the host ip as the external network ip, and on this basis, a network and a network segment are virtualized; if the host has an external network, the virtual machine can also connect to the external network. The connection principle is to find the host gateway from the virtual machine, and then find the external network gateway outside the host. Set up the virtual machine to use NAT connection. Execute ipconfig command under cmd View the VMnet8 IP VMnet8! [] (the ip that https://s1.51cto.com/images/blog/201806/28/3610bf29af10468950d10c6371e5ed11.png?x-oss-process=image/watermark,size_16,text_QDUxQ1RP5Y2a5a6i,color_FFFFFF,t_100,g_se,x_10,y_10,shadow_90,type_ZmFuZ3poZW5naGVpdGk=) performs ifconfig to view in linux is also an IP VMnet8 of the 248Net segment! [] (https://s1.51cto.com/images/blog/201806/28/6d9b79bafb37137a41c2ca2313fc1176.png?x-oss-process=image/watermark, Size_16,text_QDUxQ1RP5Y2a5a6i,color_FFFFFF,t_100,g_se,x_10,y_10,shadow_90,type_ZmFuZ3poZW5naGVpdGk=) at this time, if the host is connected to the external network The virtual machine can also be connected to the external network. As for which one we use in the actual development process, it is determined by our own use cases. When there is an external network, we use more VMnet0 and VMnet8. If we do not need to use the external network and do not want to be disturbed by the external network, we use VMnet1.

For VMnet1 and VMnet8, we can also set information such as ip:

There is another unexpected situation. After the linux system is installed in the virtual machine, if you execute ifconfig without an ip address, you can execute the command dhclient ens33;, but although you can generate ip this time, but the next time you start linux without ip, if you want to generate ip automatically every time:

Enter / etc/sysconfig/network-scripts/

Modify ONBOOT=no in ifcfg-ens33 to ONBOOT=yes with vi

Save and exit

Restart the network service service network restart

Here are some situations that I have encountered, which are listed here in detail, hoping to be helpful to my friends. Of course, please forgive me for any inadequacies.

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: 0

*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.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report