virtualBox install centos to set IP

After installing virtualbox, it will install a virtual network card on the host machine.

 
Double-click it as shown in the figure to view the details. The information is shown

 
in the figure. To configure the network on the virtual machine, I use the host-only method, of course, the bridge method can also be used. As for their differences, there are many online. The virtual machine mainly uses this virtual network card as the gateway.

      After entering the centOS system, there are three main files that need to be configured:

  1. Modify the ip address

  Use the command vi /etc/sysconfig/network-scripts/ifcfg-eth0 to modify the content of the file as follows

DEVICE="eth0"
BOOTPROTO="static" Here instead use static ip
HWADDR="08:00:27:0C:33:8F"
NM_CONTROLLED="yes"
ONBOOT="yes" set to auto-start
TYPE="Ethernet"
UUID="f4adafbc-322d-4dc8-b549-4291f1c04f01"
IPADDR=192.168.137.101 Set the ip address of the virtual machine, which must be in the same network segment as the host machine, but cannot have the same name.
NETMASK=255.255.255.0 Set the subnet mask
# GATEWAY=192.168.137.1 sets the gateway, that is

  2. Modify the gateway

Use the command: vi /etc/sysconfig/network to modify the content of the file as follows:

NETWORKING=yes
HOSTNAME=localhost.localdomain
GATEWAY=192.168.137.1 The gateway is set here, which is the ip of the virtual network card

  3. Modify DNS

Use the command: vi /ect/resolv.conf to modify the content of the file as follows:

nameserver 192.168.137.1 Add a domain name server

 

Finally restart the network service and it will be ok, use the command service network restart.

 

To start, I follow these steps to complete the configuration. Ping the virtual machine on the host machine, no problem can be pinged. However, there is a problem with pinging the host and gateway on the virtual machine, let alone pinging the external network. Questions are as follows:

Ping the host and gateway does not indicate that the ping cannot be reached, but cannot receive information from the other party. Packets: Sent = 4, Received = 0, Lost = 4 (100% loss). Ping www.baidu.com  results in invalid hostname. This problem has plagued me for a whole day, and Baidu can't find any results. I know that the problem must be in the configuration of the ip. After Baidu failed tonight, I thought of the virtual network card. I used the above method to configure the virtual network card as the gateway, but the virtual network card simply Without configuration, it has nothing to do with the network card on my computer, and it is definitely impossible to use it directly. Later, I thought that we can use broadband to share wireless wifi, why can't we share the broadband connection to that virtual network card? Try it immediately, after starting the sharing, the ip of the virtual network card has changed again, and then reconfigure the network information in centos according to the above steps.



 Note: I still can't do it here. Finally, I enter the setup command and set it to automatically obtain IP when setting up the network service.

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326879427&siteId=291194637