Skip to main content
The 2024 Developer Survey results are live! See the results
2 of 3
added 156 characters in body; edited title
init_js
  • 375
  • 2
  • 7
  • 17

How to use Windows WSL to configure routing? Is this possible?

I noticed that IP forwarding claims to be enabled in WSL (Windows 10pro 1709). I'd like to make use of that to redirect Hyper-V VM traffic to another interface. The VM and the host share a /24 ipv4 subnet and can communicate. Ideally, I'd want to use WSL to configure iptables-like rules, or have some sort of software router program using RAW sockets that could rewrite traffic.

# on the WSL bash
$ sysctl net.ipv4.ip_forward
net.ipv4.ip_forward = 1

My windows host and the VM are both in 192.168.4.X. 192.168.4.215 is the host. 192.168.4.228 is the VM.

I've added a rule to the windows firewall to allow every incoming TCP port on that subnet, and tested connectivity by transferring web pages served by the WSL host and downloaded by the VM. (e.g. ran python -m SimpleHTTPServer in wsl and used curl http://192.168.2.215 on the vm)

I've added the windows host as the default gateway inside the VM:

# route add default gw 192.168.4.215
# route -n
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
0.0.0.0         192.168.4.215   0.0.0.0         UG    0      0        0 eth0
172.17.0.0      0.0.0.0         255.255.0.0     U     0      0        0 docker0
192.168.4.0     0.0.0.0         255.255.255.0   U     0      0        0 eth0

But my TCP connections initiated on the VM are not being routed by Windows (e.g. curl http://<publicip>.). Can't connect

What else do I need to unblock in Windows?

init_js
  • 375
  • 2
  • 7
  • 17