CentOS network configuration in visual box virtual machine environment

Source: Internet
Author: User

CentOS network configuration in visual box virtual machine environment

In the following configuration, the CentOS virtual machine can be connected to the Internet, and the host can also be connected to the CentOS virtual machine:

The best solution is to use two NICs, NAT (the Virtual Machine accesses the Internet and uses the 10.0.2.X segment) and host-only (the virtual machine communicates with the host and uses the 192.168.56.X segment ).
Enable the virtual machine configuration and add the second network card as host-only in the network. when you use it for the first time, you will find that the "Interface Name" is blank and prompt that you cannot complete the operation. In this case, you can enable VirtualBox preference settings and select Host-Only in the network, click the plus sign on the right to add an interface (vboxnet0). Then, return to the virtual machine configuration and you will see that the interface name already has an optional option.
After the settings, we open CentOS, at this time ping the Internet is not available, You Need To in/etc/sysconfig/network-scripts/ifcfg-eth0 to change ONBOOT = "no" to yes, add BOOTPROTO = "dhcp", save and quit, and then ping the internet. at this point, you can use the command route to check and record the route. If you cannot access the Internet later, use route to check what exceptions occur. ping the virtual network card 192.168.56.1 on the host and find that there is no problem. It is okay, but the host cannot access the virtual machine. This is a headache, in this case, our second Nic Host-Only is used to access the VM. the procedure is as follows:
Check whether there are any ifcfg-eth1 files under/etc/sysconfig/network-scripts/. If not, copy the ifcfg-eth0, change it to the ifcfg-eth1, and change the ONBOOT value to yes, here, I set it to a static IP address. The configuration is as follows:

123 BOOTPROTO = & quot; static & quot; # the IP address is obtained automatically through dhcp or bootp, static is a fixed IP address, and none is a manual IPADDR = & quot; 192.168.56.2 & quot; NETMASK = & quot; 255.255.255.0 & quot;

Do not forget to modify

12 DEVICE = & quot; eth1 & quot; HWADRR = & quot; your Nic physical address. You can view it in the configuration & quot;

Note that the GATEWAY cannot be set because:
Linux dual-network card default Routing Problem: after the second network card is installed, there is a problem with the Internet access, use the route to find that the default route is faulty, after multiple verification, it was found that eth0 and eht1 were first loaded when linux loaded the NIC configuration file. in this way, if gateway is set in eth1, the gateway settings in eth0 will be overwritten. Therefore, the solution is to delete the gateway settings in eth1.

The following are some related knowledge:

There are four network access methods in the VirtualBox graphic interface:
1. NAT Network Address Translation mode (NAT, Network Address Translation)
2. Bridged Adapter Bridging Mode
3. Internal network mode
4. Host-Only Adapter Host Mode

In CommandLine, there are eight methods. In addition to the four listed above, there are also the following four methods:
1. UDP Tunnel networking
2. VDE networking
3. Limiting bandwidth for network I/O
4. Improving network performance

VirturalBox provides eight virtual PCI NICs for each virtual machine. For each type of virtual Nic, you can choose one of the following six network hardware types:
AMD PCNet pci ii (Am79C970A)
AMD PCNet fast iii (Am79C973, the default)
Intel PRO/1000 MT Desktop (82540EM) (Windows Vista and later versions)
Intel PRO/1000 T Server (82543GC) (Windows XP)
Intel PRO/1000 MT Server (82545EM) (OVF imports from other platforms)
Paravirtualized network adapter (virtio-net)

Features:
1. The NAT mode is the simplest way to Implement Virtual Machine Internet access. You can understand it as follows:
All data of the Vhost accessing the network is provided by the host, and the Vhost does not exist in the network. The host and any machine on the network cannot view and access the existence of the Vhost.
Relationship between virtual machines and hosts: Only one-way access is allowed. virtual machines can access hosts through the network, and hosts cannot access virtual machines 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: they cannot access each other. They are completely independent from each other and cannot access each other through the network.
IP: 10.0.2.15
Gateway: 10.0.2.2
DNS: 10.0.2.3

2. in the Bridged Adapter mode, a bridge is established through the host Nic and directly connected to the network. therefore, it allows virtual machines to be allocated to independent IP addresses in a network. All network functions are the same as those of real machines in the network.
Relationship between virtual machines and hosts: mutual access is allowed. Because virtual machines have independent IP addresses in the real network segment, the host and virtual machines are in the same network segment and can access each other through their respective IP addresses.
Virtual machines are connected to other hosts in the Network: they access each other. Similarly, because virtual machines have independent IP addresses in the real network segment, the virtual machines are in the same network segment as other hosts on all networks, each Other can access each other through their respective IP addresses.
Relationship between virtual machines: mutual access is allowed. The reason is the same as above.
Feature: exclusively occupies an ip address in the network.
Note: If the host directly accesses the Internet through a dial-up instead of a route, this method is unavailable.

3. The Internal mode, as its name implies, is the Internal network mode. The virtual machine is completely disconnected from the Internet and only implements the Internal network mode between the virtual machine and the virtual machine.
Relationship between virtual machines and hosts: they cannot access each other, they do not belong to the same network, and they cannot access each other.
Relationship between virtual machines and other hosts in the Network: mutual access is not allowed for the same reason as above.
Relationship between virtual machines: mutual access is allowed, provided that the two virtual machines set the same network name when setting the network.

4. Host-Only Adapter Mode

Host mode. This is a complex mode that requires a solid basic network knowledge. it can be said that the functions implemented in the previous modes can be achieved through virtual machine and nic settings in this mode. we can understand that the Vbox model a dedicated Nic for the virtual machine in the host. All virtual machines are connected to the NIC. We can set this Nic to achieve Internet access and many other functions, such as NIC sharing and nic bridging.
Relationship between virtual machines and hosts: mutual access is not allowed by default. Both parties do not belong to the same IP segment. The default IP segment of the Host-Only NIC is 192.168.56.X, And the subnet mask is 255.255.255.0, this CIDR block is also allocated to the following virtual machines. through Nic sharing and nic bridging, virtual machines can access each other on the host.
Relationship between virtual machines and network hosts: mutual access is not allowed by default. The reason is the same as above. Mutual access can be achieved through settings.
Relationship between virtual machines: by default, virtual machines can access each other, both in the same network segment.
The VM accesses the Host using the VirtualBox Host-Only Network Nic IP address 192.168.56.1 of the Host, regardless of whether the Host is connected locally or not.
When the host accesses the VM, it uses the IP address 192.168.56.101 of network adapter 3 of the VM, regardless of whether the host is connected locally or not.
When a virtual machine accesses the internet, it uses its own network adapter 2. In this case, the host must be able to access the Internet through a "Local Connection", but the wireless network adapter will not work.

Some related knowledge is well summarized:

I. NAT Mode

Features:
1. If the host can access the Internet, the VM can access the Internet.
2. ping is not allowed between virtual machines.
3. the VM can ping the host (in this case, ping the gateway of the VM, that is, ping the host)
4. The host cannot ping the VM.

Application scenarios:
Virtual machines only require Internet access, without other special requirements, to meet the most general needs

Configuration method:
Select Network Address Translation (NAT) as the connection method)
Advanced-control chip selection PCnet-FAST III
Advanced-reject in Mixed Mode
Advanced-access network cable √
(Virtual Machine ip address automatically obtained)

Ip style:
Ip 10.0.2.15
Gateway 10.0.2.2
Note that the gateway here may be the same value in different virtual machines, but it belongs to different NAT engines. Therefore, in fact, different virtual machines use different gateways.

Principle:
Requests from virtual machines are sent to the NAT Engine, which uses the host for external network access, and the returned packets are then sent to the Virtual Machine by the NAT Engine.

Ii. Bridged Adapter mode (Bridging Mode)

Features:
1. If the host can access the Internet, the VM can access the Internet.
2. ping between virtual machines
3. the VM can ping the host.
4. The host can ping the VM.
The preceding points are based on the premise that the host can access the Internet.
5. If the host cannot access the Internet, all 1-4 features are unavailable.

Application scenarios:
The virtual machine requires Internet access, and the virtual machine completely simulates a physical machine

