Network Configuration of CentOS in VirtualBox virtual machine

Source: Internet
Author: User
Recently, hadoop was developed on Linux, so I installed a virtualbox virtual machine and installed a centOS system on the virtual machine. Linux is installed, but network configuration is another headache. I mainly want to allow the host machine and virtual machine to access each other. Then I went to Baidu and configured it step by step based on Baidu's results.

Recently, hadoop was developed on Linux, so I installed a virtualbox virtual machine and installed a centOS system on the virtual machine. Linux is installed, but network configuration is another headache. I mainly want to allow the host machine and virtual machine to access each other.

Then I went to Baidu and configured it step by step based on Baidu's results.

After virtualbox is installed, it will install a Virtual NIC on the host machine,

  

Double-click it to view details and information.

I used the host-only method to configure the network on a virtual machine. of course, the bridging method can also be used. There are many differences between them on the Internet. The virtual machine uses this virtual network card as the gateway.

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

1. modify the IP address

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

DEVICE = "eth0"
BOOTPROTO = "static". here, the static IP address is used.
HWADDR = "08: 00: 27: 0C: 33: 8F"
NM_CONTROLLED = "yes"
ONBOOT = "yes" is set to auto start
TYPE = "Ethernet"
UUID = "f4adafbc-322d-4dc8-b549-4291f1c04f01"
IPADDR = 192.168.137.101 sets the IP address of the virtual machine. the IP address must be in the same CIDR block as the host machine, but cannot be renamed.
NETMASK = 255.255.255.0 set the subnet mask
# GATEWAY = 192.168.137.1 set the GATEWAY, that is

2. modify the Gateway

Run vi/etc/sysconfig/network to modify the file content as follows:

NETWORKING = yes
HOSTNAME = localhost. localdomain
GATEWAY = 192.168.137.1 set the GATEWAY here, that is, the ip address of the virtual network card

3. modify DNS

Run vi/ect/resolv. conf to modify the file as follows:

Add a domain name server for nameserver 192.168.137.1

Restart the network service and run the service network restart command.

First, complete the configuration according to this step. Ping the VM on the host machine. No problem. However, ping the host machine and gateway on the virtual machine fails, let alone ping the Internet. The problem is as follows:

When you ping the host machine and the gateway, the system does not prompt that the Ping fails, but cannot receive the Peer Information. Packets: Sent = 4, Received = 0, Lost = 4 (100% loss ). The result of ping www.baidu.com is invalid host name. This problem plagued me for a whole day and Baidu could not find the result. I know the problem must be the ip address configuration. after Baidu failed this evening, I thought of the virtual network card. I used the above method to configure it, the virtual network card is used as the gateway, but the virtual network card is not configured at all, it has nothing to do with the network card on my computer, it is certainly not good to use it directly. Later, I thought we could use broadband to share Wireless wifi. Why can't we share the broadband connection with that virtual network card? Try again immediately. after the sharing is started, the ip address of the virtual network card changes again, and thenCentosConfigure the network information according to the above steps. The result is OK. the problem that bothered me for a day or two finally solved.

Ping the host machine. OK.

Ping www.baidu.com is also OK.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.