linux virtual machine and the host three network connections

First, install the VMware, in which the Ubuntu system is installed, then start thinking about how to be able to make normal startup hosts and virtual machines are interconnected by the host and the virtual machine to send documents through online access to relevant information, records study notes as follows.

Learning Resources:

The difference between linux virtual machine and the host of the three network connections

http://blog.csdn.net/xh16319/article/details/17272113

& VM three network modes bridge mode setting step

http://blog.csdn.net/to_baidu/article/details/52593380

Set the network under VMware NAT mode

http://www.cnblogs.com/kanyun/p/8366040.html

winscp connection vmwareubuntu

http://www.cnblogs.com/supertang/p/4097030.html

Network configuration VMware contrast three modes (bridge mode | Host Mode | Network Address Translation)

http://www.chinastor.com/a/xunihua/vmware/02063N962018.html

 

 

VMware virtual machines and host connections in the following three ways:

A bridge mode (Bridged)

 

IP address of the physical and virtual network adapter card 1. This mode is the same network segment, subnet mask, gateway, DNS and other parameters are the same.

2. The local physical NIC and the virtual NIC by the virtual switch VMnet0 bridge, located at both ends of the virtual machine and the host VMnet0 the virtual switch, the switch such that both ends are in the same segment.

3.VMware each virtual system is equivalent to an independent host, bridge mode is equivalent to the same hosts and virtual machines in a local area network two computers, the virtual machine and the host in the same position. In this case the host and the virtual machine is able to communicate, you need to be in the same network segment, which will need to manually configure the virtual system's IP address and subnet mask, ensure that the virtual machine and the host in the same segment. Virtual machine as a stand-alone host can communicate with any computer on the LAN.

Virtual network connectivity system bridge mode setting step:

1. Set the local connection click select "Properties" (here a wireless network) properties, right in front of "VMware bridge protocol" tick in the network connection.

2. Open VMware, select the "virtual machine" à "Settings", select the column on the right-Fi "bridge" in the following pages in the menu bar.

3.VMware menu bar, select "Edit" à "Virtual Network Editor", click on the bottom right of the page that opens "Change Settings", then the page will appear VMnet0, column click and choose "Bridge Mode" in VMnet information "bridge to the" name of the option to select the host physical network card back (host network connection page, under the name of the network that string of characters), and then click OK.

4. Virtual machine turned on, click on the virtual machine at the top right-Fi button, select the drop-down list in the "Edit Connections ...", open the Network Settings editing interface, click on the right select the network Edit, select the IPv4 Settings, Method select "Auto (DHCP) ", as shown below.

Click the lower right corner Save to save the changes. Then let the virtual machine to reconnect about networks, IP addresses and host address is automatically set the same network segment, then the virtual machine and the host can communicate, the bridge is completed.

5. In the virtual machine desktop, right-select "Openin Terminal" to open the command-line virtual machine page, enter ifconfig to view the virtual machine's current IP address on the page, ping the address in the host cmd command line, ping a host in a virtual machine on the command line IP addresses can be found in the communication, the bridge is successful, the virtual machine can be networked and enables communication between the virtual machine and the host.

If this ping is not found, you can look at the host or virtual machine's firewall is turned off.

 

Second, network address translation mode (NAT)

 

1. without any manual configuration, IP addresses and other network configuration information provided by the DHCP server VMnet8 (NAT) virtual network, as long as the host can access the virtual machine can achieve network connection. IP address of the virtual network adapter VMware Network Adapter VMnet8 virtual NICs and virtual machine hosts in the same network segment, subnet mask, gateway, DNS and other parameters are the same, but the real physical NIC host (host serves as a router) and virtual IP address of the machine is not in the same range.

2.虚拟系统处于虚拟的NAT网络中,虚拟机虚拟出了一个NAT服务器,使其虚拟网卡能够连接到Internet。在这种连接模式下Guest使用VMnet8虚拟交换机,在主机的网络共享中心中可以看到VMware NetworkAdapter VMnet8虚拟网卡,这块虚拟网卡连接在VMnet8虚拟交换机上与虚拟系统的虚拟网卡进行通信,即它的功能是让主机能够和VMnet8网段通信,但不是为VMnet8网段提供路由功能,去掉这个虚拟网卡Guest仍然可以上网,但是主机无法再访问VMnet8网段,即主机和虚拟机无法再进行通信。

3.VMware Network Adepter VMnet8虚拟网卡的IP地址是在安装VMware时由系统指定生成的,虚拟机虚拟出来的NAT网络所处的网段和VMware Network AdepterVMnet8虚拟网卡所处的网段是相同的,所以主机和虚拟机的两个虚拟网卡之间可以正常通信。

4.在NAT模式下,虚拟机虽然处于内部局域网,但是它是可以访问外网的,因为这时候宿主计算机相当于一台开启了DHCP功能的路由器,宿主机真实的物理网卡(即NAT device)连接着Network,此时虚拟机相当于局域网中的一台真实主机,所以虚拟机可以通过宿主计算机的DHCP来动态获得网络参数,相当于一台计算机通过路由器连接了外部互联网。宿主机可以访问虚拟机,但是局域网内其他主机是无法访问虚拟机的,因为NAT的网络在vmware提供的一个虚拟网络里。(可以通过设置ssh来实现访问,见文末设置步骤)