Configuration method:
Select bridging network card for connection mode
Interface Name selection (If your laptop has a wireless network card and a wired network card, you need to select according to the current Internet access method)
Advanced-control chip selection PCnet-FAST III
Advanced-reject in Mixed Mode
Advanced-access network cable √
(Virtual Machine ip address automatically obtained)

Ip style:
The ip address and the local ip address are in the same network segment.
The gateway is the same as the local gateway.

Principle:
Establish a bridge through the host Nic and connect it directly to the network. It allows virtual machines to be allocated to independent IP addresses in a network. All network functions are completely consistent
The real machines on the network are the same.
(Virtual machines obtain IP addresses through the DHCP service in the network where the host is located. Therefore, the two are completely independent, but the fact is that virtual machines do not
If there is an independent hardware, it still depends on the host's network card. Therefore, if the host needs to disconnect the network, the virtual machine will not be able to get the ip address ~~ All features
Disappear)

Iii. Host-only Adapter Mode

Features:
1. the VM cannot access the Internet.
2. ping between virtual machines
3. the VM can ping the Host. (Note that the VM communicates with the Host through the NIC named VirtualBox Host-Only Network of the Host. Therefore, the ip address
Is the ip address 192.168.56.1 of the network adapter, not the ip address you are using to access the Internet)
4. The host can ping the VM.

Application scenarios:
When the host cannot access the Internet (host-only or bridging can be used when the host can access the Internet), a simulated LAN needs to be set up, and all machines can access each other.

Configuration method:
Select Host-Only adapter for connection mode
Select VirtualBox Host-Only Ethernet Adapter as the interface Name
Advanced-control chip selection PCnet-FAST III
Advanced-reject in Mixed Mode
Advanced-access network cable √
(The Virtual Machine ip address is automatically obtained, or you can configure it yourself. The Gateway is configured as the address of the virtual network card in the host [Default: 192.168.56.1], and the ip address is configured as the same network segment as the virtual network card address)

Ip style:
The ip address is in the same Network segment as the NIC ip address of the local VirtualBox Host-Only Network (192.168.56. * by default .*)
Nic ip address of the VirtualBox Host-Only Network on the local machine of the Gateway (default: 192.168.56.1)

Principle:
The VirtualBox Host-Only Network Nic is used for communication. The virtual machine uses the ip address as the gateway. Therefore, the local Network of the Local Machine and each virtual machine is simulated,
It should be impossible to access the internet (but some people say that the virtual machine can access the Internet by bridging the VirtualBox Host-Only Network adapter, but it is better to directly
It's easy to use bridging. Besides, I didn't try it. Some people also said no, because the host does not provide the routing service, and I am not confused, try it yourself ~~)

Iv. Internal Mode (intranet Mode)

Features:
1. the VM cannot access the Internet.
2. ping between virtual machines
3. the VM cannot ping the host.
4. The host cannot ping the VM.

Application scenarios:
Isolate virtual machines from each other in an isolated LAN.

Configuration method:
Select internal network for connection mode
Select intnet as the interface Name (you can rename it. All virtual machines placed in the same LAN have the same name)
Advanced-control chip selection PCnet-FAST III
Advanced-reject in Mixed Mode
Advanced-access network cable √
(Virtual Machine ip Address: For XP, You can automatically obtain the ip address, but for linux, you must manually configure the ip address and subnet mask. During manual configuration, you must ensure that the ip addresses of each virtual machine are in the same network segment)

Ip style:
Ip 169.254.147.9
Subnet Mask 255.255.0.0
No Default Gateway

Principle:
Each virtual machine uses the built-in DHCP server of VirtualBox to obtain the ip address. packet transmission does not pass through the network of the host, so the security is high to prevent external packet capture ~

5. NAT mode + port ing

Map a port of the VM to a port of the host so that the host and external machine can access the services provided by the VM ~~
The command is as follows:
(In command line mode, first go to the installation directory of VirtualBox; otherwise, the command cannot be found)
Vboxmanage setextradata "VBoxInternal/Devices/pcnet/0/LUN #0/Config/ /Protocol "TCP
Vboxmanage setextradata "VBoxInternal/Devices/pcnet/0/LUN #0/Config/ /GuestPort "80
Vboxmanage setextradata "VBoxInternal/Devices/pcnet/0/LUN #0/Config/ /HostPort "8000

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.