Linux Virtual Machine network connection mode

Source: Internet
Author: User
Tags virtual environment
VMWare provides three working modes: bridged (bridging mode), NAT (network address translation mode), and host-only (host mode ). To apply them properly in network management and maintenance, you should first understand the three working modes. 1. bridged (bridging mode) in this...

 

VMWare provides three working modes: bridged (bridging mode), NAT (network address translation mode), and host-only (host mode ). To apply them properly in network management and maintenance, you should first understand the three working modes.

1. bridged (bridging mode)

In this mode, the virtual operating system of VMWare is like an independent host in the LAN, which can access any machine in the network. In the bridge mode, you need to manually configure the IP address and subnet mask for the virtual system, and also need to be in the same network segment as the host machine, so that the virtual system can communicate with the host machine. At the same time, because the virtual system is an independent host system in the LAN, you can manually configure its TCP/IP configuration information to access the Internet through the LAN gateway or router.

The relationship between a virtual system in the bridge mode and the host machine is like connecting two computers on the same Hub. If you want them to communicate with each other, you need to configure the IP address and subnet mask for the virtual system. Otherwise, the communication will fail.

If you want to use VMWare to create a virtual server in the Lan to provide network services for LAN users, you should select the bridge mode.

2. host-only (host mode)

In some special network debugging environments, you must isolate the real environment from the virtual environment. in this case, you can adopt the host-only mode. In host-only mode, all virtual systems can communicate with each other, but the virtual system and the real network are isolated.

Tip: in host-only mode, the virtual system and the host machine system can communicate with each other, equivalent to the two machines connected through twisted pair wires.

In host-only mode, the TCP/IP configuration information of the virtual system (such as the IP address, Gateway address, and DNS server) is created by VMnet1 (host-only) DHCP servers in the virtual network are dynamically allocated.

If you want to use VMWare to create a virtual system isolated from other machines in the network and perform some special network debugging, you can select the host-only mode.

3. NAT (network address translation mode)

The NAT mode enables the virtual system to use the NAT (network address translation) function to access the public network through the network of the host machine. That is to say, you can use the NAT mode to access the Internet in a virtual system. In NAT mode, the TCP/IP configuration information of the virtual system is provided by the DHCP server of the VMnet8 (NAT) virtual network and cannot be modified manually, therefore, the virtual system cannot communicate with other real hosts in the local area network. The biggest advantage of using the NAT mode is that it is very easy for the virtual system to access the Internet. you do not need to configure any other configurations, but only need the host machine to access the Internet.

If you want to use VMWare to install a new virtual system, you can directly access the Internet without manual configuration in the virtual system. we recommend that you use the NAT mode.

Tip: The VMnet8 virtual network mentioned above in NAT mode, the VMnet1 virtual network in host-only mode, and the VMnet0 virtual network in bridged mode, they are all generated based on the automatic configuration of the vmwarevm and do not need to be set by the user. VMnet8 and VMnet1 provide DHCP services, while VMnet0 does not.

========================================

Vmware network settings 3: Understand the virtual network type

Many of my friends use vmware to test different systems. I will discuss my understanding of network settings based on my experience. please correct me if I am not correct.

Bridge:

This method is the easiest. you can directly bridge the virtual network card to a physical network card. it is similar to binding two different addresses to the next network card in linux. In fact, you can set the network card to the hybrid mode, this allows you to listen on multiple IP addresses.

In this mode, the network card (for example, eth0 in linux) inside the virtual machine is directly connected to the network where the physical network card is located. it can be imagined that the virtual machine and the host machine are in the same status, the network relationship is equal, and no one is behind it.

This method is easy to use, provided that you can get more than one address. It is not suitable for anyone who wants to conduct various network experiments, because you cannot control the network of the virtual machine and it goes out directly.

Nat mode:

In this way, a virtual Nic vmnet8 (by default) appears inside the host. if you have experience as a nat server, the vmnet8 here is equivalent to a network adapter connected to the intranet, the virtual machine itself is equivalent to a machine running on the intranet, and the NIC (eth0) in the virtual machine is independent of vmnet8.

In this way, the dhcp service provided by vmware is loaded to the vmnet8 interface by default, so that the virtual machine can use the dhcp service. More importantly, vmware comes with the nat service, which provides address translation from vmnet8 to the internet. Therefore, a real nat server is running, it is only for virtual machines.

