2

I have set up ubuntu with WSL2 on windows 10 and my goal is to route traffic from my laptop through my windows desktop to the linux on WSL2.

My local network uses 192.168.1.0/24.
Windows created a virtual hypervisor adapter with network 172.26.176.0/20
Windows sits at 192.168.1.11 on my network and at 172.26.176.1/20 on the virtual adapter
The WSL2 linux sits at 172.26.191.190/20


      [the internets]
             |
[router / pub. ip / 192.168.1.1]
                     |
                   [SW] -- [gw+dhcp / 192.168.1.5 / (more irrelevant adapters)]
                        \- [laptop / 192.168.1.13]
                        \- [windows / 192.168.1.11 (phys) / 172.26.176.1 (virt.)]
                                                             |
                                                           [WSL2 linux / 172.26.191.190]

I have a laptop on 192.168.1.0/24 with which I want to access the WSL linux with using ssh. I also have a gateway server, running linux on 192.168.1.5/24.

How do I configure my gateway and windows to allow traffic from anywhere in my network to the 172.26.176.0/20 network?

My idea is to add an iptable DNAT rule like so:

sudo iptables -t nat -A PREROUTING -j DNAT -d 172.26.176.0/20 --to-destination 192.168.1.11

Though I have the feeling I should probably use route instead of iptables.

But how do I make windows route the package to the hypervisor? Just the command on the gateway alone doesn't fix the issue.

EDIT

I restarted the windows machine and now it sits on a whole different subnet. It seems to be random. How do I even deal with that?

EDIT2

I don't want to use NAT from windows to port forward the ports on the WSL, but instead want to route the traffic to the WSL ip address range.
That requires routing in the gateway system and in the windows system. On linux you can just write a 1 into /proc/sys/net/ipv4/ip_forward and it just works. I don't know the windows equivalent if there is any.

Then there is the issue of the random IP addresses. Windows can access the gateway with SSH, so a script could possibly work to alter the routing tables.
Or I could add all possible 172.[16-32]../20 subnets... But on second thought that seems like a bad idea.

I have had a search and came accross this which allows hostnames to be assigned to the WSL instances. But it does it locally using the hosts file and I'm not sure how this would help me for remote access.

EDIT3

I have found this answer that suggests that
HKEY_LOCAL_MACHINE \SYSTEM\CurrentControlSet\Services\Tcpip\Parameters\IPEnableRouter
enables ip routing for windows. Now I just need to tell my gateway the network routing.

However I have tried adding a route with

sudo route add -net 172.26.176.0/20 gw 192.168.1.11

However my ping still didn't go through. However wireshark (on the windows machine) registers that the ping arrives for the target ip (which is then not pinged.)
However a ping from windows to the very same address (WSL machine) works fine.

I'd be happy if windows would forward the request. I can easily program a service of some kind for my gateway to allow windows to connect to it and update the ip for the routing table.

0

You must log in to answer this question.