Networking between Windows and Linux virtual machines for SSH remote connectivity and VMware's 3 network modes [NAT, bridging, and host-only]

Source: Internet
Author: User
Tags switches domain name server


networking between Windows and Linux virtual machines for SSH remote connectivity and VMware's 3 network modes [NAT, bridging, and Host-only]


Tian Qi





One, the network between Windows and Linux virtual machine for SSH remote connection


If we were to configure an IP address for a virtual machine with host name MINI1, the following steps are required:






To view the IP address on Linux, if the Linux server has an IP address, let its IP address and Windows IP address in the same network segment, they can be networked. The command to view the IP address on Linux is "Ifconfig":









found that the eth0 NIC does not have an IP address configured. So we're going to configure it for the NIC. Enter the "Setup" command to eject the configuration interface:






Select Network Configuration.






Select Device Configuration.






Select "Eth0". Represents the No. 0 Ethernet card in a Linux system.






In the "Name" and "Device" two items remain the default, do not modify.



Where use DHCP means using the DHCP protocol to obtain an IP address, that is, the IP address is automatically obtained. We don't want it to get automatically because it's possible to get an IP address.



Open the Windows Services window:






Because a Windows service is registered when VMware starts up, the service may not start and must be started to obtain an IP address automatically:









Because we do not use the automatic acquisition of IP, press the SPACEBAR on the keyboard to remove the "*" sign after DHCP. We want to specify the IP address ourselves. So how do we specify an IP address?






Here are a few network modes, first of all, the NAT network mode.



VMware itself creates a virtual network switch that connects all of the virtual machines we create to this internal virtual switch and then connects. So if you want to implement networking between a Linux virtual machine and Windows, you have to know the IP address segment of the virtual switch inside VMware.



The following is a schematic diagram of the NAT network mode:






In, all of the virtual machines we create in VMware are connected to one of its virtual switches, which has a network segment, and all of the virtual machines we create should be in the same network segment as the virtual machine switch. Windows also has a virtual network card (the virtual network card is also created by VMware), Vmnet8, which is also connected to this virtual switch. Also make sure that the VMNET8 virtual network card and all of the virtual machines we create are in the same network segment, so that they can connect to each other. They are the equivalent of forming an intranet. So we want to configure the virtual machine's IP address, first of all to know the VMware Virtual Switch IP address is how much.









Knowing the network segment and gateway IP of VMware's Virtual switch, we can then configure the IP address of our virtual machine.



