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

What are the connection methods of virtual machine network card

2025-03-25 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

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

This article mainly introduces the connection methods of the virtual machine network card, the article is very detailed, has a certain reference value, interested friends must read it!

1. The background of the question

According to the usual settings, I use the bridge mode to surf the Internet, but now the demand scenario is as follows:

It is required that the centos virtual machine can be mirrored by yum install and docker, so it is necessary to access the Internet. Centos needs to access the vpn of the local host. The local xshell can access the cenots virtual machine with ssh.

Therefore, in order to achieve my target requirements, the nat+host-only method is used to set up the virtual machine.

2. What are the connection methods for the virtual machine Nic?

There are 4 network connection methods in VirtualBox:

NAT

Bridged Adapter

Internal

Host-only Adapter

Let's start with a picture, from which it is easy to see the difference between the four ways:

2.1 、 NAT

NAT:Network Address Translation, network address translation

NAT mode is the easiest way to implement virtual machine access to the Internet, you can understand it like this:

All the data that Guest accesses to the network is provided by the host, Guest does not really exist in the network, the host and any machine in the network can not view and access the existence of Guest.

Guest can access all the networks that the host can access, but Guest is not visible to the host and other machines on the host network, and even the host cannot access the Guest.

* * relationship between virtual machine and host: * * only one-way access is allowed. The virtual machine can be accessed to the host through the network, and the host cannot access the virtual machine through the network.

* * relationship between virtual machines and other hosts in the network: * * only one-way access is allowed. Virtual machines can access other hosts in the network, and other hosts cannot access virtual machines through the network.

* * relationship between virtual machines and virtual machines: * * cannot access each other. Virtual machines and virtual machines are completely independent and cannot access each other through the network.

Bridged Adapter (bridge mode)

Bridge mode, you can understand it like this:

It is through the host network card, set up a bridge, directly connected to the network. Therefore, it allows virtual machines to be assigned to a separate IP in a network, and all network functions are exactly the same as real machines in the network.

A virtual machine in bridge mode, you just think of it as a real computer.

* * relationship between virtual machines and hosts: * * they can access each other because virtual machines have independent IP in the real network segment. Hosts and virtual machines are in the same network segment and can access each other through their respective IP.

* * relationship between virtual machines and other hosts in the network: * * they can access each other. Also because virtual machines have independent IP in the real network segment, virtual machines are in the same network segment as all other network hosts and can access each other through their own IP.

* * relationship between virtual machine and virtual machine: * * can access each other for the same reason as above.

2.3.The Internal (intranet mode)

The intranet model, as its name implies, is the intranet model:

The virtual machine is completely disconnected from the external network, and only the internal network mode between the virtual machine and the virtual machine is realized.

* * relationship between virtual machines and hosts: * * cannot access each other, do not belong to the same network, and cannot access each other.

* * relationship between virtual machines and other hosts in the network: * * cannot access each other for the same reason as above.

* * relationship between virtual machines and virtual machines: * * can access each other, provided that when setting the network, the two virtual machines set the same network name. As in the configuration figure above, the name is intnet.

2.4.The Host-only Adapter (host mode)

Host mode, which is a more complex model, requires a relatively solid basic knowledge of the network to play. It can be said that the functions realized by the previous modes can be realized through the settings of virtual machines and network cards in this mode.

We can understand that Guest simulates a network card dedicated to virtual machines in the host, and all virtual machines are connected to this network card. We can set up this network card to access the Internet and many other functions, such as (network card sharing, network card bridging, etc.).

* * relationship between virtual machines and hosts: * * they cannot access each other by default, and they do not belong to the same IP segment. The default IP segment of host-only Nic is 192.168.56.X subnet mask of 255.255.255.0, and all subsequent virtual machines are assigned to this IP address range. Through network card sharing, network card bridging and so on, virtual machines can access each other between hosts.

