pfSense Edge Firewall Lab on Hyper-V

Overview


This guide builds a pfSense virtual machine on a Windows Hyper-V host and places it at the edge of a small Active Directory lab: two domain controllers and one member server. When finished:

  • Every server reaches the internet only through pfSense.
  • Servers sit on a management VLAN (101) carried by the UniFi Dream Router (UDR) but routed and filtered by pfSense.
  • Client VMs sit on an internal VLAN (102) that exists only inside the Hyper-V host and can reach only the AD ports on the domain controllers, plus web traffic out.
  • pfSense resolves the AD domain through the DCs, and the DCs forward internet lookups through pfSense.
  • pfSense is managed over HTTPS and key-only SSH from a single admin workstation.

Tested with pfSense CE 2.9.2 (Netgate Installer v1.2), Windows Server domain controllers and Hyper-V on Windows.

Final Topology


            Internet
               |
        UniFi Dream Router  (10.1.10.0/24 untagged, VLAN 101 tagged, VLAN-only)
               |
   Host NIC  ->  Hyper-V switch "VLAN10-External" (External)
               |                         |
        untagged (WAN)            access VLAN 101
               |                         |
          hn0 WAN                  hn1 EXT_V101_MGMT
          10.1.10.54 (DHCP)        192.168.10.254/24
               \                       /
                +---- pfSense-FW01 ---+
                          |
                     hn2 TRUNK (VLAN 102-199)
                          |
         Hyper-V switch "LAB-Internal" (Private)
                          |
                    access VLAN 102
                          |
          hn2.102 INT_V102_CLIENTS 192.168.20.254/24
                          |
                       Client1 (DHCP)

   VLAN 101 (192.168.10.0/24): DC01 .10   SRV01 .21 (DC)   SRV02 .22

Addressing and Naming Plan


NetworkVLANSubnetGatewayCarried BypfSense Interface
WANUntagged10.1.10.0/24UDRUDRWAN (hn0)
Server management101192.168.10.0/24192.168.10.254UDR (VLAN-only) + Hyper-VEXT_V101_MGMT (hn1)
Clients102192.168.20.0/24192.168.20.254Hyper-V Private switch onlyINT_V102_CLIENTS (hn2.102)
HostRoleIPDNS
pfSense-FW01 (fw01lab.lab.local)Edge firewall10.1.10.54 / 192.168.10.254 / 192.168.20.2541.1.1.1 + domain overrides
DC01DC, GC, DNS192.168.10.10Self / SRV01
SRV01DC, GC, DNS192.168.10.21Self / DC01
SRV02Member server192.168.10.22DC01, SRV01
Client1Domain clientDHCP 192.168.20.100-199DC01, SRV01
Admin workstationManagement10.1.10.30-

Naming convention: EXT_ for VLANs that the UDR carries, INT_ for VLANs that exist only behind pfSense, followed by the VLAN ID and role. pfSense interface descriptions accept only letters, numbers and underscores.

Prerequisites


RequirementNotes
Hyper-V host with an External switch on a NIC that reaches the internetHere VLAN10-External
Upstream switch port to the host that can carry a tagged VLANUDR port profile with VLAN 101 tagged
Netgate Installer ISOHere C:\ISOs\netgate-installer-v1.2-RELEASE-amd64.iso. The installer downloads pfSense during install, so WAN needs internet
Domain admin credentialsUsed with PowerShell Direct
Admin workstation with OpenSSH clientWindows 10/11 includes it

All Hyper-V commands run in an elevated PowerShell on the host. Each step below states where commands run: HOST, pfSense console/shell, pfSense webGUI, or WORKSTATION.

Part 1: Management VLAN on the UniFi Dream Router


In UniFi Network create a new network for VLAN 101 and set the Router option to VLAN-only Network (Third-party Gateway in some versions). This makes the UDR carry the tag without owning an IP, NAT or DHCP on it, so pfSense is the only gateway.

SettingValue
NameEXT-V101-SRV-MGMT
RouterVLAN-only Network
VLAN ID101
DHCPNone

Allow VLAN 101 tagged on the switch port connected to the Hyper-V host, leaving the existing untagged network unchanged.

A standard (routed) UniFi network would give the UDR its own gateway and NAT on VLAN 101, and traffic would bypass pfSense.

Part 2: Build the pfSense VM


Create the VM


HOST:

$VM = "pfSense-FW01"
New-VM -Name $VM -Generation 2 -MemoryStartupBytes 2GB `
       -NewVHDPath "$((Get-VMHost).VirtualHardDiskPath)\$VM.vhdx" -NewVHDSizeBytes 20GB `
       -SwitchName "VLAN10-External"
Get-VMNetworkAdapter -VMName $VM | Rename-VMNetworkAdapter -NewName "WAN"
Add-VMNetworkAdapter -VMName $VM -Name "LAN" -SwitchName "VLAN10-External"
Set-VMProcessor -VMName $VM -Count 2
Set-VMMemory -VMName $VM -DynamicMemoryEnabled $false
Set-VM -Name $VM -AutomaticCheckpointsEnabled $false -AutomaticStartAction Start -AutomaticStopAction ShutDown
Add-VMDvdDrive -VMName $VM -Path "C:\ISOs\netgate-installer-v1.2-RELEASE-amd64.iso"
Set-VMFirmware -VMName $VM -EnableSecureBoot Off -FirstBootDevice (Get-VMDvdDrive -VMName $VM)
SettingValueReason
Generation 2, Secure Boot offUEFIFreeBSD bootloader is not signed for the Microsoft UEFI CA
Static 2 GB memoryDynamic memory offPer Netgate Hyper-V guidance
Automatic checkpoints offAvoids unplanned checkpoints of a firewall

The LAN adapter is left untagged for the install and moved to VLAN 101 after its IP is set.

Lock the MAC Addresses


Static MACs keep the hn0/hn1 mapping stable. HOST:

Start-VM $VM; Start-Sleep 5; Stop-VM $VM -TurnOff -Force
Get-VMNetworkAdapter -VMName $VM | ForEach-Object { Set-VMNetworkAdapter -VMNetworkAdapter $_ -StaticMacAddress $_.MacAddress }
Get-VMNetworkAdapter -VMName $VM | Format-Table Name, SwitchName, MacAddress

Record the MACs; the WAN MAC identifies hn0 in the installer.

Run the Netgate Installer


HOST:

Start-VM pfSense-FW01; vmconnect.exe localhost pfSense-FW01
PromptChoice
WAN interfacehn0 (WAN MAC)
WAN modeDHCP, gateway and DNS from DHCP
LAN interfacehn1 (LAN MAC)
EditionpfSense CE
FilesystemZFS on the 20 GB disk

Detach the ISO and Boot from Disk


At the reboot prompt, HOST:

$VM = "pfSense-FW01"
Stop-VM $VM -TurnOff -Force
Get-VMDvdDrive -VMName $VM | Set-VMDvdDrive -Path $null
Set-VMFirmware -VMName $VM -FirstBootDevice (Get-VMHardDiskDrive -VMName $VM)
Start-VM $VM

Console check: WAN (wan) -> hn0 -> v4/DHCP4: 10.1.10.x/24. Use console option 7 to ping 1.1.1.1.

Set the LAN Address


pfSense console, option 2 (Set interface(s) IP address):

PromptAnswer
Interface2 (LAN)
Configure IPv4 via DHCPn
IPv4 address / bits192.168.10.254 / 24
Upstream gatewayEnter (none)
IPv6 via DHCP6 / addressn / Enter
Enable DHCP server on LANn
Revert to HTTPn

Move the LAN Adapter onto VLAN 101


HOST:

Stop-VM pfSense-FW01 -Force
Set-VMNetworkAdapterVlan -VMName pfSense-FW01 -VMNetworkAdapterName "LAN" -Access -VlanId 101
Start-VM pfSense-FW01
Checkpoint-VM -Name pfSense-FW01 -SnapshotName "Clean-Install"

Part 3: Management Access from an Admin Workstation


The webGUI is managed from the admin workstation on the WAN-side network. pfSense blocks unsolicited inbound WAN traffic by default, so a pass rule limited to one source address is used.

