Solve the problem that Xshell cannot connect to the virtualBox virtual machine

First, explain the network setting mode of the virtualBox virtual machine: NAT+Host-Only mode
Selecting this mode can not only ensure that the virtual machine is connected to the external network, but also ensure that the local computer is connected to the virtual machine.

Network 1: NAT mode

insert image description here

Network 2: Host-Only mode

insert image description here

Enter the virtual machine, enter ifconfig and find that no ip is displayed:

insert image description here

But ping Baidu can be pinged:

insert image description here
Therefore, it can be inferred that there is no problem with the NAT network, and there is a problem with Host-Only.

And it is normal to say that there should be information about two network cards, but currently there is only enp0s3, so we can reasonably speculate that the Host-Only network card is not activated.

Solution:

1. First set enp0s3 to boot automatically

vim /etc/sysconfig/network-scripts/ifcfg-enp0s3
添加ONBOOT="yes"

2. If there is no enp0s8, create enp0s8

cp enp0s3 enp0s8
vim enp0s8

配置如下:
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="3ec9eebb-f9e1-4e4a-8ea7-ae6c4df8c795"
DEVICE="enp0s8"
ONBOOT="yes"
IPADDR="192.168.56.105"

Note: The copied UUID needs to be modified briefly to distinguish it from the one in ifcfg-en0s3.

3. Restart the network

systemctl restart network

4. Check the ip and you already have it.
insert image description here
Here you can use the local computer Xshell to connect to the virtual machine, and at the same time ping http://www.baidu.com can also be connected to the Internet.

Guess you like

Origin blog.csdn.net/weixin_44455388/article/details/121328480