* * relationship between virtual machines and network hosts: * * they cannot access each other by default. The reason is the same as above. You can access each other by setting.

* * relationship between virtual machines and virtual machines: * * they can access each other by default, and they are all in the same network segment.

3. Let's start with the configuration.

Software environment

Virtualbox 6.0.22

Centos linux7

3.1 set up the Nat network

The nat network is set up so that virtual machines can access the Internet.

Turn off the virtual machine before setting up, the author has been trampling here for a long time.

Click * * manage * *-> * * Global Settings * *-> * * Network * *-> add a New NAT Network * * in the VirtualBox main control interface.

In the pop-up dialog box, set [Network CIDR] to [192.168.100.0], [OK]

Enter the following figure as shown:

Click * * Settings * *-> * * Network * *-> * * Network Card 1 * * on the management interface, select * * NAT Network * * for * * connection method * *, select * * NATNetwork * * for * * Interface name * *, and * * OK * *. The screenshot is as follows:

[start]

After logging in to the system, run:

# vi / etc/sysconfig/network-scripts/ifcfg-enp0s3

Change [ONBOOT] to [yes]. The configuration is as follows:

TYPE=EthernetPROXY_METHOD=noneBROWSER_ONLY=noBOOTPROTO=dhcpDEFROUTE=yesIPV4_FAILURE_FATAL=noIPV6INIT=yesIPV6_AUTOCONF=yesIPV6_DEFROUTE=yesIPV6_FAILURE_FATAL=noIPV6_ADDR_GEN_MODE=stable-privacyNAME=enp0s3UUID=3b8d1c63-5d2e-43d2-9508-6c1ecec961346DEVICE=enp0s3ONBOOT=yesHWADDR=08:00:27:AF:90:BF

Restart the network service:

Systemctl restart network

The network can be connected normally at this time. Curl visits Baidu as shown in the following figure:

But it is not possible to log in to the server through SSH at this time.

3.2 set up the Host-only network

Turn off the virtual machine before setting up, the author has been trampling here for a long time.

In "manage"-"Global Settings"-"Network", you should see the tab of "Host (Host-Only) Network only". After installing VirtualBox, you can see [VirtualBox Host-Only Network] in "Network and sharing Center"-"change Adapter Settings" on your computer:

Right-click [Properties]-[Internet Protocol version 4 (TCP/IPv4)] to see that the IP address is [192.168.56.1]:

Go back to VirtualBox and select Edit Host-only (Host-Only) Network. You can see:

* * Settings * *-> * * Network * *-> * * Network Card 2 *-* enable Network connection * *, and select * * Host-Only Network only * * for * * connection method * *:

Turn it on.

Execute the following command:

Copy a network card configuration

Cp ifcfg-enp0s3 ifcfg-enp0s8vi ifcfg-enp0s8

Delete [HWADDR] line, delete [UUID] line, add [IPADDR] and [NETMASK], change [DEVICE] to [enp0s8], [BOOTPROTO] to [static]:

TYPE=EthernetPROXY_METHOD=noneBROWSER_ONLY=noBOOTPROTO=staticDEFROUTE=yesIPV4_FAILURE_FATAL=noIPV6INIT=yesIPV6_AUTOCONF=yesIPV6_DEFROUTE=yesIPV6_FAILURE_FATAL=noIPV6_ADDR_GEN_MODE=stable-privacyNAME=enp0s8UUID=3b8d1c63-5d2e-43d2-9508-6c1ecec96146DEVICE=enp0s8ONBOOT=yesIPADDR=192.168.56.42NETMASK=255.255.255.0

Restart the network service.

Systemctl restart network

At this point, you can use xshell to connect to the virtual machine, as shown in the following figure:

The successful connection is shown in the following figure:

The above is all the contents of the article "what are the connection modes of virtual machine network cards". Thank you for reading! Hope to share the content to help you, more related knowledge, welcome to follow the industry information channel!

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

Development

Wechat

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

12
Report