Using a VyOS Router with Hyper-V

Please share with your friends...
  • 1
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
    1
    Share

Preparation

VyOS

Download the latest amd64 release from the VyOS website.

For the purpose of the instructions in this guide, it is assumed you have downloaded the VyOS ISO file to the C:\ISO directory on your computer. If you have used a different location, please adjust the following instructions accordingly.

Hyper-V

Before installing VyOS, we need to create a new Virtual Machine on the Hyper-V host. The following Virtual Machine settings are recommended:

Hyper-V Virtual Machine Settings
Bios Generation 1
Processor Processors 1
Memory Memory 256 MB (Static)
Drive Hard Drive 2 GB (Dynamically Expanding)
Network Network Adapter 10 Gbps (WAN/External)
Network Network Adapter 10 Gbps (LAN/Internal)

The first Network Adapter is used for all external (WAN) communications between the router and the outside world. It is assumed that this interface will be configured using DHCP.

The second Network Adapter is used for all internal (LAN) communications between the router and its routed networks. VLANs are used to facilitate an almost unlimited number of routed networks through this second Network Adapter interface.

As we are implementing some advanced VLAN options on the second Network Adapter, it is not possible to create a new Virtual Machine using Hyper-V Manager – as these options are not exposed through the user interface. Instead, we must create a Virtual Machine from the command-line using Windows PowerShell.

To create a new Hyper-V Virtual Machine for VyOS, perform the following steps from the Windows PowerShell ISE (Run as Administrator).

  1. Set scripting parameters, using the following commands:
    $VyOS_Name = "VyOS Router"
    $VyOS_ISO = "C:\ISO\vyos-1.1.6-amd64.iso"

    Change VyOS Name as required. Ensure VyOS ISO path is correct.

  2. Set scripting variables, using the following commands:
    $VirtualHardDiskPath = (Get-VMHost).VirtualHardDiskPath
    $FastestPhysicalAdapter = (Get-NetAdapter -Physical | Where-Object {$_.Status -eq 'Up'} | Sort-Object $_.LinkSpeed | Select-Object -First 1).Name
    If (((Get-VMSwitch -SwitchType External).Name) -eq $null) {New-VMSwitch -Name 'External' -NetAdapterName $FastestPhysicalAdapter -AllowManagementOS $true -Notes 'External Switch'}
    $ExternalSwitch = (Get-VMSwitch -SwitchType External).Name

    The above determines if an external interface exists, and if not, then creates one.

  3. Create a Hyper-V Private virtual switch, using the following commands:
    New-VMSwitch -Name "$VyOS_Name - Private Switch" -SwitchType Private -Notes "$VyOS_Name - Private Switch"

    The commands produce output similar to the following:

    Name                         SwitchType NetAdapterInterfaceDescription
    ----                         ---------- ------------------------------
    VyOS Router - Private Switch Private
  4. Create the VyOS Virtual Machine, using the following commands:
    New-VM -Name $VyOS_Name -Generation 1 -MemoryStartupBytes 256MB -NewVHDPath $VirtualHardDiskPath\$VyOS_Name.vhdx -NewVHDSizeBytes 2GB -SwitchName $ExternalSwitch
    Set-VM -VMName $VyOS_Name -ProcessorCount 1 -StaticMemory -Notes "VyOS Router`r`nCreated:`t$((Get-Date).ToString())`r`nSource:`t$(Split-Path $VyOS_ISO -Leaf)"
    Rename-VMNetworkAdapter -VMName $VyOS_Name -Name "Network Adapter" -NewName "Network Adapter (External)" 
    Add-VMNetworkAdapter -VMName $VyOS_Name -Name "Network Adapter (Internal)" -SwitchName "$VyOS_Name - Private Switch"
    Set-VMNetworkAdapterVlan -VMName $VyOS_Name -VMNetworkAdapterName "Network Adapter (Internal)" -Trunk -NativeVlanId 0 -AllowedVlanIdList 1-4094

    The command will produce output similar to the following:

    Name        State CPUUsage(%) MemoryAssigned(M) Uptime   Status             Version
    ----        ----- ----------- ----------------- ------   ------             -------
    VyOS Router Off   0           0                 00:00:00 Operating normally 7.0
  5. Connect the installation ISO to the VyOS Virtual Machine, using the following command:
    Set-VMDvdDrive -VMName $VyOS_Name -Path $VyOS_ISO
  6. Start the VyOS Virtual Machine, using the following command:
    Start-VM -Name $VyOS_Name

    The VyOS Virtual Machine will start and boot to the login prompt.

Leave the Windows PowerShell ISE window open.


Please share with your friends...
  • 1
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
    1
    Share

7 comments

  1. Hey Chris,
    Nice work! Easy to follow as well. I’ve been doing something similar with 2012R2 Routing and Remote Access with VLANs but I have 2 x hosts running 2012R2 (both with a single NIC) and then have three VLANs that need to be routed. I needed both hosts to be in the domain so I can configure constrained delegation and move VMs between hosts. Have you tried this config on two hosts?

    1. Hi Martin!

      Thanks for you comments 🙂 What you are currently doing with RRAS should be quite easy with VyOS – although I haven’t specifically tried it.

      Kind Regards,
      Chris.

  2. Hi Chris,

    It works! Just started learning VyOs and this guide helps me a lot!
    Thank you very much.

    wks_adm

  3. Hi Chris,

    It is possible that I can communicate with the VM into my local machine? I tried to use the Internal Network adapter but I can’t ping the VM’s IP. Thank you in advance.

    1. Hi wks_adm,

      The VyOS configuration presented in the tutorial uses NAT in the same way as a home broadband router, so by default it is not possible for your host machine on the “outside” to communicate with a virtual machine on the “inside”. However, like a router, in VyOS you can setup port forwarding (Desination NAT) – so you can manually setup rules to allow individual outside connections through.

      For example, the following commands enable port forwarding for RDP (TCP 3389) to host 172.16.1.20:

      set nat destination rule 10 description 'RDP to 172.16.1.20:3389'
      set nat destination rule 10 destination port 3389
      set nat destination rule 10 inbound-interface eth0
      set nat destination rule 10 protocol tcp
      set nat destination rule 10 translation address 172.16.1.20
      set nat destination rule 10 translation port 3389

      RDP to the VyOS eth0 external address. Use different destination port addresses for multiple hosts with the same service.

      Hope that helps!
      Chris.

  4. Hi Chris,

    Fantastic! I was looking this for kind of tutorial, I followed all the instructions and it works like a Charm
    Thank you very much for spending your time making this great tutorial.

Leave a Reply