Temporary Access and Setup Wizard


pfSense console, option 8 (Shell):

pfctl -d
exit

pfctl -d disables the packet filter until the ruleset is next reloaded. WORKSTATION: browse to https://10.1.10.54, log in as admin / pfsense.

Wizard PageSettingValue
GeneralHostname / Domainfw01lab / lab.local
Primary DNS1.1.1.1
TimeTimezoneEurope/London
WANTypeDHCP
Block RFC1918 Private NetworksUnticked (admin workstation is on 10.x)
Block bogon networksTicked
LANIP192.168.10.254/24
AdminPasswordChanged

The wizard reload re-enables the filter. Run pfctl -d from the console once more before creating the WAN rule.

WAN Rule for the webGUI


webGUI, Firewall > Rules > WAN > Add (top):

FieldValue
Action / ProtocolPass / TCP
Source10.1.10.30/32
DestinationWAN address
PortHTTPS (443)
LogTicked
DescriptionMGMT - Workstation 10.1.10.30 to webGUI HTTPS

Save and Apply. Applying re-enables the filter with the rule in place.

Rename the LAN interface: Interfaces > LAN > Description EXT_V101_MGMT.

Key-Only SSH


WORKSTATION:

if (-not (Test-Path "$env:USERPROFILE\.ssh\id_ed25519.pub")) { ssh-keygen -t ed25519 -C "admin@fw01" }
Get-Content "$env:USERPROFILE\.ssh\id_ed25519.pub" | Set-Clipboard

webGUI:

  1. System > User Manager > admin > Authorized SSH Keys: paste the key, Save.
  2. System > Advanced > Admin Access > Secure Shell: Enable, SSHd Key Only = Public Key Only, port 22, Save.
  3. Firewall > Rules > WAN: copy the HTTPS rule, set port SSH (22), description MGMT - Workstation 10.1.10.30 to SSH, Save, Apply.

Add the key before switching to key-only so access cannot be lost. Test from the WORKSTATION:

ssh admin@10.1.10.54

Part 4: Cut the Servers Over to pfSense


Before the cutover the servers used the Hyper-V host as their gateway (192.168.10.1 with a New-NetNat rule on an Internal switch). All servers move together because the subnet temporarily exists on two layer 2 segments and hosts on different segments cannot reach each other.

Checkpoint


HOST:

"DC01","Srv01","Srv02" | ForEach-Object { Checkpoint-VM -Name $_ -SnapshotName "Pre-pfSense-Cutover" }

Change the Gateway with PowerShell Direct


PowerShell Direct runs commands inside the VM over VMBus, so it keeps working while network paths change. HOST:

$Cred = Get-Credential   # LAB\Administrator
Invoke-Command -VMName DC01, Srv01, Srv02 -Credential $Cred -ScriptBlock {
    $ip = Get-NetIPAddress -AddressFamily IPv4 | Where-Object IPAddress -like "192.168.10.*"
    Remove-NetRoute -InterfaceIndex $ip.InterfaceIndex -DestinationPrefix "0.0.0.0/0" -Confirm:$false -ErrorAction SilentlyContinue
    New-NetRoute -InterfaceIndex $ip.InterfaceIndex -DestinationPrefix "0.0.0.0/0" -NextHop 192.168.10.254 | Out-Null
    [pscustomobject]@{ Host = $env:COMPUTERNAME; IP = $ip.IPAddress; Gateway = (Get-NetRoute -InterfaceIndex $ip.InterfaceIndex -DestinationPrefix "0.0.0.0/0").NextHop }
}

Selecting the adapter by its 192.168.10.x address avoids touching the Tailscale adapter.

Move the Adapters to VLAN 101


HOST:

$Nics = Get-VMNetworkAdapter -VMName DC01, Srv01, Srv02 | Where-Object SwitchName -eq "BasicLab"
$Nics | Connect-VMNetworkAdapter -SwitchName "VLAN10-External"
$Nics | Set-VMNetworkAdapterVlan -Access -VlanId 101

Verify


HOST:

Invoke-Command -VMName DC01, Srv01, Srv02 -Credential $Cred -ScriptBlock {
    [pscustomobject]@{
        Host     = $env:COMPUTERNAME
        Gateway  = (Test-Connection 192.168.10.254 -Count 1 -Quiet)
        Internet = (Test-Connection 1.1.1.1 -Count 1 -Quiet)
        DNS      = [bool](Resolve-DnsName www.microsoft.com -ErrorAction SilentlyContinue)
        DC_LDAP  = (Test-NetConnection 192.168.10.10 -Port 389 -WarningAction SilentlyContinue).TcpTestSucceeded
        SecureCh = if ($env:COMPUTERNAME -ne "DC01") { Test-ComputerSecureChannel } else { "n/a" }
    }
} | Format-Table Host, Gateway, Internet, DNS, DC_LDAP, SecureCh

All columns should be True.

Retire the Old Host NAT


HOST:

Remove-NetNat -Name "BasicLabNAT" -Confirm:$false
Remove-NetIPAddress -InterfaceAlias "vEthernet (BasicLab)" -IPAddress 192.168.10.1 -Confirm:$false

pfSense is now the only egress for the servers. The BasicLab switch itself is kept.

Part 5: Active Directory DNS Integration


Servers / clients --> DC01 / SRV01 (authoritative for lab.local)
                          | forwarders
                          v
                    pfSense Unbound 192.168.10.254 --> Internet

pfSense itself --> Unbound --(domain override lab.local)--> DC01 / SRV01

Domain members always use the DCs for DNS; pfSense is never their DNS server.

Domain Overrides on pfSense


webGUI, Services > DNS Resolver > Domain Overrides > Add (one per DC):

DomainLookup ServerDescription
lab.local192.168.10.10AD - lab.local to DC01
lab.local192.168.10.21AD - lab.local to SRV01

pfSense shell:

host dc01.lab.local 127.0.0.1

DC Forwarders to pfSense


Keep Tailscale Out of AD DNS


Both steps run together on the DCs, plus the Tailscale step on the member server. HOST:

Invoke-Command -VMName DC01, Srv01 -Credential $Cred -ScriptBlock {
    Get-DnsClient -InterfaceAlias "Tailscale*" -ErrorAction SilentlyContinue | Set-DnsClient -RegisterThisConnectionsAddress $false
    Set-DnsServerForwarder -IPAddress 192.168.10.254 -UseRootHint $false
    Clear-DnsServerCache -Force
    ipconfig /registerdns | Out-Null
}
Invoke-Command -VMName Srv02 -Credential $Cred -ScriptBlock {
    Get-DnsClient -InterfaceAlias "Tailscale*" -ErrorAction SilentlyContinue | Set-DnsClient -RegisterThisConnectionsAddress $false
    ipconfig /registerdns | Out-Null
}

A domain controller with more than one adapter should register only the adapter clients can reach. Tailscale settings may change after Tailscale upgrades, so re-check periodically.

On every domain-joined machine running Tailscale, also turn off Use Tailscale DNS (tray menu, or tailscale set --accept-dns=false). When enabled, Tailscale adds a catch-all NRPT rule that sends all queries to 100.100.100.100, which cannot answer for the AD domain. Check:

Get-DnsClientNrptPolicy | Select-Object Namespace, NameServers   # should return nothing

Check the Same-as-Parent Records


The lab.local (@) A records are used to locate DCs and must list only DCs. HOST:

Invoke-Command -VMName DC01 -Credential $Cred -ScriptBlock {
    Get-DnsServerResourceRecord -ZoneName lab.local -Name "@" -RRType A |
        Select-Object @{n="IP";e={$_.RecordData.IPv4Address.IPAddressToString}}, Timestamp
}

To remove an entry that is not a DC (replace the IP):

Invoke-Command -VMName DC01 -Credential $Cred -ScriptBlock {
    Get-DnsServerResourceRecord -ZoneName lab.local -Name "@" -RRType A |
        Where-Object { $_.RecordData.IPv4Address.IPAddressToString -eq "192.168.10.22" } |
        Remove-DnsServerResourceRecord -ZoneName lab.local -Force -Verbose
}

