Moving from Ubuntu to Windows 10, Hyper-V and getting rid of the iron router

Having bought a new laptop, I regretfully noticed that my beloved Ubuntu no longer supports the work of the sensors and the fans are constantly buzzing, making the work not comfortable. At the same time, if you download the pre-installed Windows 10 Pro from the original hard drive, then there is a pleasant silence for the ear. While it was cool outside (and at home), it was tolerable. But as the heat came, patience came to an end. It was decided to migrate to Windows.

In my work, I use numerous virtual machines for building, testing and debugging software being developed. Windows 10 Pro includes Hyper-V virtualization - once the money is paid, you have to use it! In Ubuntu, I used libvirt and virtual machines integrated into one internal virtual network.

Transferring Windows from the original disk to the SSD and transforming the virtual machine images into hyper-v format, with a pain in my heart, I began to master the new operating system.

It turned out not so scary! Virtual desktops were replaced with windows desktops (unfortunately only horizontal), the console replaced the WSL console (Windows Subsystem for Linux), for X11 applications VcXsrv was installed and added to the autorun, virtual machines started working in Hyper-V and even OSX was launched.

The native terminal was not entirely convenient and without tabs, so it was mercilessly replaced with the xfce4 terminal, which is launched via a shortcut with a hidden console linux window:

image

Object:

C:\Windows\System32\wscript.exe ./runhidden.vbs bash -c "export DISPLAY=:0.0; export GDK_DPI_SCALE=1.2; cd ~; exec xfce4-terminal"

Script code for launching an application with a hidden window (hiding the native console, which opens when you start X11 applications from the command line), googled on the Internet:

' Simple command-line help.selectcase WScript.Arguments(0)
case"-?", "/?", "-h", "--help"
  WScript.echo "Usage: runHidden executable [...]" & vbNewLine & vbNewLine & "Runs the specified command hidden (without a visible window)."
  WScript.Quit(0)
endselect' Separate the arguments into the executable name' and a single string containing all arguments.
exe = WScript.Arguments(0)
sep = ""for i = 1to WScript.Arguments.Count -1' Enclose arguments in "..." to preserve their original partitioning.
  args = args & sep & """" & WScript.Arguments(i) & """"
  sep = " "next' Execute the command with its window *hidden* (0)
WScript.CreateObject("Shell.Application").ShellExecute exe, args, "", "open", 0

As a result, it turned out like this:

image

I have to travel often, especially for traveling, I had a small TP-LINK router WR703N stitched OpenWRT:

image

VPNs are configured on the router to work machines and for Internet access. If there is a cable, it connects to the network through a cable, distributes over WiFi for a laptop, phones and other devices, if only WiFi, then connects to a laptop through a cable. You can set up a WiFi client and an access point at the same time, but the signal quality drops, trips and speed drops begin.

In this regard, the idea arose to get rid of this router altogether (at the same time increasing the connection bandwidth), the coil of wires and the power supply, replacing it with a virtual router. Obviously, all virtual machines and Windows should be combined into one local network.

Launch Hyper-V Manager and select Virtual Switch Manager. We create a new internal virtual switch that will serve our virtual local area network. Let's call it LAN Internal:

image

We will go to the Internet through a wireless adapter and an Ethernet cable. We create two external virtual switches, not forgetting to remove the checkbox "Allow the operating system to share this network adapter" - there is no need for Windows to go directly to the Internet.

Virtual switch for WiFi:

image

Virtual switch for ezernet cable:

image

I selected server-based Ubuntu 16.04 as the operating system of the virtual machine of the router. Why 16.04? Because at 18.04 the simple network settings in / etc / network / interfaces were replaced with netplan - I don't want to! We create a new virtual machine and add our virtual switches to it:

image

On the Security tab, either disable the safe boot, or select the Microsoft UEFI Certificate Authority and set the operating system as usual.

