1. Problem BackgroundAccording to my usual settings, I use bridge mode to surf the Internet, but now I am facing the following demand scenario: The centos virtual machine is required to be able to yum install and docker pull Internet images, so it needs to access the Internet. CentOS needs to access the local host's VPN. The local xshell can access the cenots virtual machine through ssh. Therefore, in order to achieve my goal, I used the NAT+host-only method to set up the virtual machine. It took some time to set up, so this article was written to summarize the experience. 2. What are the connection methods for virtual machine network cards?There are 4 network connection methods in VirtualBox:
Let's take a look at a picture first. It's easy to see the difference between these four methods through this picture: 2.1 NAT NAT: Network Address Translation
**The relationship between the virtual machine and the host: **Only one-way access is allowed. The virtual machine can access the host through the network, but the host cannot access the virtual machine through the network. 2.2. Bridged Adapter (Bridge Mode) Bridge mode, you can understand it like this: 2.3. Internal (intranet mode) Intranet mode, as the name implies, is the internal network mode: 2.4. Host-only Adapter (Host Mode) Host mode is a relatively complex mode that requires solid basic network knowledge to use. It can be said that the functions implemented in the previous modes can be realized in this mode through the settings of the virtual machine and the network card. 3. Let’s configure it!Software Environment
3.1 Setting up NAT network The purpose of setting up a NAT network is to allow the virtual machine to access the Internet. Shut down the virtual machine before setting up. I fell into a trap here for a long time.
As shown in the figure below: In the management interface, click [Settings] – [Network] – [Network Card 1], select [NAT Network] in [Connection Mode], select [NAT Network] in [Interface Name], and click [OK]. The screenshot is as follows: 【start up】 After logging into the system, run: # vi /etc/sysconfig/network-scripts/ifcfg-enp0s3 Change [ONBOOT] to [yes]. The specific configuration is as follows: TYPE=Ethernet PROXY_METHOD=none BROWSER_ONLY=no BOOTPROTO=dhcp DEFROUTE=yes IPV4_FAILURE_FATAL=no IPV6INIT=yes IPV6_AUTOCONF=yes IPV6_DEFROUTE=yes IPV6_FAILURE_FATAL=no IPV6_ADDR_GEN_MODE=stable-privacy NAME=enp0s3 UUID=3b8d1c63-5d2e-43d2-9508-6c1ecec961346 DEVICE=enp0s3 ONBOOT=yes HWADDR=08:00:27:AF:90:BF Restart the network service: systemctl restart network At this point, you can connect to the Internet normally. Use curl to access Baidu as shown below: However, you cannot log in to the server via SSH at this time. 3.2 Setting up a host-only networkShut down the virtual machine before setting up. I fell into a trap here for a long time. In [Management] - [Global Settings] - [Network], you should be able to see the [Host-Only Network] tab. After installing VirtualBox, you can see [VirtualBox Host-Only Network] in the computer's [Network and Sharing Center] - [Change Adapter Settings]: Right click [Properties] – [Internet Protocol Version 4 (TCP/IPv4)] and you can see that the IP address is [192.168.56.1]:
Go back to VirtualBox and select Edit Host-Only Network. You can see:
[Settings] – [Network] – [Network Card 2] – [Enable network connection], select [Host-Only network] in [Connection method]: Turn on the computer. Execute the following command: Copy a network card configuration cp ifcfg-enp0s3 ifcfg-enp0s8 vi ifcfg-enp0s8 Delete the [HWADDR] line, delete the [UUID] line, add [IPADDR] and [NETMASK], change [DEVICE] to [enp0s8], and [BOOTPROTO] to [static]: TYPE=Ethernet PROXY_METHOD=none BROWSER_ONLY=no BOOTPROTO=static DEFROUTE=yes IPV4_FAILURE_FATAL=no IPV6INIT=yes IPV6_AUTOCONF=yes IPV6_DEFROUTE=yes IPV6_FAILURE_FATAL=no IPV6_ADDR_GEN_MODE=stable-privacy NAME=enp0s8 UUID=3b8d1c63-5d2e-43d2-9508-6c1ecec96146 DEVICE=enp0s8 ONBOOT=yes IPADDR=192.168.56.42 NETMASK=255.255.255.0 Restart the network service. systemctl restart network At this point you can use xshell to connect to the virtual machine and configure the connection as shown below: The connection is successful as shown in the figure below: knock off! refer to https://www.cnblogs.com/dee0912/p/5470700.html This is the end of this article about the pitfalls of using NAT+host-only networking in VirtualBox CentOS7. For more information about VirtualBox host-only networking, please search previous articles on 123WORDPRESS.COM or continue to browse the following related articles. I hope you will support 123WORDPRESS.COM in the future! You may also be interested in:
|
<<: vue3 custom directive details
>>: A brief discussion on whether too many MySQL data queries will cause OOM
Table of contents After creating a container loca...
I've been a little busy these two days, and t...
The computer system is: win7 This article is main...
Table of contents 1.sleep function 2. setTimeout ...
The problem of resetting the password for Zabbix ...
When we use the MySQL service, under normal circu...
width: auto The child element (including content+...
In the previous article, I wrote a cross-table up...
Overview The prototype pattern refers to the type...
Table of contents Overview Vuex four major object...
The steps for configuring Tomcat in IDEA 2020 are...
Date type differences and uses MySQL has five dat...
Table of contents 1. Shared and Exclusive Locks 2...
Generally speaking, once a column in a data table...
Transactional Characteristics 1. Atomicity: After...