I'm going to talk here about the possibility of setting up a secure IPsec VPN between Microsoft Windows hosts in the same LAN, to greatly improve network security. Thanks to this configuration, all exchanges between machines will be encrypted, without exception.
For the purposes of this article, we'll keep our architecture as simple as possible. We'll set up a secure connection with an IPsec VPN with PSK between a computer running Windows 11 and a server running Windows 2022. Both computers will be on the same local network.
PS C:\> $PSKAuthProp = New-NetIPsecAuthProposal -Machine -PreSharedKey "IPsuperSECRET"
PS C:\> $PSKAuthSet = New-NetIPsecPhase1AuthSet -DisplayName "PSK auth" -Proposal $PSKAuthProp
PS C:\> New-NetIPsecRule -DisplayName "IPsec" -Name "IPsec" -Mode Transport -InboundSecurity Require -OutboundSecurity Require -LocalAddress 192.168.1.200 -RemoteAddress 192.168.1.30 -Enable True -Phase1AuthSet $PSKAuthSet.Name
We will create a Firewall Rule to allow encrypted flows.
PS C:\> New-NetFirewallRule -DisplayName "IPsec ALLOW" -Direction Inbound -Enabled True -Action Allow -LocalAddress 192.168.1.200 -RemoteAddress 192.168.1.0/24 -Protocol Any -Encryption Dynamic -Authentication Required
We've now finished configuring the server. Now it's time to move on to client configuration.
I'm going to describe them all, but the steps are pretty much the same as those we followed for the server.
From here, everything should work and connections are already encrypted. Here, we'll look at how to further enhance security by choosing more robust IPsec protocols thant those offered by default. All command listed below must be entered on both client and server.
PS C:\> Set-NetIPsecRule -DisplayName "IPsec" -KeyModule IKEv2 -ForwardPathLifetime 120
PS C:\> $proposal1 = (New-NetIPsecQuickModeCryptoProposal -Encapsulation ESP -Encryption AES256 -ESPHash SHA256)
PS C:\> $mMCryptoSet=(New-NetIPsecQuickModeCryptoSet -DisplayName "Quick Mode Rule" -Proposal $proposal1)
PS C:\> Set-NetIPsecRule -DisplayName IPsec -QuickModeCryptoSet $mMCryptoSet.Name
PS C:\> Get-NetIPsecRule -DisplayName IPsec
PS C:\> Remove-NetIPsecRule -DisplayName IPsec
PS C:\> Get-NetIPsecMainModeRule -DisplayName IPsecMain
PS C:\> Remove-NetIPsecMainModeRule -Name "{XXX-XXX-XXX}"
PS C:\> Get-NetIPsecMainModeSA
PS C:\> Get-NetIPsecQuickModeSA
Contact :