After installation, we go into the newly installed system and check the network interfaces with the ifconfig command. External connections via cable and WiFi can get ip addresses if they are connected and active. If addresses are not received, use the address retrieval utility:
dhclient eth0 eth1 eth2

Internal will be without an address, because the dhcp server is not working in our local network.
In my case, eth0 is external ezernet, eth1 is a local network, eth2 is an external wireless connection (in the order of adding network cards). The local area network will be 192.168.3.0.

Edit the network settings in / etc / network / interfaces using, for example, the nano editor:

source /etc/network/interfaces.d/*
# The loopback network interface
auto lo
iface lo inet loopback
# The primary network interface
allow-hotplug eth0
iface eth0 inet dhcp
# Internal LAN
auto eth1
iface eth1 inet static
        address 192.168.3.1
        netmask 255.255.255.0
        network 192.168.3.0
        broadcast 192.168.3.255# The primary network interface
allow-hotplug eth2
iface eth2 inet dhcp

Reboot the router and go to it again. Now all network interfaces must have addresses (external if they have a connection).

A lot of articles are devoted to setting up routing and there is a sufficient amount of material, so let's go quickly through the minimum setting.

Install the applications we need:
sudo apt install dnsmasq iptables-persistent netfilter-persistent openvpn

Allow forwarding ip packets:

cat > /etc/sysctl.d/10-forwarding.conf 
net.ipv4.ip_forward=1

Configuring the firewall:

cat > /etc/iptables/rules.v4
# Generatedby iptables-save v1.6.0on Fri Jun 2211:13:102018
*nat
:PREROUTING ACCEPT [2901:568651]
:INPUT ACCEPT [707:80315]
:OUTPUT ACCEPT [445:30025]
:POSTROUTING ACCEPT [14:1200]
-A POSTROUTING -o eth0 -j MASQUERADE
-A POSTROUTING -o eth2 -j MASQUERADE
-A POSTROUTING -o tun+ -j MASQUERADE
COMMIT
# Completed on Fri Jun 2211:13:102018
# Generatedby iptables-save v1.6.0on Fri Jun 2211:13:102018
*filter
:INPUT ACCEPT [57264:68964200]
:FORWARD ACCEPT [0:0]
:OUTPUT ACCEPT [44820:7558046]
-A FORWARD -m conntrack --ctstate RELATED,ESTABLISHED -j ACCEPT
-A FORWARD -i eth1 -o tun+ -j ACCEPT
COMMIT
# Completed on Fri Jun 2211:13:102018

Configure dhcp server and name server:

cat > /etc/dnsmasq.d/router.conf 
dhcp-authoritative
domain-needed
localise-queries
read-ethers
bogus-priv
expand-hosts
local-service
domain=lan
server=/lan/
dhcp-leasefile=/tmp/dhcp.leases
interface=eth1
dhcp-range=lan,192.168.3.100,192.168.3.249,255.255.255.0,12h

Reboot and get a working router for Windows and other virtual machines!

image

We configure on the openvpn router and enjoy life without additional hardware and cables.

But let me ask you, what about the phone and other gadgets?

A simple solution is to use Mobile Hotspot built into Windows 10! But not everything is so simple. Mobile hotspot does not want to activate on the virtual interface of our VLAN! Bad luck ...

image

Googling the emerging problem, several alternative utilities were found to launch a mobile access point. Unfortunately, they were all paid. It was decided to write my application, with some buns, free and open source.

Having suffered a week, the application was written (and at the same time a previously unknown beast was mastered - Visual Studio):

image

In addition to activating the access point, the application can be started at login, activate the launch point and close the application after activation.

Source code is available on github .
For those who can not or who are too lazy to collect from source, the application (free of charge, without SMS and any advertising) is available in the Windows Store NoWiFi .

Thus, the task was solved, the old router finally retired, and the place in the backpack was cleared!

At this I have everything, thank you all for your attention and patience when reading such tedious material!

Also popular now: