Customize your WSL2 system to use network bridging, which is nearly a pre-requisite for running ufw and WireGuard
Right-click Windows Terminal and Run as Administrator.
Enable Hyper-V management features:
DISM /Online /Enable-Feature /FeatureName:Microsoft-Hyper-V-Management-PowerShell /All
Answer Y to restart Windows.
Right-click Windows Terminal and Run as Administrator.
Create a new VM adapter to be bridged with WSL:
Get-NetAdapter
New-VMSwitch -Name "WSL-Bridge" -NetAdapterName "Ethernet" -AllowManagementOS $true
Stop the WSL2 instance (assuming default Debian instance):
wsl --terminate Debian
Start your text editor.
Navigate to %USERPROFILE% folder, open or create ".wslconfig"
Add these lines and save .wslconfig:
[wsl2]
networkingMode=bridged
vmSwitch=WSL-Bridge
firewall=false
ipv6=true
Restart WSL2
wsl -d Debian
It should start without errors.
Enable systemd networking at startup
sudo vi /etc/wsl.conf
[boot]
systemd=true
[network]
generateResolvConf = false
Configure eth0 adapter to use DHCP (after a 1 second delay):
vi /etc/systemd/network/10-eth0.network
[Match]
Driver=hv_netvsc
[Link]
ActivationDelaySec=1s
[Network]
Description=WSL2-Bridge
DHCP=ipv6
IPv6AcceptRA=true
MulticastDNS=true
LLMNR=true
[IPv6AcceptRA]
UseDNS=true
[DHCPv6]
UseDNS=true
UseHostname=false
Start systemd network daemon
sudo systemctl enable systemd-networkd
sudo systemctl start systemd-networkd
Determine the settings returned from DHCP, especially DNS
networkctl status | grep DNS
Create resolv.conf:
vi /etc/resolv.conf
# Add nameserver <address>, example below
nameserver 2001:4860:4860::8888
Test network and DNS by updating Debian:
apt update
Install the systemd DNS resolution service (this might be more of a pain than it's worth):
sudo apt install systemd-resolved libnss-resolve -y
sudo systemctl enable systemd-resolved --now