Obviously, this method is suitable if you only have one Internet address.

Hostonly:

This should be the most flexible method. if you are interested, you can conduct various network experiments. The only difference with nat is that there is no address translation service in this mode. Therefore, in the case of model recognition, the virtual machine can only access the host, which is also the meaning of the hostonly name.

By default, a dhcp service is also loaded to vmnet1. In this way, the virtual machine connected to vmnet1 can still be set to dhcp to facilitate system configuration.

Is there no way to connect to the internet in this way? of course not. In fact, this method is more flexible. you can use your own method to achieve the best configuration, for example:

A. Use your own dhcp service: first stop the dhcp service provided by vmware to make the dhcp service more unified.

B. Use your own nat to facilitate the firewall. Windows host can be used for nat in many ways, such as windows xp internet sharing, and complex nat services such as windows server.

C. use your own firewall. Because you have full control over vmnet1, you can add (or test) a firewall between the vmnet1 and the Internet Nic.

As you can see from the above, the hostonly mode is similar to the normal nat server with the entire intranet, so you can easily conduct relevant experiments, such as setting a strong fire prevention.

My other two articles on specific network settings

(Linux host + windows guest

Http://bbs.chinaunix.net/forum/viewtopic.php? T = 367907 & highlight = yunqing

And

Windows host + linux guest

Http://bbs.chinaunix.net/forum/viewtopic.php? T = 374483 & highlight = yunqing

) Is also based on this configuration.

From: http://www.chinaunix.net/jh/4/376768.html

For more replies and answers, refer to the above link.

================================

Summary of Vmware network connection methods

1. bridge:

Vmnet0 is used by default.

Set the ip address of the virtual machine and the ip address of the host in the same network segment, and the rest are the same as those of the host:

For example, if the host ip address is 10.70.54.31, set the virtual machine ip address to 10.70.54.22. Netmask, broadcast, gateway, and dns are all the same as the host to implement Internet communication between virtual machines <---> host virtual machines <---->.

2. nat:

Vmnet8 is used by default.

Set the VM to use dhcp to access the internet. in windows, select "automatically obtain ip address". In linux, enable the dhcp service.

You can also set it manually:

The IP address is set to the same network segment as vmnet8, and the gateway is set to the gateway (/etc/vmware/vmnet8/nat) of vmnet8. conf) to check the vmnet8 gateway, which is usually xxx. xxx. xxx.2.

The netmask and broadcast settings are the same as those of vmnet8, and the dns settings are the same as those of the host.

For example, vmnet8 ip: 172.16.249.1 gw: 172.16.249.2

Virtual machine settings: ip: 172.16.249.100 gw: 172.16.249.2

3. host-only:

Vmnet1 is used by default.

Set the virtual machine ip address to the same network segment as vmnet1 and gateway to the ip address of vmnet1. the other settings are the same as vmnet1, and the dns settings are the same as those of the host.

For example, vmnet1 ip: 172.16.245.1

Virtual machine settings: ip: 172.16.245.100 gateway: 172.16.245.1

In this way, the VM <---> host communication is realized, but the VM <---> The Internet still cannot communicate.

Communication between virtual machines and the Internet:

1. enable host routing

2. set iptables to make the host a nat server

1. echo 1>/proc/sys/net/ipv4/ip_forward so that the host has the routing function

2. iptables-t nat-a postrouting-o eth0-s 172.16.245.0/24-j MASQUERADE

This rule is used to disguise the source ip address from 172.16.245.0/24 packets as an eth0 ip address to implement communication between virtual machines and the Internet.

If the network interface is ppp + or pppoe, you need to change it to-o pppoe.

Of course,-s 172.16.245.0/24 should also be based on

====================================

Using VMware to build a real virtual network (I)

In our previous articles, we have introduced a simple VMware network. VMWare provides three working modes: bridged (bridge mode) and NAT (network address translation mode) and host-only (host mode ). These three modes allow users to easily connect virtual machines to the network based on actual network conditions after creating virtual machines. We understand the working principles of these three networks, and we can use VMware to customize our network structure.

After installing VMware Workstation, we will find that two more virtual NICs (such as) will be added to the network connection ),

Two new virtual NICs are added.

 