Part 6: Internal Client VLAN


Trunk Adapter on a Private Switch


HOST (pfSense is offline for about a minute):

$VM = "pfSense-FW01"
New-VMSwitch -Name "LAB-Internal" -SwitchType Private -Notes "pfSense internal VLAN trunk (102+)"
Checkpoint-VM -Name $VM -SnapshotName "Pre-Internal-Trunk"
Stop-VM $VM
Add-VMNetworkAdapter -VMName $VM -Name "TRUNK" -SwitchName "LAB-Internal"
Set-VMNetworkAdapterVlan -VMName $VM -VMNetworkAdapterName "TRUNK" -Trunk -AllowedVlanIdList "102-199" -NativeVlanId 1
Start-VM $VM; Start-Sleep 5; Stop-VM $VM -TurnOff -Force
$n = Get-VMNetworkAdapter -VMName $VM -Name "TRUNK"; Set-VMNetworkAdapter -VMNetworkAdapter $n -StaticMacAddress $n.MacAddress
Start-VM $VM
Get-VMNetworkAdapterVlan -VMName $VM

Expected: TRUNK Trunk 1,102-199. pfSense sees the adapter as hn2. A Private switch has no uplink, so these VLANs never leave the host.

VLAN 102 Interface


webGUI:

  1. Interfaces > Assignments > VLANs > Add: Parent hn2 (check MAC), Tag 102, Description INT_V102_CLIENTS.
  2. Interfaces > Assignments: add VLAN 102 on hn2.
  3. Edit the new interface:
FieldValue
EnableTicked
DescriptionINT_V102_CLIENTS
IPv4Static 192.168.20.254/24, no gateway
IPv6None

DHCP


webGUI, Services > DHCP Server > INT_V102_CLIENTS:

FieldValue
EnableTicked
Range192.168.20.100 - 192.168.20.199
DNS Servers192.168.10.10, 192.168.10.21
Domain name / search listlab.local

pfSense permits DHCP automatically on interfaces where its DHCP server is enabled.

Aliases


webGUI, Firewall > Aliases:

NameTypeEntries
AD_DCsHost(s)192.168.10.10, 192.168.10.21
RFC1918Network(s)10.0.0.0/8, 172.16.0.0/12, 192.168.0.0/16
AD_TCPPort(s)53, 88, 135, 389, 445, 464, 49152:65535
AD_UDPPort(s)53, 88, 123, 389
WEBPort(s)80, 443
TAILSCALE_UDPPort(s)3478, 41641
PortPurpose
53 TCP/UDPDNS
88 TCP/UDPKerberos
123 UDPTime sync
135 TCPRPC endpoint mapper
389 TCP/UDPLDAP and CLDAP (DC locator)
445 TCPSMB (SYSVOL, Group Policy)
464 TCPKerberos password change
49152-65535 TCPRPC dynamic ports (Netlogon)

LDAPS (636) and Global Catalog (3268/3269) are omitted for a single-domain client.

Client Rules


webGUI, Firewall > Rules > INT_V102_CLIENTS, top to bottom:

#ActionProtoSourceDestinationPortDescription
1PassICMP echoCLIENTS subnets192.168.20.254-CLIENTS - ping gateway
2PassUDPCLIENTS subnetsAD_DCsAD_UDPCLIENTS - AD UDP to DCs
3PassTCPCLIENTS subnetsAD_DCsAD_TCPCLIENTS - AD TCP to DCs
4Block (log)anyCLIENTS subnetsRFC1918anyCLIENTS - block all internal
5PassTCPCLIENTS subnetsanyWEBCLIENTS - web out

Everything else hits the implicit default deny. Confirm the loaded order from the pfSense shell:

pfctl -sr | grep -i "CLIENTS"

Attach a Client


HOST:

