Skip to main content

Routing / Open Port WSL2 and Host Machine.

Cách routing port từ WSL2 sang local machine và public network.

Mở window POWER SHELL của windows với ADMINISTRATOR

netsh interface portproxy add v4tov4 listenport=3000 listenaddress=0.0.0.0 connectport=3000 connectaddress=172.27.237.24

Giải thích: 

IP: thay đổi ip address 172.27.237.24 thành ip address của wsl2 ubuntu server

PORT: 3000 là port open từ wsl2 qua local machine

muốn biết WSL2 Address thì cứ vào networking adapters xem phần VEthernet(WSL)

image.png

image.png

Xem thêm video hướng dẫn nếu cần: https://youtu.be/yCK3easuYm4?si=eB-6vNyp6H18daGJ

Để xem port nào đã routing forward thì check:

netsh interface portproxy show all

image.png

Để delete:

netsh interface portproxy delete v4tov4 listenport=9001 listenaddress=0.0.0.0
netsh interface portproxy delete v4tov4 listenport=9000 listenaddress=0.0.0.0
netsh interface portproxy delete v4tov4 listenport=3000 listenaddress=0.0.0.0