Thanks for comments.
Found solution towards the end of this whole wsl2 ubuntu setup guide here:
https://dev.to/aitorsol/wsl2-windows-linux-subsystem-a-guide-to-install-a-local-web-server-ubuntu-20-04-apache-php8-y-mysql8-3bbk
The script included in that post is slightly incompatible with my system because ifconfig has been deprecated so the version I used uses ip addr on the first line rather than ifconfig. From reading elsewhere eth0 may not be used on your system so you may need to adjust that first line according to the adapter
Edit what ports you want forwarding to the virtual machine in the script.
:
$remoteport = bash.exe -c "ip addr list eth0 | grep 'inet '"
$found = $remoteport -match '\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}';
if( $found ){
$remoteport = $matches[0];
} else{
echo "The Script Exited, the ip address of WSL 2 cannot be found";
exit;
}
#[Ports]
#All the ports you want to forward separated by coma
$ports=@(80,443,10000,3000,5000,8080);
#[Static ip]
#You can change the addr to your ip config to listen to a specific address
$addr='0.0.0.0';
$ports_a = $ports -join ",";
#Remove Firewall Exception Rules
iex "Remove-NetFireWallRule -DisplayName 'WSL 2 Firewall Unlock' ";
#adding Exception Rules for inbound and outbound Rules
iex "New-NetFireWallRule -DisplayName 'WSL 2 Firewall Unlock' -Direction Outbound -LocalPort $ports_a -Action Allow -Protocol TCP";
iex "New-NetFireWallRule -DisplayName 'WSL 2 Firewall Unlock' -Direction Inbound -LocalPort $ports_a -Action Allow -Protocol TCP";
for( $i = 0; $i -lt $ports.length; $i++ ){
$port = $ports[$i];
iex "netsh interface portproxy delete v4tov4 listenport=$port listenaddress=$addr";
iex "netsh interface portproxy add v4tov4 listenport=$port listenaddress=$addr connectport=$port connectaddress=$remoteport";
}
Once you have run this you should be able to access apache on the virtual machine by accessing your windows machines LAN IP and obviously 127.0.0.1 works on the machine itself
After testing it I set it run it from .profile so that the port forwarding changes occur when the virtual machine starts up.
/mnt/c/Windows/System32/WindowsPowerShell/v1.0/powershell.exe "C:\Users\user\wsl-networking-startup-ip-change.ps1"