You can run the ipconfig command to view the attributes of the newly added Nic. The two NICs belong to different subnets (see figure ).

Information of the new virtual network card

 

In the previous article, we introduced three typical VMware networks. the bridging mode is to directly bridge the virtual machine's Nic on your real Nic, it does not generate an independent Nic in your system. The network in the bridge mode is represented by VMnet0 in VMware. In fact, it can be seen that the real LAN of your local machine is mapped in the virtual machine network, using VMnet0 or a virtual machine connected to the network in bridging mode is equivalent to using a vSwitch to access your local network together with your real machine. If your lan provides the DHCP service, your bridging network machine can automatically obtain the IP address of the LAN. If you run the ipconfig command on a VM connected to the network through a bridge network, you can see that the IP address of the VM is within the actual LAN segment. For other machines on the internet, just as a real machine is added in this section. Let's take a look at the two new NICS:

"Ethernet adapter VMware Network Adapter VMnet1" is used to connect the local machine to a virtual machine that uses the NAT Network mode. the virtual machine created in this mode is located in the VMnet1 subnet of the virtual machine. in this subnet, VMware also provides the DHCP service to allow subnet virtual machines to conveniently obtain IP addresses. Of course, you can also manually set IP addresses for virtual machines in this subnet, but be sure to pay attention to the IP address within the network segment set by vmnet1. At this time, your real host will be used as the VMnet1 gateway, that is, the vro between the virtual network VMnet1 and the real LAN will forward data between the two network segments. What is special about VMnet1 is that VMware enables NAT services (such as) for this network segment by default ),

Enable NAT in the virtual subnet

 

The "VMware Network Adapter VMnet8" Nic is used to connect a Real host to a VM in host-only mode. a VM in this mode is located in the VMnet8 subnet of the VMware virtual Network, in addition to the different IP segments and the absence of NAT services, this subnet is no different from a virtual subnet composed of VMnet1, or NAT mode. If you like it, you can activate the NAT service of the VMnet8 subnet. in this way, VMnet8 becomes another NAT mode subnet. If NAT is disabled by default, the virtual machines in the subnet can only communicate with other virtual machines in the VMnet8 network and the Real host. this is the origin of the "host-only" name.

Open the network settings interface of VMware and you can have a deeper understanding of the VMware network mode (see ),

The ing between subnets in VMware and NICs in hosts can have a maximum of 9 different virtual subnets in VMware (three of them have been enabled after software is installed, and they are VMnet0, VMnet1, VMnet8), you can click ">" next to each word network to set the IP address of the subnet and whether to enable DHCP. On the "Host Virtual Adapers" tab (for example), you can add more Virtual NICs and connect these NICs to the corresponding Virtual network through the interface shown in the figure above.

 

Add a virtual Nic to a real host

 

