# 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

```bash
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](https://wiki.kyluat.com/uploads/images/gallery/2024-12/scaled-1680-/image.png)](https://wiki.kyluat.com/uploads/images/gallery/2024-12/image.png)

[![image.png](https://wiki.kyluat.com/uploads/images/gallery/2024-12/scaled-1680-/oLhimage.png)](https://wiki.kyluat.com/uploads/images/gallery/2024-12/oLhimage.png)

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

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

```
netsh interface portproxy show all
```

[![image.png](https://wiki.kyluat.com/uploads/images/gallery/2025-01/scaled-1680-/image.png)](https://wiki.kyluat.com/uploads/images/gallery/2025-01/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
```