Configuration of internal vswitch under Hyper-V and SSH connection to Linux virtual machines

Source: Internet
Author: User
Tags ssh server

In the recent work to run the Ubuntu16 instance in Windows Server 2016/hyper-v 10, you need to create a "plug and Play" image file, which is installed to ssh in from outside. Before I used Hyper-V, I was accustomed to using external vswitch as an interface for external communication of virtual machines in the network dynamic assignment IP mode. The virtual machine in this mode is equivalent to a new host in the LAN, and it is very convenient to obtain the information of its own IP and gateway through DHCP.

But this time the intranet implementation is static IP configuration scheme, each physical machine has a fixed and only 1 IP. Because processes within a virtual machine need to communicate with other virtual machines, only internal vSwitch can be used. In this mode, the equivalent of the physical and virtual machine components as a new subnet, the physical machine plays the role of Gateway, the virtual machine external communication must pass through the physical machine forwarding. The students who are familiar with Vmvare will find that this topology is often called Nat.

1. The Ubuntu-based ISO creates a virtual machine, which is a simple step, and Hyper-V provides a very convenient graphical interface for operation. Since the next steps require networking to download the installation package, configure external VSwitch for the Ubuntu instance first.

2. Configure the network connection for the Ubuntu instance (DHCP by default).

Go in with Hyper-V Connect and append the following to the/etc/network/interfaces file:

Auto eth0iface eth0 inet staticaddress 192.168.1.100netmask 255.255.255.0gateway 192.168.1.1

It is recommended to use the Ifconfig command to confirm the name of the network card is not for eth0.

Type the shell and restart the network:

1 sudo /etc/init.d/networking restart

3. Install the SSH server program for Ubuntu instance. Go in with Hyper-V connect and type the shell:

1 sudo apt-get purge openssh-server2sudoinstall -y openssh-Server  3sudo service sshd start

4. Close the Ubuntu instance and export it. Type PowerShell:

1 " Ubuntu16 " 2 " F:\vm-export " 3 STOP-VM-Name $VmName4 export-vm-name $VmName-path $Dstination

This completes the creation of the virtual machine image, which relies on the VHDX format file under the $destination directory. Change the physical machine to start the installation of the virtual machine image.

1. Create internal VSwitch, using PowerShell:

1 $HyperVVirtualSwitchName = "Isinternalswitch" 2 new-vmswitch-name $HyperVVirtualSwitchName-switchtype Internal3 Get-netadapter | where {$_. Name-match $HyperVVirtualSwitchName} | New-netipaddress-ipaddress "192.168.1.1"-prefixlength 24

2. Create a new instance based on the exported Ubuntu image and Vswitch. Type PowerShell:

1 $VMName="Ubuntu16"2 $HyperVVirtualSwitchName="Isinternalswitch"3 $VMPath="F:\vm-import\ $VMName"4 $VHDX="$VMPath \virtual Hard DISKS\UBUNTU16-TENSORFLOW10.VHDX"5New-vm-name$VMName-switchname$HyperVVirtualSwitchName-path$VMPath-vhdpath$VHDX-generation 16Start-vm-name$VMName

3. The last step, set the port forwarding and opening firewall. Type the Windows Batch command:

1 netsh interface portproxy delete v4tov4 listenport=222 netsh interface portproxy add v4tov4 listenport =22 connectport=22 connectaddress=192.168.1.1003 netsh advfirewall firewall delete rule name= "Ubuntu_ssh"  4dir=in localport=22 action=allow

In this, Internal vswitch configuration complete, with putty to native localhost or virtual machine located on the remote machine LAN IP to initiate an SSH connection request, Success!

Configuration of internal vswitch under Hyper-V and SSH connection to Linux virtual machines

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.