Hello, dear readers, please do not throw tomatoes at me because of the strange use of virtualization, I have a fairly good wireless network at home with a ping of less than 1 ms and a speed of about 90 Mbit, there is only one wall between the router and the computer and it is without metal reinforcement. Wire to the company is problematic. I needed to keep the server on Linux in constant access to the external network and so that it worked in the background and started itself when the computer was turned on, since Windows 10 pro has hyper-v, so why not use it. But I was very upset when virtual machines started to lose contact with the outside world for periods, ping losses reached 20-40%.
The virtual switch was configured on the external network, i.e. forwarding the bridge to the local wireless network. After working one day, I found that the site is often unavailable from the outside, and after 30 seconds it works again, and then it was repeated. First, I couldn’t understand what was happening for a long time, took out a laptop, started pinging a virtual machine, pings go and at that moment the site is already open, then started pinging from the virtual console, found breaks, launched ping from the host system at the same time, everything is perfect, 0 % loss.
For three days I crawled around in different forums looking for an answer, but everywhere people said that the host system takes resources from virtual machines, that Windows 10 has such a curve and it’s necessary to install a server system for such purposes, but the reason turned out to be not that.
')
It turns out that when creating a bridge, virtual network interfaces with different mac-addresses go through my network card, as a result one network card goes to the network with different mac, if it works fine on a wired network, in a wireless network this behavior causes inadequate network operation, Some wi-fi cards will not have such problems, but most of them have problems.
To solve the problem with the stability of the connection of virtual machines, you need to use NAT and forward ports. There are many instructions on the web how to do this, but with a simple opening of access on an external network interface card, this will not work.
And now, in order, first we need to create a virtual switchboard with the “internal network” type, a virtual interface will appear in the network connections, it will be a link to the virtual machines. For virtual machines, we assign IP addresses on a subnet different from our local network. If we have a subnet 192.168.0.0/24 in our local network, then in virtual we make, for example, 192.168.137.0/24, our virtual machine is set to 192.168.137.100, and the virtual interface is 192.168.137.1 and this will be the gateway for our machines.
And now about NAT, the usual way of sharing the interface will work until the first reboot of the host machine, most likely the virtual interface appears in the system later than the real network card with its shared access and NAT just flies, but we need everything to work right away when you turn on the computer.
This instruction comes to the rescue, open the PowerShell console on behalf of the administrator and enter there:
New-NetNat -Name nat1 -InternalIPInterfaceAddressPrefix 192.168.137.0/24
Once again, we check that the virtual network card on the host system does not get lost ip, now about port forwarding in the same console
netsh interface portproxy add v4tov4 listenport=8080 connectaddress=192.168.137.100 connectport=80 protocol=tcp
As a result, when accessing our computer via port 8080, the request will be redirected to our virtual machine from ip 192.168.137.100 to port 80y.
Then you can forward the 80th port from the router to our machine at 8080 and the virtual web server will be accessible from the outside, you can do the same with ftp, ssh and other necessary services.
I hope that someone else, faced with such a problem, will not reinstall the drivers, rearrange different checkboxes in the hyper-v settings and update the kernel in Linux, but immediately make NAT. Such a setting is not suitable for combat servers, but for all home temporary servers it will be fine.