https://www.cnblogs.com/guiyishanren/p/15763057.html
1. The preparation is ready, check the ip of the wsl2 virtual machine
ip addr show eth0
2. Set port forwarding (requires administrator privileges to run POWERSHELL)
Format
netsh interface portproxy add v4tov4 listenport=【host windows platform listening port】 listenaddress=0.0.0.0 connectport=【wsl2 platform listening port】 connectaddress=【wsl2 platform ip】protocol=tcp
netsh interface portproxy add v4tov4 listenport=80 listenaddress=0.0.0.0 connectport=80 connectaddress=172.30.144.91 protocol=tcp
或
netsh interface portproxy add v4tov4 listenport=80 listenaddress=* connectport=80 connectaddress=172.30.144.91 protocol=tcp
All parameters need to be adjusted according to the actual situation
Then check the port forwarding status:
netsh interface portproxy show all
As shown in the figure, the port forwarding is successful.
Find a computer in the LAN to access the local area network ip address of the machine to test.
At this point, my colleagues can successfully visit.
If unsuccessful, you may need to configure the inbound rules to try.
3. Delete port forwarding
Format
netsh interface portproxy delete v4tov4 listenport=【host windows platform listening port】 listenaddress=0.0.0.0
netsh interface portproxy delete v4tov4 listenport=80 listenaddress=*
或
netsh interface portproxy delete v4tov4 listenport=80 listenaddress=0.0.0.0
Note
that when you write 0.0.0.0 to delete, you also need to use 0.0.0.0 to correspond, otherwise you will be prompted that the file cannot be found.