Giving My Lab A Real Router

Part 3 of the Beyond Port 1433 series. New here? Start with Part 0.

My lab’s gateway was my laptop, but to reach Azure, it needed a real router. As a data professional who comfortably lived outside of the networking domain, this was definitely a knowledge stretch for me. I was definitely hesitant to commit to put a router VM in front of a working cluster. But this was such a good learning experience to see how the entire machine works together and impacts connectivity at the SQL Server level. To be able to have my lab reach out beyond my home network, I went with OPNsense which is a free open-source firewall and router built on FreeBSD. By the end of this post, you’ll see how a router with the same address can support the end to end connectivity from on-prem to Azure without having to change a single lab VM.

Architecture diagram showing a Hyper-V SQL Server lab connected to an Azure environment through a WireGuard tunnel, with SQL replication and a cloud witness.
Part 3 adds one box, and everything else routes through it.

What A Gateway Is, And Why My Laptop Wasn’t Enough

A gateway is the subnet’s (neighborhood’s) exit. Any traffic for an address outside the lab goes to it, and every lab VM points at 192.168.100.1. Until now, .1 was the laptop running Windows NAT which does one job and that is to share the laptop’s internet with the lab. There are three main things that the tunnel to Azure needs that Windows NAT cannot do, and that is:

  1. Know about other networks. NAT doesn’t know “10.20.x.x goes into the tunnel, and everything else goes to the internet.” It only knows “everything goes to the internet.”
  2. It cannot host the VPN. The lab’s end of the tunnel has to live on the gateway itself.
  3. Keeping real addresses. NAT rewrites the source address on everything, so Azure’s Network Security Groups (NSGs in Part 2) would never see 192.168.100.x.

Something to keep in mind as far as a differentiator goes between NAT and routing. NAT will hide many addresses behind one. Routing forwards the traffic with its addresses intact.

Before-and-after network diagram showing an OPNsense router enabling routing from lab VMs through the laptop’s default switch to a Wi-Fi home router.
Same exit with a smarter gatekeeper.

Same Address With A New Device

The router VM will take over 192.168.100.1. Every VM already points there, so zero VMs need any reconfiguration. They never know the device behind .1 changed. There will be two network cards, WAN (acts as the “outside door”) on the Hyper-V’s Default Switch, and LAN (acts as the “inside door”) on the SQLLabSwitch. You may be asking yourself “Why the Default Switch and not Wi-Fi?”. That’s because it shares the laptop’s conneciton without bridging the Wi-Fi adapter, so the home router is never aware of a new device.

Building The Router VM

When building the router VM, I chose Generation 2, with Secure Boot off. That’s because OPNsense runs on FreeBSD and won’t boot with it. I gave it static memory because a router shouldn’t have RAM reclaimed. 2 vCPUs, 20GB disk, second NIC on SQLLabSwitch, automatic checkpoints off. Here’s the PowerShell equivalent so you don’t have to click through Hyper-V if you’re interested in following along:

New-VM -Name SQLLab-RTR -Generation 2 -MemoryStartupBytes 4GB -NewVHDPath 'C:\Hyper-V\SQLLab-RTR.vhdx' -NewVHDSizeBytes 20GB -SwitchName 'Default Switch'
Set-VMMemory -VMName SQLLab-RTR -DynamicMemoryEnabled $false
Set-VMProcessor -VMName SQLLab-RTR -Count 2
Set-VMFirmware -VMName SQLLab-RTR -EnableSecureBoot Off
Add-VMNetworkAdapter -VMName SQLLab-RTR -SwitchName SQLLabSwitch
Add-VMDvdDrive -VMName SQLLab-RTR -Path '<path to OPNsense dvd .iso>'
Set-VMFirmware -VMName SQLLab-RTR -FirstBootDevice (Get-VMDvdDrive -VMName SQLLab-RTR)
Set-VM -Name SQLLab-RTR -AutomaticCheckpointsEnabled $false
Hyper-V virtual machine settings showing network adapter configuration with Default Switch selected.
Hyper-V virtual machine network adapter settings showing the SQLlabSwitch virtual switch configuration.
Hyper-V virtual machine memory settings showing 2048 MB of RAM and disabled Dynamic Memory.
Hyper-V New Virtual Machine Wizard summary showing a Generation 2 virtual machine named SQLLAB-RTR with 2048 MB memory and a default network switch.

Install, And Figuring Out Which Door Is Which

With the VM built, I grabbed the latest image from the OPNsense download page and attached it to the new VM. I booted it from the OPNsense ISO and immediately hit my first issue and the installer refused to run with 2GB of RAM. The live installer copies itself to disk and needs at least 3GB to do it. I adjusted the VM to 4GB, reran the install with UFS (simpler and lighter than ZFS for a tiny router), and dropped it back to 2GB once it was done.

OPNsense doesn’t know which card is plugged into which Hyper-V switch. It only shows MAC addresses. So I matched them up from the laptop:

Get-VMNetworkAdapter -VMName SQLLab-RTR | Format-Table Name, SwitchName, MacAddress


The Default Switch card became WAN, the router’s “outside door” to the internet. The SQLLabSwitch card became LAN, its “inside door” to the lab. I gave LAN a temporary address of 192.168.100.2 instead of .1, because my laptop still owned .1 and the lab was still running on it. That let me finish and test the router without touching anything live. I also turned OPNsense’s DHCP server off, since every machine in my lab uses a fixed address.
When it came back up, the console showed it in two lines:

LAN (hn1) -> v4: 192.168.100.2/24
WAN (hn0) -> v4/DHCP4: 172.23.121.6/20


hn0 and hn1 are FreeBSD’s names for Hyper-V network cards. DHCP4 means the Default Switch handed the WAN its address automatically. One gotcha worth calling out: the Default Switch picks a new 172.x range every time the laptop restarts, so never type a 172.x address into anything permanent.


A quick ping to 1.1.1.1 from the router console proved it could reach the internet, and https://192.168.100.2 loaded from my laptop. (The certificate warning is expected as the router signs its own cert.)

Checking DNS Before The Swap

Before swapping anything, I checked DNS since that is something that can break on you. If my DC forwarded internet lookups to 192.168.100.1, replacing the device behind that address could take name resolution down with it.

Get-DnsServerForwarder


No forwarders, root hints on. My DC resolves internet names on its own, so it never depended on the laptop. Before you replace a gateway, check what else was dependent on it.

The Swap

With the router built and tested at .2, it was time for the swap. I took a fresh checkpoint on every VM involved, and a quick check that my laptop’s NAT had no port forwards I’d lose.

Checkpoint-VM -Name SQLLab-DC, SQLLab-SQL1, SQLLab-SQL2, SQLLab-RTR -SnapshotName 'Before router swap'
Get-NetNatStaticMapping


That was empty. Then the laptop gave up .1 and moved to .5:

Remove-NetNat -Name SQLLabNAT -Confirm:$false
Remove-NetIPAddress -InterfaceAlias 'vEthernet (SQLLabSwitch)' -IPAddress 192.168.100.1 -Confirm:$false
New-NetIPAddress -InterfaceAlias 'vEthernet (SQLLabSwitch)' -IPAddress 192.168.100.5 -PrefixLength 24


Not going to lie, I was definitely holding my breath here. This is something I hadn’t done before and was really cautious about breaking something I didn’t want to break. Back in the router console, option 2 one more time, LAN becomes 192.168.100.1 and that’s it. Not one VM changed a setting! They all still point at .1, and they never knew the device behind it changed. The cluster stayed up the whole time, because the nodes talk to each other directly on the lab switch. Only the lab’s internet access paused for that minute. Phew!

Proving Everything Works With A tracert

Time to prove it. From SQL1, I checked the internet, DNS and the cluster, then ran tracert:

Test-NetConnection 1.1.1.1 -Port 443
Resolve-DnsName www.microsoft.com
Get-ClusterNode | Format-Table Name, State
tracert -d 1.1.1.1
HopAddressWhat it is
1192.168.100.1OPNsense, receiving on its LAN door
2172.23.112.1The laptop’s Default Switch gateway
3192.168.0.1My home router, then the internet


Before the swap, lab traffic went straight from my laptop’s NAT to my home router. Now OPNsense sits in the middle. That extra hop is exactly what I wanted, because it’s where the tunnel to Azure attaches in Part 4.
Here’s the part that confused me at first. Hop 2 is 172.23.112.1, not the router’s WAN address of 172.23.121.6. Each line in tracert is the device that received the traffic, listed by its receiving-side address. The router’s WAN is the sending side of hop 1, so it never shows up on its own line. And the first two hops are under a millisecond because they never leave the laptop’s memory. Only hop 3 crosses Wi-Fi.

Network interfaces list showing WAN and LAN 10Gbase-T full-duplex connections with IP addresses 172.23.121.6/20 and 192.168.100.1/24.
LAN on .1: the router now owns the lab’s front door.
Interfaces assignments table showing WAN, LAN, and WireGuard interfaces with device mappings and management commands.
That third interface, WGAZURE will show up in Part 4.

How To Undo It

If you ever need to back out, it’s the swap in reverse. In the router console, use option 2 to set LAN back to 192.168.100.2, so .1 is free again. Then on the laptop:

Remove-NetIPAddress -InterfaceAlias 'vEthernet (SQLLabSwitch)' -IPAddress 192.168.100.5 -Confirm:$false
New-NetIPAddress -InterfaceAlias 'vEthernet (SQLLabSwitch)' -IPAddress 192.168.100.1 -PrefixLength 24
New-NetNat -Name SQLLabNAT -InternalIPInterfaceAddressPrefix 192.168.100.0/24

Living With A Router

A few new day-to-day rules came out of this. The router starts first, then the DC, then the SQL nodes. I start it by hand rather than auto-starting it. If I forget, nothing will break and the cluster and AG keep running, because the nodes talk to each other directly on the lab switch. The lab just can’t reach the internet (or, soon, Azure) until the router is up. It runs happily on 2 GB of static memory, and new lab VMs follow the same recipe as always: SQLLabSwitch, a 192.168.100.x address, gateway .1, DNS .10.

Build It Yourself

Here is a PDF guideline for you to follow if you’d like to build this section out yourself:

TL;DR

  • My laptop’s Windows NAT could share the internet, but it couldn’t route to another network or host a VPN.
  • OPNsense in Hyper-V took over the lab’s gateway at the same address (.1), so not one lab VM changed a setting.
  • Its WAN sits on Hyper-V’s Default Switch, so my home Wi-Fi was never touched.
  • Each tracert line is the device that received the traffic, which is why the router’s WAN address never shows up.

Next up is Part 4, where this router earns its keep: building a WireGuard tunnel from my laptop to Azure. New here? Start with the hub post, Part 0. And network folks, would you have gone for pfSense, a different design, or no router at all? Tell me why.

One response to “Giving My Lab A Real Router”

Leave a Reply