Get-VMNetworkAdapter -VMName Client1 | Connect-VMNetworkAdapter -SwitchName "LAB-Internal"
Get-VMNetworkAdapter -VMName Client1 | Set-VMNetworkAdapterVlan -Access -VlanId 102
Invoke-Command -VMName Client1 -Credential $Cred -ScriptBlock {
    $If = (Get-NetAdapter | Where-Object Status -eq "Up" | Select-Object -First 1).Name
    Set-NetIPInterface -InterfaceAlias $If -Dhcp Enabled
    Remove-NetRoute -InterfaceAlias $If -DestinationPrefix "0.0.0.0/0" -Confirm:$false -ErrorAction SilentlyContinue
    Set-DnsClientServerAddress -InterfaceAlias $If -ResetServerAddresses
    ipconfig /renew | Out-Null
    ipconfig /flushdns | Out-Null
    Restart-Service Netlogon -Force
}

If the client runs Tailscale, disable Use Tailscale DNS first (see Part 5).

Part 7: Management VLAN Rules


Replace the default allow-all on the management VLAN. webGUI, Firewall > Rules > EXT_V101_MGMT, below the anti-lockout rule:

#ActionProtoSourceDestinationPortDescription
1PassICMP echoMGMT subnetsany-MGMT - ping
2PassTCP/UDPAD_DCsEXT_V101_MGMT address53MGMT - DCs DNS to pfSense
3PassUDPAD_DCsany123MGMT - DCs NTP out
4Block (log)anyMGMT subnetsRFC1918anyMGMT - block all internal
5PassTCPMGMT subnetsanyWEBMGMT - web out
6PassUDPMGMT subnetsanyTAILSCALE_UDPMGMT - Tailscale out

Then disable Default allow LAN to any and Default allow LAN IPv6 to any and Apply.

Server-to-server traffic stays on the same subnet and never crosses pfSense, so AD replication between DCs is unaffected. Replies to client-initiated sessions from VLAN 102 are allowed by pfSense state tracking.

Part 8: Verification


Servers, HOST: re-run the block in Verify.

Client, HOST:

Invoke-Command -VMName Client1 -Credential $Cred -ScriptBlock {
    $If = (Get-NetAdapter | Where-Object Status -eq "Up" | Select-Object -First 1).Name
    function T($h,$p){ (Test-NetConnection $h -Port $p -WarningAction SilentlyContinue).TcpTestSucceeded }
    [pscustomobject]@{
        Gateway             = (Get-NetRoute -InterfaceAlias $If -DestinationPrefix "0.0.0.0/0").NextHop
        DNS                 = (Get-DnsClientServerAddress -InterfaceAlias $If -AddressFamily IPv4).ServerAddresses -join ","
        PingGW              = Test-Connection 192.168.20.254 -Count 1 -Quiet
        ResolveWeb          = [bool](Resolve-DnsName www.microsoft.com -ErrorAction SilentlyContinue)
        SecureChannel       = Test-ComputerSecureChannel
        Web443              = T "www.microsoft.com" 443
        SHOULD_FAIL_DC_RDP  = T "192.168.10.10" 3389
        SHOULD_FAIL_FW_GUI  = T "192.168.10.254" 443
        SHOULD_FAIL_WAN_GUI = T "10.1.10.54" 443
    }
} | Format-List
CheckExpected
Gateway192.168.20.254
DNS192.168.10.10, 192.168.10.21
PingGW, ResolveWeb, SecureChannel, Web443True
SHOULD_FAIL_*False

DC location from the client:

nltest /dsgetdc:lab.local /force

Part 9: Backup


webGUI: Diagnostics > Backup & Restore > Download configuration as XML.

HOST:

"pfSense-FW01","DC01","Srv01","Srv02","Client1" | ForEach-Object { Checkpoint-VM -Name $_ -SnapshotName "Baseline-$(Get-Date -Format yyyyMMdd)" }

Operational Notes


TopicNote
pfSense shellRoot shell is tcsh. Use single commands or sh -c '...' for loops
Locked out of webGUIConsole option 8, pfctl -d, fix the rule, Apply
Emergency accessHyper-V console (vmconnect), and Tailscale subnet routes
Adding an internal VLANNew VLAN on hn2 in pfSense (103-199), assign, then set VM adapters to access that VLAN on LAB-Internal
Filter loggrep <ip> /var/log/filter.log on the pfSense shell

References