NAT模式的原理如下:

VMware Ubuntu虚拟系统NAT模式实现网络连接设置步骤:

 

1.在VMware菜单栏中选择“虚拟机”à“设置”,打开的窗口中左侧选择“网络适配器”,右侧选择“自定义”:VMnet8(NAT模式),然后点击“确定”,如下图:

2.在VMware菜单栏选择“编辑”à“虚拟网络编辑器”,首先点击右下方“更改设置”进入配置更改模式,点击选择VMnet8虚拟交换机,设置如下:

3.由于主机的虚拟网卡VMwareNetwork Adapter VMnet8和虚拟机虚拟网卡的IP地址处于同一个网段,子网掩码、网关、DNS等参数都相同,在本机的网络和共享中心中打开更改适配器设置,查看虚拟网卡VMware Network Adapter VMnet8的网络配置信息,在上一步打开的虚拟网络编辑器中依次检查修改子网IP,子网掩码,NAT设置(由于开启了DHCP功能,所以正常情况下默认值即是符合要求的)。设置完后点击确定。

4.开启虚拟机,网络设置和上面桥接模式时一样,选择自动获取。

至此完成所有设置,主机ping 虚拟机,虚拟机ping主机(物理网卡IP),虚拟机ping外网都可以成功。

注:网上很多资料采取了为虚拟机设置静态IP的形式,可以在Ubuntu系统桌面右上角直接选择Edit Connection…修改,也可以根据网上的教程通过编辑linux的网络配置文件来更改。

要想主机通过远程连接向虚拟系统中传送文件,需要配置Ubuntu的ssh功能。配置过程见文档尾。

三、主机模式(host-only)

 

1.在此模式下所有的虚拟系统之间可以相互通信,但是虚拟系统所处的虚拟网络和宿主机所处的真实网络实际上是被隔离开的。尽管被隔离,但是在这种模式下虚拟系统和主机可以通信,相当于两台机器直接用双绞线相连,这时宿主机不再为虚拟机提供路由服务,所以虚拟机不能和外部Network进行通讯。

2.VMware Network Adepter VMnet1是Host用于与Host-Only虚拟网络进行通信的虚拟网卡,但Host-Only网络没有NAT服务,所以虚拟网络是不能连接到外部的互联网的,虚拟机之间形成的虚拟网络是一个全封闭的网络,和外部的唯一联系就是虚拟机能够和主机进行通信。

3.VMware Network Adepter VMnet1虚拟网卡的IP地址也是VMware系统指定的,VMwareNetwork Adepter VMnet1虚拟网卡和虚拟机的虚拟网卡在同一个网段,这种模式下物理网卡和虚拟机的虚拟网卡不在同一个网段。

注:NAT模式与主机模式十分相似,主要不同之处即在于主机模式中宿主机不再具备NAT功能,即不再相当于虚拟机访问Internet的路由器。

 

NAT模式下实现外部网络对虚拟机(ssh)访问功能设置步骤

即使是主机与虚拟机置于同一网段内,主机也不能直接ssh连接虚拟机,还需要做一步端口映射。

1、在VMware系统菜单下选择“编辑:,进入虚拟网络编辑器,选择“NAT设置”,进入“NAT设置”后,在“端口转发”下选择“添加”按钮,添加一条NAT映射规则。其中主机端口即宿主物理网卡的端口,可以任意填写端口号,因为我们这里要实现ssh远程登录功能,这里填写“22”。虚拟机IP地址按照虚拟机实际情况填写,虚拟机端口是22(因为外部设备最终是要通过22端口来访问虚拟机的ssh服务的)。

如果在vmware中建立了多个虚拟机,有几个需要在主机ssh连接,那么就需要配几条端口转发。

2.开启虚拟机在命令行窗口进行ssh配置:(参照网络教程失败了很多次,后来发现在完成了第一步配置之后再按下面的步骤设置即能成功)

(1)检查ssh状态:ssh localhost ssh

connect to hostlocalhost port 22: Connection refused 表示没有安装ssh服务

(2)下载安装ssh:sudo apt-get install openssh-server

(3)启动ssh server:sudo /etc/init.d/ssh start

(4)检查启动状态:ps -e|grep ssh

出现 ssh-agent 和sshd  等表示已经启动

(5)设置root密码:sudo passwd root,根据提示输入

(6)在主机中使用WinSCP连接虚拟机并向虚拟机的桌面发送一个文件,成功。

 

 

VMnet0:用于虚拟桥接网络下的虚拟交换机

VMnet1:用于虚拟Host-Only网络下的虚拟交换机

VMnet8:用于虚拟NAT网络下的虚拟交换机

VMware Network Adepter VMnet1:Host用于与Host-Only虚拟网络进行通信的虚拟网卡

VMware Network Adepter VMnet8:Host用于与NAT虚拟网络进行通信的虚拟网卡

VMnet8和VMnet1提供DHCP服务,VMnet0虚拟网络则不提供。

Guess you like

Origin www.cnblogs.com/sky1130/p/11718475.html