VirtualBox configure centos7 static ip (detailed)

  VirtualBox installs centos7 and configures a static ip address that can be accessed locally and can be connected to the Internet.

Before I start, I don’t know why, most of my Baidu online are not available, or can only be accessed by the host, or can only be connected to the Internet.

My config file is ifcfg-enp0s3

just look at the picture

1. Enter after installing centos7


2. Select Settings--->Network

As shown in the figure below, you can see that there are network cards 1, 2, 3, and 4. Network card 1 is checked by default. Let's add network card 2 and check bridge mode (I will extend it here, I am a network card and can't solve it)

 

3. After the check is completed, start the virtual machine and enter the etc/sysconfig/network-scripts/ directory: my configuration file is ifcfg-enp0s3

As shown in the figure above, you can see that my configuration file has one more ifcfg-enp0s8. This is the ifcfg-enp0s3 I copied because I enabled network card 2. The configuration file needs to be named ifcfg-enp0s8

File ifcfg-enp0s3 configuration:

Note that I marked the point changed to yes

File ifcfg-enp0s8 configuration:

Enter the cmd of the machine and execute ipconfig


Note that the static IP address of the virtual machine in the place I marked yellow is 192.168.1.* (* means any number between 2-255), and the subnet mask is NETMASK.

The default gateway is GATEWAY Look at my ifcfg-enp0s8 configuration



See the place where I marked yellow: first change enp0s3 to enp0s8, uuid generates a new one, otherwise the gateway will restart and fail to generate command: uuidgen

Next we just need to restart the gateway

Execute the command: systemctl restart network configuration is complete

Take a look at the renderings: virtual machine Internet access: ping www.baidu.com

localhost to access the virtual machine: ping 192.168.1.2

At this point, you can use xshell to link the virtual machine.

Note: I have been trying not to use two network cards, but to use one network card to complete the access between the host and the virtual machine, and the access between the virtual machine and the external network. If I choose bridge mode, when BOOTPROTO=dhcp in the configuration file, a static IP is configured, which can access the external network but cannot be accessed locally. When BOOTPROTO=static, it can be accessed locally but cannot be accessed from the external network. So I only use two network cards. If anyone can fix this, please point out where my mistake is in the comments.

Therefore: NIC selection in the second step above

I disabled the first network. If it is not disabled, the local ipconfig will have an additional network address of 192.168.56.*, so that you can choose the host-only mode for the second network card. That way the static IP address is set to 192.168.56.*

So there are multiple ways to match 1.net network address translation (can access the external network) 2. bridge mode (can be accessed from the external network and the host, but cannot be implemented in one network card)

3. Host-only mode (with host access) is used (Virtual Box Host-Only)

Let me say it again: whoever found my mistake, please comment (version problem? Or configuration problem?)




Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324706196&siteId=291194637