To sum up, we can see that the three network modes in VMware are just a predefined mode to quickly add virtual machines to the real network. after you install VMware Workstaion, the software sets three virtual subnets in advance to correspond to three basic modes. We can change the default behavior of these networks by customizing their attributes, for example, converting the host-only mode to the NAT mode or vice versa. You can also add more virtual NICs to the real host to enable more virtual subnets (up to 9 virtual subnets ). A real host is the center of all virtual subnets and is connected to all virtual subnets. Colleague, you can add multiple NICs belonging to different virtual networks to a virtual machine to connect a virtual machine to different virtual subnets (for example, adding a virtual network card to a virtual machine, a complex virtual-reality hybrid network can be formed together with multiple virtual machines that belong to one or more virtual subnets. We can use various practical network skills in this real virtual network. The reason why the word "real" is added before the virtual network is because the method for doing any operation in the virtual network is consistent with that in the real network, virtual machines are installed with real operating systems, except that you do not have to deal with vSwitch network cables and other hardware devices, there is no difference with the real network. You can connect the virtual network to the real-world network and communicate with other systems in the real-world network. at this time, for clients in the real-world network, the communication virtual machine is no different from the terminal in any other real network system.

Vc3qtb25seswgtkfuic0gz7q9y1_m + 6vcg = "src =" http://up.2cto.com/2011/0730/20110730094754373.jpg "/>

Add a virtual Nic to a VM

 

A customized VMware Virtual Network topology

 

The above is a simple analysis of the network implementation methods in VMware. in future articles, we will build a virtual network and use it to complete common network management tasks in various real LAN environments.

From: http://biz.chinabyte.com/493/2178993_2.shtml

========================================================== ============

Using VMware to build a real virtual network (2)

In the previous article, we focused on the basic knowledge of VMware virtual network. starting from this article, we will actually establish and set up a virtual network.

Lab objectives

First, let's talk about the network topology we are going to build. Our goal is to establish two customized subnets, VMnet2 and VMnet3, which are not directly connected to the real host (I do not add a virtual Nic to the real host ), instead, we connect to VMnet0 through a VMnet0 virtual machine created in the bridge mode. The real Lan, that is, VMnet0, connects to the internet through a local gateway. we call VMnet2 virtual machine VMnet2PC, VMnet3 virtual machine is called VMnet3PC, and VMnet0 PC is called VMnet0PC. now VMnet3PC is used as the domain controller, and VMnet0PC is used as the router and DNS server. both the PC and VMnet0PC must be added to the domain established by VMnet3PC, the three CIDR blocks must be interconnected and all of them can access the internet. The network topology is as follows:

Target network topology

 

In this example, three virtual machines need to be created, and the real PC is in the VMnet0 subnet. once again, VMnet0 is actually a ING of the real Lan in the virtual network.

Next, let's first build this basic network architecture-create various virtual machines and add the required virtual network cards for them and then connect them to the specified network.

Build a "physical" network

First, we create the first virtual machine (VMnet0PC). when establishing the VM, we select the bridging network in the connection mode selection area (here we have not modified the default virtual network behavior, this virtual machine will have a virtual network card connected to VMnet0, which is in the same network segment as the real PC.

Select network mode when adding a VM

 

As we can see in the previous network topology, VMnet0PC should have three different network cards connected to three different virtual networks, respectively, VMware has automatically added a virtual network card connected to VMnet0. now we have added two more network cards connected to VMnet2 and vmnet3.

Open the "add" button under the "hardware" label of the virtual machine, for example ).

Add a new Nic to the VM

 

In the hardware add wizard, select Add Nic. then, the dialog box shown below is displayed. select the network to which the NIC is attached. Add two NICs to connect to VMnet2 and vmnet3. Install the Windows server 2003 Professional Edition operating system on the virtual machine and set a bridge Nic to connect to the internet. Now, the first server VMnet0PC has been set up and connected to the target network.

Select the network to which the new Nic is connected

 

After the first machine is set, close the virtual machine. click the "clone virtual machine" command on the left side of the window to copy the first virtual machine (for example) and name the new virtual machine VMnet2PC, because VMnet2PC only needs one network card, you need to delete the two extra network cards in the virtual machine hardware attribute and connect the remaining network card to vmnet2. Repeat the preceding steps to create a VM VMnet3PC and connect it to the network.

Copy a VM

 

Now, the "hardware" has been established and connected. The TCP/IP attributes of each virtual machine Nic are set separately, so that the VMnet2PC and VMnet3PC can be connected to the VMnet0PC respectively (the cross-network interconnection is not involved here, which will be the content of the next article ). Here we will briefly describe the settings of each subnet. Among the three NICs of VMnet0PC, one uses the IP address of the real Lan, the other uses the address 192.168.2.1/255.255.255.0 of the VMnet2 subnet, and the other uses the address 192.168.3.1/255.255.255.0 of the VMnet3 subnet, VMnet2PC in VMnet2 uses IP192.168.2.2/255.255.255.0, and the gateway and DNS are 192.168.2.1. VMnet3PCIP in VMnet3 is 192.168.3.2/, and the gateway and DNS are 192.168.3.1.

So far, only VMnet0PC can connect to the internet and access all network segments. In the next article, we will connect the network segments of the virtual machine that has been physically connected to each other and access the internet ..

Tips:

VM replication commands were not provided in versions earlier than VMware5.0, but they can be achieved through the complexity and convenience of virtual machine folders. However, in the new version, virtual machine replication is not a simple file replication, but provides many enhancements. The new virtual machine can be a source and a snapshot of the source virtual machine, it can also be associated with the source virtual machine to reduce the storage space required. After the first virtual machine used for the test is created, it is best to save a snapshot of the current state. after the test is complete, it can be restored to the status when the system is just installed, this will save a lot of time for future experiments.

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.