We can configure our own virtual machines in addition to "192.168.71.2" (Switch gateway IP) and "192.168.71.255" (In the TCP/IP protocol, 255 is not used to represent the IP address of a machine, but to represent all the machines in the entire network segment, If you configure the virtual machine's IP to 255, no other machine can be found, all the data sent to 255 of the entire address will be sent to all the machines in the entire network segment other than the IP address, such as we can be set to "192.168.71.11":






Then configure the subnet mask, which must be configured as "255.255.255.0". What is a subnet mask? In fact, we say that the network segment "192.168.71.0" is computed by the IP address "192.168.71.11" and the subnet mask "255.255.255.0". The method of calculation is to use each digit in "255.255.255.0" to Do "and" with each digit in the IP address "192.168.71.11". 255 and any number above is equal to the arbitrary number itself, with 0 and any number equal to 0. Therefore, to make the network segment of the virtual Switch "192.168.71.0" The network segment, the subnet mask must be configured as "255.255.255.0".






Then the gateway IP address, which is configured as the gateway IP address of the virtual switch.






Then configure the IP address of the primary NS domain name server, where we can configure it as "8.8.8.8". This is Google provides a public domain name server. Of course, you can also fill in the wire, mobile, or unicom to provide DNS domain name server. If you don't know what DNS is, you can configure it as a gateway-like IP address. Because the gateway has a function, it can find the real DNS domain name server on the network, which is the function that the TCP/IP protocol implements at the bottom. So, as long as your gateway is able to connect, you will be able to connect the virtual machine.






DNS domain name servers can be configured with multiple, primary DNS servers, and secondary DNS servers.






Description: The IP address is actually a 8-bit binary number, the largest is 8 1, that is, 2 of the decimal 8, that is, 256 (from 0 to 255).






After configuring the IP address, restart the network card:





Srvice Network Restart


Check the IP address again with the ifconfig command and restart the virtual machine with the reboot command if you still don't see the IP address.






If not, the reason may be that you are using a graphical interface that requires the following modifications in the graphical interface:


















Then right-click on the desktop blank of the graphical interface and select "Open in Terminal" to open the command-line terminal window:






Use the "ifconfig" command to see the IP address again:






Test network connectivity between a Linux virtual machine and Windows



Open a command-line window on Windows and use the ping IP address of our Linux virtual machine:






If we are able to connect, we may use the Telnet tool to join our Linux virtual machines.






We use the SECURECRT tool to remotely connect to a Linux virtual machine. The software is available for decompression.






The connection between the client and the server is a protocol, such as the browser to access a Web site, the need to pass the HTTP protocol, here we use the SECURECRT tool to access the Linux virtual machine, using the SSH2 this protocol.






If you tick "Open in a tab", the future windows that connect multiple Linux virtual machines will be displayed in the same window with tabs for easy switching.



where hostname can fill in the IP address or hostname of the Linux virtual machine to which you want to connect, if you want to fill in the hostname, you need to add a mapping between the host name and the Linux virtual machine IP in a Hosts file in Windows. Otherwise, Windows does not recognize the hostname when it does the domain name resolution.






Extended knowledge: When doing domain name resolution, Windows does not first go to the DNS server, but first find a local configuration file, is a domain name and IP mapping table, the file is "C:\Windows\System32\drivers\etc\hosts":






Open this Hosts file to configure the mapping of the IP address and hostname of our Linux virtual machine:






Then test it to see if Windows recognizes the hostname of Linux:






Next we can use the SECURECRT tool to log in to the Linux virtual machine.



If the following window appears, asking whether to cache SSH encrypted fingerprint information, select "Accept&save", to agree and save:






Follow the prompts to enter the password, and check the save password, the next time you log in will not be prompted to enter the password:














Ii. three types of networking modes in VMware----nat--bridge--hostonly





What if you want to connect multiple computers to each other? You need to buy a router or switch. We call routers or switches gateways, which are network hubs, or network exits.






Here is the local Area network organization diagram:






So how do our multiple Linux virtual machines and our Windows connect to each other?






When we use VMware to create a Linux virtual machine, we can manually select the network mode:






There are 3 network modes available for us to choose from: Bridging mode, Nat mode, and host-only mode.


1.NAT mode


The name of the network card for the multiple Linux VMS we created is called "eth0", and in NAT mode it has a virtual switch, which is a virtual switch created internally by VMware as we mentioned earlier. All Linux virtual machines will be connected to this virtual switch. Windows will also connect to this virtual switch via the VMNET8 virtual network card. The network segment and gateway IP of this virtual switch (we typically configure the last digit of the gateway IP as 1, which is a convention commonly known as the practice) can be modified. As long as you know the network segment of this virtual switch and gateway IP, then all the machines connected to the Virtual Switch network card, as long as they are in a network segment.






With NAT mode, a virtual network is formed between the network card of Windows VMNET8 and the network card of all Linux virtual machines. This virtual network has no interference with the local connection to our windows because they are two completely different networks. This virtual network is equivalent to an intranet, and our Windows local connection is equivalent to the extranet.






And in this NAT mode, VMware has a feature that allows all the machines in the intranet to have access to the extranet. In other words, as long as your Windows machine can connect to the Sisu network, VMware will enable the set machine in this intranet to connect the Sisu network. Because VMware is able to do an address forwarding, the NAT itself is the meaning of the address forwarding. When a Linux virtual machine in the intranet is connected to a Sisu network, the address that the extranet sees is the address of the local connection of Windows.






Below is the configuration of the Linux virtual machine on our notebooks that connects to the extranet via NAT mode:



Section 1 Step: Check VMware the network segments and gateways of the virtual switches IP



as can be seen, VMware the network segment of the virtual switch is " 192.168.71.0 ", the Gateway IP address is " 192.168.71.2 ":






2nd Step: Configure the network mode of the Linux virtual machine into NAT mode






3rd Step: Check the IP address of the virtual network card VMnet8 on Windows






As you can see, our VMNET8 the IP address of this virtual network card is "192.168.71.1"






4th Step: Check the network configuration of the Linux virtual machine to connect to the extranet



Note that the IP address of the Linux virtual machine, the VMNET8 virtual network card on Windows, and the VMware Virtual Switch are located in the same network segment, and the IP address must not be the same.






5th step: After you have configured the key sections above, use the following command to restart the network card for the Linux virtual machine:





Service Network restart


6th step: Use the ping command to test if you can connect to an external network








Summary: Linux virtual machines want to connect to the external network, you need to pay attention to a few key points.


(1) The network adapter of the virtual machine connected to the extranet must use the NAT network mode (set in VMware), (2) must determine the network segment and gateway IP of VMware's virtual switch, for example, our VMware Virtual Switch segment is "192.168.71.0" and the gateway IP is " 192.168.71.2 ". (3) must ensure that the IP address of the Linux virtual machine, Windows VMnet8 the virtual network card IP address, the above-mentioned virtual Switch IP, the 3 are in the same network segment; For example, the IP address of our Windows notebook's VMnet8 virtual network card is " 192.168.71.1 ", it and the VMware Virtual Machine gateway are in the" 192.168.71.0 "this network segment. (4) Gateway for Linux virtual machine eth0 NIC (need to modify "/etc/sysconfig/network-scripts/ifcfg-eth0" file) to be set as gateway to VMware Virtual Switch, or set as Google's public DNS, which is 8.8.8.8.  The subnet mask must be "255.255.255.0". For example, the gateway of our Linux virtual machine's eth0 NIC is set to "192.168.71.2", just like the gateway to the VMware Virtual switch. (5) Ensure that our Windows PC must be able to connect to the extranet because the Linux virtual machine is connected to the extranet via Windows.

 




2. Bridging mode


In bridging mode, all of our Linux virtual machines are no longer connected to a virtual switch, but to the real physical switch that connects directly to the local connection of our Windows computer. So, all of our Linux virtual machines have IP addresses in the same network segment as the real physical switch's IP address.






We do not recommend that you use this network mode, because you change the environment, you need to reconfigure the network, such as you are in the classroom, your computer is connected to the classroom switch, you go home, the home of the switch IP and classroom IP is certainly not a network segment. So you need to reconfigure the IP address for each environment, it is inconvenient.






But bridging also has a benefit, such as the teacher's notebook all the virtual machines are configured to bridge mode, then all my virtual machine network segment and your (student) computers are in the same network segment, you can directly ping my virtual machine. I deploy a service on my virtual machine and you can access it directly. For example, I have a Hadoop cluster on my Linux virtual machine, and our virtual machines are configured as bridging mode, so you can access them directly. If I use NAT mode, you won't be able to access it. Because I'm not in the same network segment as your computer.






The IP configuration of the bridge mode is very simple, that is, all the virtual machine's IP is configured as a network segment of the real switch, and the Windows computer does not have to modify anything.





3.host-only mode


This pattern is very similar to NAT, and it has an internal



All Linux virtual machines are connected to the VMNET1 virtual network card on Windows, so that all virtual machine gateways point to the VMnet1 gateway. So the Windows computer and all the virtual machine also formed an intranet, in this intranet inside each other can access each other.






So what's the difference between host-only mode and NAT mode?



The difference is that VMware does not provide address translation services for VMnet1, so in host-only mode, all Linux virtual machines are not connected to the extranet.





[End of Article]





Networking between Windows and Linux virtual machines for SSH remote connectivity and VMware's 3 network modes [NAT, bridging, and host-only]


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.